generated from specklesystems/speckle_automate_python_example
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aff023b
commit 3b4c855
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Importing necessary modules and packages | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
# Speckle is a data platform for AEC; here we're importing essential modules from it | ||
from specklepy.api import operations | ||
from specklepy.api.client import SpeckleClient | ||
from specklepy.objects import Base | ||
from specklepy.transports.server import ServerTransport | ||
|
||
|
||
# Setting up some pytest fixtures for testing | ||
# Fixtures are a way to provide consistent test data or configuration for each test | ||
|
||
@pytest.fixture() | ||
def speckle_token(request) -> str: | ||
"""Get the Speckle token from test configuration. | ||
These variables may be in a `.env` file or as secrets in your CI/CD pipeline.""" | ||
return request.config.SPECKLE_TOKEN | ||
|
||
|
||
@pytest.fixture() | ||
def speckle_server_url(request) -> str: | ||
"""Provide a speckle server URL for the test suite. | ||
Defaults to localhost if not specified. Useful only if you are spinning up a local server. | ||
""" | ||
return request.config.SPECKLE_SERVER_URL | ||
|
||
|
||
@pytest.fixture() | ||
def test_version_object(speckle_server_url: str, speckle_token: str) -> Base: | ||
"""Retrieve a specific commit from the Speckle server.""" | ||
test_client = SpeckleClient(speckle_server_url, True) | ||
test_client.authenticate_with_token(speckle_token) | ||
|
||
# Sample project/stream and version/commit IDs | ||
# Could also be environment variables | ||
project_id = "PROJECT_ID" # Replace with your stream ID | ||
version_id = "VERSION_ID" # Replace with your commit ID | ||
|
||
transport = ServerTransport(client=test_client, stream_id=project_id) | ||
version = test_client.commit.get(project_id, version_id) | ||
version_object = version.referencedObject | ||
obj = operations.receive(obj_id=version_object, remote_transport=transport) | ||
|
||
return obj | ||
|
||
|
||
# Main test functions | ||
def test_real_data(test_version_object: Any, speckle_server_url: str): | ||
""" | ||
Test your code against a real Speckle commit. | ||
""" | ||
|
||
assert isinstance(Base, test_version_object) | ||
|
||
pass |