def test_StrictFilePathField_mommy(): mommy = Mommy(model=FilePathFieldModel) mommy.type_mapping.update(MODEL_MOMMY_MAPPING) with pytest.raises(TypeError): mommy.prepare() with pytest.raises(TypeError): mommy.make()
def test_StrictIntegerField_mommy(): mommy = Mommy(model=IntegerFieldModel) mommy.type_mapping.update(MODEL_MOMMY_MAPPING) try: mommy.prepare() except ValidationError: # this is OK because it means our mapping works pass try: mommy.make() except ValidationError: # this is OK because it means our mapping works pass
def test_StrictTextField_mommy(): mommy = Mommy(model=TextFieldModel) mommy.type_mapping.update(MODEL_MOMMY_MAPPING) try: mommy.prepare() except ValidationError: # the mapping + validator worked but mommy shoved in too much data. pass try: mommy.make() except ValidationError: # the mapping + validator worked but mommy shoved in too much data. pass
def test_if_nullables_are_not_filled_when_fill_null_is_false(self): from model_mommy.mommy import Mommy from model_mommy.models import Person # force None to nullable fields mom = Mommy(Person, fill_null=False) p = mom.make() self.assertEqual(p.bio, None)
def test_if_nullables_are_filled_when_fill_null_is_true(self): from model_mommy.mommy import Mommy from model_mommy.models import Person # force value for nullable fields mom = Mommy(Person, fill_null=True) p = mom.make() self.assertTrue(isinstance(p.bio, basestring))
def test_always_fill_nullables_if_value_provided_via_attrs(self): from model_mommy.mommy import Mommy from model_mommy.models import Person bio_data = 'some bio' mom = Mommy(Person, None) p = mom.make(bio=bio_data) self.assertIn(p.bio, (bio_data, None))
def test_create_person_from_factory_using_paramters(self): from model_mommy.mommy import Mommy from model_mommy.models import Person person_mom = Mommy(Person) person = person_mom.make(happy=False, age=20, gender='M', name='John') self.assertEqual(person.age, 20) self.assertEqual(person.happy, False) self.assertEqual(person.name, 'John') self.assertEqual(person.gender, 'M')
def test_StrictGenericIPAddressField_mommy(): mommy = Mommy(model=GenericIPAddressFieldModel) mommy.type_mapping.update(MODEL_MOMMY_MAPPING) mommy.prepare() mommy.make()
def test_StrictURLField_mommy(): mommy = Mommy(model=URLFieldModel) mommy.type_mapping.update(MODEL_MOMMY_MAPPING) mommy.prepare() mommy.make()
def test_StrictCsvField_mommy(): mommy = Mommy(model=CommaSeparatedIntegerFieldModel) mommy.type_mapping.update(MODEL_MOMMY_MAPPING) mommy.prepare() mommy.make()
def test_StrictPositiveIntegerField_mommy(): mommy = Mommy(model=PositiveIntegerFieldModel) mommy.type_mapping.update(MODEL_MOMMY_MAPPING) mommy.prepare() mommy.make()