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_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_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_creating_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_one(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_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_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 factory(model, **kwargs): """ Creates a factory boy factory class """ ns = {'Meta': type('Meta', (), {'model': model})} # Handle explicitly declared values for k, v in kwargs: ns[k] = explicit_declaration(model, k, v) # Create mommy instance to help with automatic value generation mommy = Mommy(model) # Create implicit declarations for field in model._meta.fields: if not requires_declaration(model, field.name, ns): continue ns[field.name] = implicit_declaration(model, field.name, ns, mommy) return type(model.__name__ + 'Factory', (BoogieFactory, ), ns)
def exist_a_project(step): for project_hashes in step.hashes: mom = Mommy(Project, False) project = mom.make_one(name=project_hashes.get('name'))
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()
def exist_a_news(step): for news_hashes in step.hashes: mom = Mommy(News, False) news = mom.make_one(title=news_hashes.get('title'), summary=news_hashes.get('summary'))
def exist_a_tool(step): for tool_hashes in step.hashes: mom = Mommy(Tool, False) tool = mom.make_one(name=tool_hashes.get('name'), highlight=tool_hashes.get('highlight'))
def exist_a_project(step): for project_hashes in step.hashes: mom = Mommy(Project, False) project = mom.make_one(name=project_hashes.get('name'), status=project_hashes.get('status'))