Re: django tests
2013/11/23 Harjot Mann <harjotmann1992@gmail.com>
-- Now my code is this:
class UserProfileTestCase(TestCase):
def setUp(self):
self.userprofile = UserProfile.objects.filter(user_id =
1).update(first_name = "Harjot")
def test_profile(self):
self.assertEqual(self.userprofile.user_id, 1)
and I am getting this error:
Traceback (most recent call last):File "/home/harjot/Automation/../Automation/tcc/tests.py", line 20,
in test_profile
self.assertEqual(self.userprofile.user_id, 1)
AttributeError: 'int' object has no attribute 'user_id'
The method update return the number of rows matched (read the django docs at https://docs.djangoproject.com/en/1.5/ref/models/querysets/#update) not objects updated. Your code:
"self.userprofile = UserProfile.objects.filter(user_id =1).update(first_name = "Harjot")"
set the variable "self.userprofile" with the number of rows matched by "UserProfile.objects.filter(user_id =1)",
therefore "self.userprofile" is an int object as the exception is telling you ("AttributeError: 'int' object has no attribute 'user_id'")
the correct code should be
...
self.userprofile = UserProfile.objects.filter(user_id =1)
self.userprofile.update(first_name = "Harjot")
...
self.assertEqual(self.userprofile.user_id, 1)
Cheers,
Simone
Simo
- Registered Linux User #395060
- Software is like sex, it is better when it is free --> Linus B. Torvalds
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CAKZfPmwb7iq106fw5tNrd065Zp9dWzDBaghOQr5uqwy3E8tZRQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home