def testIfForeignKeyFieldsOfaModelIsPopulated(self): """Tests if the foreign key fields of a model is populated if generate_fk is set to True """ instance = seeder.seed(Space) self.assertEqual(instance.author, None) instance = seeder.seed(Space, generate_fk=True) self.assertTrue(isinstance(instance.author, User)) User.objects.all().delete()
def seed(self, model, properties=None, constraints=None, follow_fk=None, generate_fk=None, follow_m2m=None, factory=None, commit=True): """Generates and returns a new instance of the `model` with properties in `properties`. """ instance = seeder.seed(model=model, constraints=constraints, follow_fk=follow_fk, generate_fk=None, follow_m2m=None, factory=None, model_properties=properties, commit=commit) return instance
def testIfInstanceIsGeneratedWithRequiredAttributes(self): """Tests if the generated instance has the desired properties. """ properties = {"name": "Test Space", "description": "Temporary Description", "public": "False"} instance = seeder.seed(Space, model_properties=properties) self.assertEqual(instance.name, properties["name"]) self.assertEqual(instance.description, properties["description"]) self.assertEqual(instance.public, properties["public"]) # Space.author is a Foreign Key. Since generate_fk is False by default, # Space.author should be None as it will not be populated. self.assertEqual(instance.author, None) self.assertFalse(isinstance(instance.author, User))
def testIfInstanceIsGeneratedWithRequiredAttributes(self): """Tests if the generated instance has the desired properties. """ properties = { 'name': 'Test Space', 'description': 'Temporary Description', 'public': 'False', } instance = seeder.seed(Space, model_properties=properties) self.assertEqual(instance.name, properties['name']) self.assertEqual(instance.description, properties['description']) self.assertEqual(instance.public, properties['public']) #Space.author is a Foreign Key. Since generate_fk is False by default, #Space.author should be None as it will not be populated. self.assertEqual(instance.author, None) self.assertFalse(isinstance(instance.author, User))
def testInstanceIsCreated(self): """Tests if the correct instance of a model is generated. """ created_model = seeder.seed(Space) self.assertTrue(isinstance(created_model, Space))