def test_all_nonstrict_mutation(self): """ If schema instance is mutated, the output of All should reflect it. """ class MySchema(Schema): wow = IntegerField(required=False) instance = MySchema(random=2) instance.wow = 1 allof = All(strict=False)(instance) self.assertEqual({"wow": 1, "random": 2}, allof.serialize()) # strict on the other hand... instance = MySchema(wow=1, random=2) instance.wow = 2 allof = All(strict=True)(instance) self.assertEqual({"wow": 2}, allof.serialize())
def test_all_is_all_by_default(self): class Myschema(Schema): wow = IntegerField() extras = {"wow": 1, "other": 2} m = Myschema(extras) # by default extra keys are passed through allof = All()(m) self.assertEqual(extras, allof.serialize()) # without a schema, we obvs have to pass everything schemaless = All(strict=True)(extras) self.assertEqual(extras, schemaless) # the 'strict' flag means extra kwargs outside the schema # get filtered out. filtered = All(strict=True)(m) self.assertEqual({"wow": 1}, filtered.serialize())