def test_make_attrs_with_fill_as_true(self): from model_mommy import mommy from model_mommy.models import Person attrs = mommy.make_attrs(Person, fill_null=True) meta = Person._meta for field in meta.fields: if field.null: self.assertIsNotNone(attrs[field.name])
def test_make_attrs_with_params(self): from model_mommy import mommy from model_mommy.models import Person, GENDER_CH attrs = mommy.make_attrs(Person, name="John", happy=True, gender=GENDER_CH[0][0], age=20) self.assertEqual(attrs["name"], "John") self.assertEqual(attrs["happy"], True) self.assertEqual(attrs["gender"], GENDER_CH[0][0]) self.assertEqual(attrs["age"], 20)
def test_make_attrs_with_fill_as_false(self): from model_mommy import mommy from model_mommy.models import Person attrs = mommy.make_attrs(Person, fill_null=False) attrs_keys = attrs.keys() meta = Person._meta for field in meta.fields: if type(field) not in (AutoField, GenericRelation) and\ not isinstance(field, RelatedField): if field.null: self.assertNotIn(field.name, attrs_keys) else: self.assertIsNotNone(attrs[field.name])
def test_make_attrs_without_params(self): from model_mommy import mommy from model_mommy.models import Person attrs = mommy.make_attrs(Person) attrs_keys = attrs.keys() meta = Person._meta fields = meta.fields for field in fields: # no related field is created if isinstance(field, RelatedField) or\ type(field) in (AutoField, GenericRelation): self.assertNotIn(field.name, attrs_keys) else: if not field.null: self.assertIn(field.name, attrs_keys)