Unit testing - self.assertEqual(login, True)

184 views
Skip to first unread message

Pepsodent Cola

unread,
Jul 3, 2014, 8:09:41 AM7/3/14
to django...@googlegroups.com
I want to run a unit test for a user logging in but I get error.  What am I doing wrong?


from django.test import TestCase
from userprofile.models import UserProfile
from django.contrib.auth.models import User

class UserProfileTest(TestCase):
    # User factory method
    def create_user(self, username='joe', password='joe'):
        return User.objects.create(username=username, password=password)

    # Create User
    def test_creation_USER(self):
        u = self.create_user()
        self.assertTrue(isinstance(u, User))
        login = self.client.login(username='joe', password='joe')
        self.assertEqual(login, True)

======================================================================
FAIL: test_creation_USER (userprofile.tests.UserProfileTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/Django/project/userprofile/tests.py", line 44, in test_creation_USER
    self.assertEqual(login, True)
AssertionError: False != True

----------------------------------------------------------------------


Amim Knabben

unread,
Jul 3, 2014, 8:57:24 AM7/3/14
to django...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5d49c776-fe1f-4702-abc1-d2c99468d82a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

AMIM KNABBEN
+55 48 9680 9126 (m)

Pepsodent Cola

unread,
Jul 3, 2014, 11:30:29 AM7/3/14
to django...@googlegroups.com
Thanks!  I see what I did wrong now.


class UserProfileTest(TestCase):
    # Create User
    def setUp(self):
        self.user = User.objects.create_user(username='captain', password='america')

    # Logged in
    def test_VIEW_USER__Logged_in(self):
        self.assertTrue(isinstance(self.user, User))
        login = self.client.login(username='captain', password='america')
        self.assertEqual(login, True)



https://docs.djangoproject.com/en/1.5/intro/tutorial05/#testing-our-new-view
Reply all
Reply to author
Forward
0 new messages