|
18 | 18 | from labthings.extensions import BaseExtension
|
19 | 19 | from labthings.schema import LogRecordSchema, Schema
|
20 | 20 | from labthings.views import ActionView, EventView, PropertyView
|
| 21 | +from labthings.utilities import get_by_path |
21 | 22 |
|
22 | 23 |
|
23 |
| -def test_openapi(thing): |
24 |
| - """Make an example Thing and check its openapi description validates""" |
25 |
| - |
| 24 | +@pytest.fixture |
| 25 | +def thing_with_some_views(thing): |
26 | 26 | class TestAction(ActionView):
|
27 | 27 | args = {"n": fields.Integer()}
|
28 | 28 |
|
@@ -53,8 +53,33 @@ def post(self, args):
|
53 | 53 |
|
54 | 54 | thing.add_view(TestFieldProperty, "TestFieldProperty")
|
55 | 55 |
|
56 |
| - thing.spec.to_yaml() |
57 |
| - validate_spec(thing.spec) |
| 56 | + return thing |
| 57 | + |
| 58 | + |
| 59 | +def test_openapi(thing_with_some_views): |
| 60 | + """Make an example Thing and check its openapi description validates""" |
| 61 | + |
| 62 | + thing_with_some_views.spec.to_yaml() |
| 63 | + thing_with_some_views.spec.to_dict() |
| 64 | + validate_spec(thing_with_some_views.spec) |
| 65 | + |
| 66 | + |
| 67 | +def test_duplicate_action_name(thing_with_some_views): |
| 68 | + """Check that name clashes don't overwrite schemas""" |
| 69 | + t = thing_with_some_views |
| 70 | + |
| 71 | + class TestAction(ActionView): |
| 72 | + args = {"m": fields.Integer()} |
| 73 | + |
| 74 | + def post(self): |
| 75 | + return "POST" |
| 76 | + |
| 77 | + t.add_view(TestAction, "TestActionM", endpoint="TestActionM") |
| 78 | + |
| 79 | + api = t.spec.to_dict() |
| 80 | + original_input_schema = get_by_path(api, ["paths", "/TestAction", "post"]) |
| 81 | + modified_input_schema = get_by_path(api, ["paths", "/TestActionM", "post"]) |
| 82 | + assert original_input_schema != modified_input_schema |
58 | 83 |
|
59 | 84 |
|
60 | 85 | def test_ensure_schema_field_instance():
|
|
0 commit comments