mardi 29 septembre 2015

How to test OneToOne with User?

I trying to write a test, which asserts if a profile model is created, once a user model is.

My profile model looks like this

class Profile(models.Model):
    user = models.OneToOneField(User, unique=True)
    image_url = models.URLField(max_length=500, blank=True)
    address = models.ForeignKey(Address, null=True, blank=True)

My test method looks like

class TestUserBasics(TestCase):
    def test_profile_user_one_to_one(self):
        u = user.objects.create()
        u.save()
        self.assertTrue(u.profile != None)

The test fails, for the test user has no profile field. However in manage.py shell the same scenario ends positive.

What am I missing?

Aucun commentaire:

Enregistrer un commentaire