コード例 #1
0
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()
コード例 #2
0
    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))
コード例 #3
0
    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)
コード例 #4
0
    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))
コード例 #5
0
    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')
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
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)
コード例 #9
0
def exist_a_project(step):
    for project_hashes in step.hashes:
        mom = Mommy(Project, False)
        project = mom.make_one(name=project_hashes.get('name'))
コード例 #10
0
def test_StrictGenericIPAddressField_mommy():
    mommy = Mommy(model=GenericIPAddressFieldModel)
    mommy.type_mapping.update(MODEL_MOMMY_MAPPING)
    mommy.prepare()
    mommy.make()
コード例 #11
0
def test_StrictURLField_mommy():
    mommy = Mommy(model=URLFieldModel)
    mommy.type_mapping.update(MODEL_MOMMY_MAPPING)
    mommy.prepare()
    mommy.make()
コード例 #12
0
def test_StrictCsvField_mommy():
    mommy = Mommy(model=CommaSeparatedIntegerFieldModel)
    mommy.type_mapping.update(MODEL_MOMMY_MAPPING)
    mommy.prepare()
    mommy.make()
コード例 #13
0
def test_StrictPositiveIntegerField_mommy():
    mommy = Mommy(model=PositiveIntegerFieldModel)
    mommy.type_mapping.update(MODEL_MOMMY_MAPPING)
    mommy.prepare()
    mommy.make()
コード例 #14
0
ファイル: steps.py プロジェクト: rodrigomanhaes/nsi_site
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'))
コード例 #15
0
ファイル: steps.py プロジェクト: rodrigomanhaes/nsi_site
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'))
コード例 #16
0
ファイル: steps.py プロジェクト: rodrigomanhaes/nsi_site
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'))
コード例 #17
0
ファイル: steps.py プロジェクト: rodrigomanhaes/nsi_site
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'))
コード例 #18
0
ファイル: steps.py プロジェクト: rodrigomanhaes/nsi_site
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'))