Skip to content

Commit

Permalink
Test locally copy pasta
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdbroughton committed Oct 27, 2023
1 parent aff023b commit 3b4c855
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Rules/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_data_traversal_rules() -> GraphTraversal:

default_rule = TraversalRule(
[lambda _: True],
lambda o: o.get_member_names(), # TODO: avoid deprecated members
lambda o: o.get_member_names(),
)

return GraphTraversal([display_value_rule, default_rule])
58 changes: 58 additions & 0 deletions tests/test_local.py
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

0 comments on commit 3b4c855

Please sign in to comment.