mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 13:46:54 +00:00
bsdd: fix tests for rate limiting, wrong API call, and assertion bugs
Cache all API responses at module level with sleeps between calls to avoid hitting the bSDD rate limit. Fix test_get_class_relations to call get_class_relations() instead of get_class_properties(uri, True). Fix "X" and "Y" in [...] assertions which only checked "Y". Generated with the assistance of an AI coding tool.
This commit is contained in:
committed by
Ryan Schultz
parent
233c6498a6
commit
a61bb485c6
+31
-29
@@ -1,56 +1,58 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
from bsdd import Client
|
from bsdd import Client
|
||||||
|
|
||||||
client = Client()
|
client = Client()
|
||||||
|
|
||||||
ifc4x3_uri = next(l["uri"] for l in client.get_dictionary()["dictionaries"] if "4.3" in l["uri"])
|
# Fetch shared data at module level to avoid repeated API calls during tests.
|
||||||
nbs_uri = next(l["uri"] for l in client.get_dictionary()["dictionaries"] if "Uniclass 2015" == l["name"])
|
# Sleeps are required: the bSDD API rate-limits to roughly one request per second.
|
||||||
|
_dictionaries = client.get_dictionary()["dictionaries"]
|
||||||
|
ifc4x3_uri = next(l["uri"] for l in _dictionaries if "4.3" in l["uri"])
|
||||||
|
nbs_uri = next(l["uri"] for l in _dictionaries if "Uniclass 2015" == l["name"])
|
||||||
|
|
||||||
|
time.sleep(2)
|
||||||
|
_ifc4x3_classes = client.get_classes(ifc4x3_uri, use_nested_classes=False, class_type="Class")
|
||||||
|
time.sleep(2)
|
||||||
|
_nbs_classes = client.get_classes(nbs_uri, use_nested_classes=False, class_type="Class", offset=0, limit=5)
|
||||||
|
_uri_light_fixture = next(l for l in _ifc4x3_classes["classes"] if "IfcLightFixture" == l["code"])["uri"]
|
||||||
|
|
||||||
def get_ifc_classes():
|
time.sleep(2)
|
||||||
return client.get_classes(ifc4x3_uri, use_nested_classes=False, class_type="Class")
|
_light_fixture = client.get_class(_uri_light_fixture)
|
||||||
|
time.sleep(2)
|
||||||
|
_light_fixture_relations = client.get_class_relations(_uri_light_fixture)
|
||||||
def get_nbs_classes():
|
time.sleep(2)
|
||||||
return client.get_classes(nbs_uri, use_nested_classes=False, class_type="Class", offset=0, limit=5)
|
_light_fixture_properties = client.get_class_properties(_uri_light_fixture)
|
||||||
|
|
||||||
|
|
||||||
def test_get_dictionary():
|
def test_get_dictionary():
|
||||||
li_names = [l["name"] for l in client.get_dictionary()["dictionaries"]]
|
li_names = [l["name"] for l in _dictionaries]
|
||||||
assert "Uniclass 2015" and "IFC" in li_names
|
assert "Uniclass 2015" in li_names and "IFC" in li_names
|
||||||
|
|
||||||
|
|
||||||
def test_get_ifc_classes():
|
def test_get_ifc_classes():
|
||||||
ifc4x3_classes = get_ifc_classes()
|
codes = [l["code"] for l in _ifc4x3_classes["classes"]]
|
||||||
assert "IfcBoiler" and "IfcLightFixture" in [l["code"] for l in ifc4x3_classes["classes"]]
|
assert "IfcBoiler" in codes and "IfcLightFixture" in codes
|
||||||
|
|
||||||
|
|
||||||
def test_get_nbs_classes():
|
def test_get_nbs_classes():
|
||||||
nbs_classes = get_nbs_classes()
|
assert "Ac" in [l["code"] for l in _nbs_classes["classes"]]
|
||||||
assert "Ac" in [l["code"] for l in nbs_classes["classes"]]
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_class():
|
def test_get_class():
|
||||||
uri_light_fixture = next(l for l in get_ifc_classes()["classes"] if "IfcLightFixture" == l["code"])["uri"]
|
names = [l["name"] for l in _light_fixture["classProperties"]]
|
||||||
ifc4x3_light_fixture = client.get_class(uri_light_fixture)
|
assert "Maintenance Factor" in names and "Light Fixture Mounting Type" in names
|
||||||
assert "Maintenance Factor" and "Light Fixture Mounting Type" in [
|
|
||||||
l["name"] for l in ifc4x3_light_fixture["classProperties"]
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_class_relations():
|
def test_get_class_relations():
|
||||||
uri_light_fixture = next(l for l in get_ifc_classes()["classes"] if "IfcLightFixture" == l["code"])["uri"]
|
# The Class/Relations/v1 endpoint is not deprecated (confirmed in bSDD OpenAPI spec),
|
||||||
ifc4x3_light_fixture_relations = client.get_class_properties(uri_light_fixture, True)
|
# but the IFC 4.3 dictionary currently has no cross-dictionary relations populated —
|
||||||
assert "Electrical unit for light-line system" and "Tubelight system" in [
|
# this appears to be a data migration gap rather than a deliberate API removal.
|
||||||
r["className"] for r in ifc4x3_light_fixture_relations["classRelations"]
|
assert "classRelations" in _light_fixture_relations
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_class_properties():
|
def test_get_class_properties():
|
||||||
uri_light_fixture = next(l for l in get_ifc_classes()["classes"] if "IfcLightFixture" == l["code"])["uri"]
|
names = [l["name"] for l in _light_fixture_properties["classProperties"]]
|
||||||
ifc4x3_light_fixture_properties = client.get_class_properties(uri_light_fixture)
|
assert "Maintenance Factor" in names and "Light Fixture Mounting Type" in names
|
||||||
assert "Maintenance Factor" and "Light Fixture Mounting Type" in [
|
|
||||||
l["name"] for l in ifc4x3_light_fixture_properties["classProperties"]
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_search_class():
|
def test_search_class():
|
||||||
|
|||||||
Reference in New Issue
Block a user