def test_multiple_fragments_with_common_parent(self): factory = Factory(self.collection) factory.fragment('versioned', {"v": 5}) factory.fragment("alert_prefs", { "emails": True }, parent='versioned') factory.fragment('audit_trail', { "actions": ['created', 'updated'] }, parent='versioned') factory.document("user", { "first_name": 'John', "last_name": 'Smith', "age": 32, "alerts": factory.embed("alert_prefs"), "audit_trail": factory.embed("audit_trail") }) self.assertDictEqual(factory.build("user"), { "first_name": "John", "last_name": "Smith", "age": 32, "alerts": { "emails": True, "v": 5 }, "audit_trail": { "actions": ['created', 'updated'], "v": 5 } })
def test_fragments_with_only_traits(self): factory = Factory(self.collection) factory.trait('versioned', {"v": 5}) factory.fragment("alert_prefs", traits=['versioned']) factory.document("user", { "first_name": 'John', "last_name": 'Smith', "age": 32, "alerts": factory.embed("alert_prefs") }) self.assertDictEqual(factory.build("user"), { "first_name": "John", "last_name": "Smith", "age": 32, "alerts": { "v": 5 } })
def test_fragments(self): factory = Factory(self.collection) factory.fragment("alert_prefs", { "emails": True }) factory.document("user", { "first_name": 'John', "last_name": 'Smith', "age": 32, "alerts": factory.embed("alert_prefs") }) self.assertDictEqual(factory.build("user"), { "first_name": "John", "last_name": "Smith", "age": 32, "alerts": { "emails": True } })
def test_fragments_with_inheritance(self): factory = Factory(self.collection) factory.fragment('versioned', {"v": 5}) factory.fragment("alert_prefs", { "emails": True }, parent='versioned') factory.document("user", { "first_name": 'John', "last_name": 'Smith', "age": 32, "alerts": factory.embed("alert_prefs") }) self.assertDictEqual(factory.build("user"), { "first_name": "John", "last_name": "Smith", "age": 32, "alerts": { "emails": True, "v": 5 } })
def test_embed_fragment_with_inline_trait(self): factory = Factory(self.collection) factory.trait('versioned', {"v": 5}) factory.trait('sms', {"sms": True}) factory.fragment("alert_prefs", { "emails": True }, traits=['versioned']) factory.document("user", { "first_name": 'John', "last_name": 'Smith', "age": 32, "alerts": factory.embed("alert_prefs", traits=["sms"]) }) self.assertDictEqual(factory.build("user"), { "first_name": "John", "last_name": "Smith", "age": 32, "alerts": { "emails": True, "v": 5, "sms": True } })