Skip to content

Commit 15c34c2

Browse files
committed
Adding tests for BusPath.parameter_schema and BusPath.response_schema
1 parent 98ddbe6 commit 15c34c2

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

lightbus/client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,22 @@ async def lazy_load_now(self):
407407
)
408408
)
409409

410-
# 2. Open the transports
410+
# 2. Add any local APIs to the schema
411+
for api in self.api_registry.all():
412+
await self.schema.add_api(api)
413+
414+
logger.info(
415+
LBullets(
416+
"Loaded the following local schemas ({})".format(len(self.schema.remote_schemas)),
417+
items=self.schema.local_schemas.keys(),
418+
)
419+
)
420+
421+
# 3. Open the transports
411422
for transport in self.transport_registry.get_all_transports():
412423
await transport.open()
413424

414-
# 3. Done
425+
# 4. Done
415426
self._lazy_load_complete = True
416427

417428
# RPCs

lightbus/path.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ def response_schema(self):
168168
Only RPCs have responses. Accessing this property for an event will result in a
169169
SchemaNotFound error.
170170
"""
171-
rpc_schema = self.client.schema.get_rpc_schema(self.api_name, self.name)["response"]
172-
return rpc_schema["response"]
171+
return self.client.schema.get_rpc_schema(self.api_name, self.name)["response"]
173172

174173
def validate_parameters(self, parameters: dict):
175174
self.client.schema.validate_parameters(self.api_name, self.name, parameters)

tests/test_bus_path_unit.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,33 @@ async def test_positional_only_rpc(dummy_bus: lightbus.path.BusPath):
5656
async def test_positional_only_event(dummy_bus: lightbus.path.BusPath):
5757
with pytest.raises(InvalidParameters):
5858
await dummy_bus.my.dummy.event.fire_async(123)
59+
60+
61+
@pytest.mark.asyncio
62+
async def test_parameter_schema_event(dummy_bus: lightbus.path.BusPath, dummy_api):
63+
dummy_bus.client.register_api(dummy_api)
64+
await dummy_bus.client.lazy_load_now()
65+
schema = dummy_bus.my.dummy.my_event.parameter_schema
66+
assert schema
67+
assert isinstance(schema, dict)
68+
assert "$schema" in schema
69+
70+
71+
@pytest.mark.asyncio
72+
async def test_parameter_schema_rpc(dummy_bus: lightbus.path.BusPath, dummy_api):
73+
dummy_bus.client.register_api(dummy_api)
74+
await dummy_bus.client.lazy_load_now()
75+
schema = dummy_bus.my.dummy.my_proc.parameter_schema
76+
assert schema
77+
assert isinstance(schema, dict)
78+
assert "$schema" in schema
79+
80+
81+
@pytest.mark.asyncio
82+
async def test_response_schema_rpc(dummy_bus: lightbus.path.BusPath, dummy_api):
83+
dummy_bus.client.register_api(dummy_api)
84+
await dummy_bus.client.lazy_load_now()
85+
schema = dummy_bus.my.dummy.my_proc.response_schema
86+
assert schema
87+
assert isinstance(schema, dict)
88+
assert "$schema" in schema

0 commit comments

Comments
 (0)