The generated class should check in the setter that a proper value for thing1 field is given (not None). Following modified test (in test_compiled_files.py should pass:
def test_record_with_record(self):
""" tests nested records work """
from records import RecordWithRecord
from records import Thing
data1 = {'thing1': {'id': 10}, 'thing2': {'id': 0}}
data2 = {'thing1': Thing({'id': 10}), 'thing2': Thing({'id': 0})}
data_with_default = {'thing1': {'id': 10}}
invalid_data = {'thing1': None}
record1 = RecordWithRecord(data1)
record2 = RecordWithRecord(data2)
record3 = RecordWithRecord(data_with_default)
self.assertEqual(
record1.serialize(),
record2.serialize(),
'nested records should be equal'
)
self.assertEqual(
record1.serialize(),
record3.serialize(),
'records should be equal'
)
with self.assertRaises(TypeError):
RecordWithRecord(invalid_data)
Consider following definition
The generated class should check in the setter that a proper value for
thing1
field is given (notNone
). Following modified test (intest_compiled_files.py
should pass: