Skip to content

Commit 18a36a5

Browse files
committed
add test for nested controllers
1 parent cc859fc commit 18a36a5

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

tests/test_schema.py

+30-9
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ def quux(self):
7171
assert controller.quux != quux
7272

7373

74-
# XXX - need proper test of child controllers for nested fields
75-
def test_child_controller_decoration(Controller, valid_data):
76-
pass
74+
def test_initialize_nested_controller(ParentController, Controller, nested_data):
75+
controller = ParentController(nested_data)
76+
assert isinstance(controller.child, Controller)
77+
78+
79+
def test_nested_controller_as_dict_matches_data(ParentController, nested_data):
80+
controller = ParentController(nested_data)
81+
assert nested_data == vars(controller)
7782

7883

7984
@pytest.fixture
@@ -96,13 +101,29 @@ class Controller:
96101

97102

98103
@pytest.fixture
99-
def valid_data():
100-
return dict(foo="bar", quux=42)
104+
def ParentModel(Model):
105+
@dataclass
106+
class ParentModel:
107+
baz: str
108+
child: Model
109+
110+
return ParentModel
101111

102112

103113
@pytest.fixture
104-
def data_with_extra_field():
105-
return dict(foo="bar", quux=42, boz=True)
114+
def ParentController(ParentModel, Controller):
115+
@schema.controller(ParentModel)
116+
class ParentController:
117+
@schema.controller
118+
def child(self, child):
119+
return Controller(child)
120+
121+
return ParentController
122+
123+
124+
@pytest.fixture
125+
def valid_data():
126+
return dict(foo="bar", quux=42)
106127

107128

108129
@pytest.fixture
@@ -111,5 +132,5 @@ def data_with_missing_quux():
111132

112133

113134
@pytest.fixture
114-
def data_with_wrong_quux_type():
115-
return dict(foo="bar", quux="42")
135+
def nested_data(valid_data):
136+
return dict(baz="xyzzy", child=valid_data)

0 commit comments

Comments
 (0)