def test_accept_model_as_string(self):
     person = mommy.make_one('model_mommy.person')
     self.assertTrue(isinstance(person, Person))
     person = mommy.prepare_one('model_mommy.Person')
     self.assertTrue(isinstance(person, Person))
     people = mommy.make_many('model_mommy.person')
     [self.assertTrue(isinstance(person, Person)) for person in people]
Esempio n. 2
0
 def test_accept_model_as_string(self):
     person = mommy.make_one('model_mommy.person')
     self.assertIsInstance(person, Person)
     person = mommy.prepare_one('model_mommy.Person')
     self.assertIsInstance(person, Person)
     people = mommy.make_many('model_mommy.person')
     [self.assertIsInstance(person, Person) for person in people]
Esempio n. 3
0
    def test_prepare_one_should_not_create_one_object(self):
        dog = mommy.prepare_one(Dog)
        self.assertTrue(isinstance(dog, Dog))
        self.assertTrue(isinstance(dog.owner, Person))

        # makes sure database is clean
        self.assertEqual(Person.objects.all().count(), 0)
        self.assertEqual(Dog.objects.all().count(), 0)
Esempio n. 4
0
 def test_register_rule_no_score(self):
     rulecard = mommy.prepare_one(RuleCard)
     scoresheet = _prepare_scoresheet(self.game, "p1", blue = 1)
     scoresheet.register_score_from_rule(rulecard, 'test', is_random = True)
     self.assertEqual(rulecard, scoresheet.scores_from_rule[0].rulecard)
     self.assertEqual('test', scoresheet.scores_from_rule[0].detail)
     self.assertIsNone(scoresheet.scores_from_rule[0].score)
     self.assertTrue(getattr(scoresheet.scores_from_rule[0], 'is_random', False))
    def test_prepare_one_should_not_persist_one_object(self):
        person = mommy.prepare_one(Person)
        self.assertTrue(isinstance(person, Person))

        # makes sure database is clean
        self.assertEqual(Person.objects.all().count(), 0)

        self.assertEqual(person.id, None)
    def test_prepare_one_should_not_create_one_object(self):
        dog = mommy.prepare_one(Dog)
        self.assertTrue(isinstance(dog, Dog))
        self.assertTrue(isinstance(dog.owner, Person))

        # makes sure database is clean
        self.assertEqual(Person.objects.all().count(), 0)
        self.assertEqual(Dog.objects.all().count(), 0)
Esempio n. 7
0
    def test_prepare_one_should_not_persist_one_object(self):
        person = mommy.prepare_one(Person)
        self.assertTrue(isinstance(person, Person))

        # makes sure database is clean
        self.assertEqual(Person.objects.all().count(), 0)

        self.assertEqual(person.id, None)
Esempio n. 8
0
    def test_prepare_one_should_not_persist_one_object(self):
        from model_mommy import mommy
        from model_mommy.models import Person

        person = mommy.prepare_one(Person)
        self.assertTrue(isinstance(person, Person))
        
        # makes sure database is clean
        self.assertEqual(Person.objects.all().count(), 0)
Esempio n. 9
0
 def test_prepare_one_should_not_persist_one_object(self):
     """
     prepare_one method is deprecated, so this test must be removed when the
     method is removed
     """
     person = mommy.prepare_one(Person)
     self.assertIsInstance(person, Person)
     self.assertEqual(Person.objects.all().count(), 0)
     self.assertEqual(person.id, None)
Esempio n. 10
0
 def test_prepare_one_should_not_persist_one_object(self):
     """
     prepare_one method is deprecated, so this test must be removed when the
     method is removed
     """
     person = mommy.prepare_one(Person)
     self.assertIsInstance(person, Person)
     self.assertEqual(Person.objects.all().count(), 0)
     self.assertEqual(person.id, None)
Esempio n. 11
0
    def test_prepare_model_with_M2MField_does_not_hit_database(self):
        from model_mommy.models import DummyM2MModel
        from model_mommy.models import DummyRelationModel
        from model_mommy import mommy

        dummy_m2m_model = mommy.prepare_one(DummyM2MModel)

        # relation is not created if parent model is not persisted
        self.assertEqual(DummyRelationModel.objects.count(), 0)
        self.assertRaises(ValueError, lambda: dummy_m2m_model.m2m_field)
Esempio n. 12
0
    def test_prepare_one_object_with_fill_null_as_false(self):
        from model_mommy import mommy
        from model_mommy.models import Person

        person = mommy.prepare_one(Person, fill_null=False)
        meta = person._meta
        fields = meta.fields

        for field in fields:
            name = field.name

            if field.null:
                field_value = getattr(person, name)
                self.assertIsNone(field_value)
Esempio n. 13
0
 def test_ForeignKey_model_field_population_should_work_with_prepare(self):
     dog = mommy.prepare_one(Dog, breed='X1', owner__name='Bob')
     self.assertEqual('X1', dog.breed)
     self.assertEqual('Bob', dog.owner.name)
Esempio n. 14
0
 def test_unicode_regression(self):
     obj = mommy.prepare_one(u'generic.Person')
     self.assertIsInstance(obj, Person)
Esempio n. 15
0
 def test_model_class(self):
     obj = mommy.prepare_one(Person)
     self.assertIsInstance(obj, Person)
Esempio n. 16
0
 def test_model_string(self):
     obj = mommy.prepare_one('Person')
     self.assertIsInstance(obj, Person)
Esempio n. 17
0
 def test_raise_on_ambiguous_model_string(self):
     with self.assertRaises(AmbiguousModelName):
         obj = mommy.prepare_one('Ambiguous')
Esempio n. 18
0
 def test_ForeignKey_model_field_population_should_work_with_prepare(self):
     dog = mommy.prepare_one(Dog, breed='X1', owner__name='Bob')
     self.assertEqual('X1', dog.breed)
     self.assertEqual('Bob', dog.owner.name)