Skip to content

Commit f39851c

Browse files
committed
Check duplicate action names
I worried that two ActionView subclasses with the same __name__ would result in name conflicts of their input/output schemas. Turns out I needn't have worried! This test was mostly to reassure myself, but may as well be kept to check future code as well.
1 parent 704cba9 commit f39851c

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

tests/test_openapi.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
from labthings.extensions import BaseExtension
1919
from labthings.schema import LogRecordSchema, Schema
2020
from labthings.views import ActionView, EventView, PropertyView
21+
from labthings.utilities import get_by_path
2122

2223

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):
2626
class TestAction(ActionView):
2727
args = {"n": fields.Integer()}
2828

@@ -53,8 +53,33 @@ def post(self, args):
5353

5454
thing.add_view(TestFieldProperty, "TestFieldProperty")
5555

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
5883

5984

6085
def test_ensure_schema_field_instance():

0 commit comments

Comments
 (0)