Simple, first create a user model and do the following:
def setup(self):
self.user = User.objects.filter(pk=1)
self.userprofile = UserProfile.objects.create(first_name = "Harjot")
def test_profile(self):
self.assertEqual(self.userprofile.first_name, "Harjot")
add any other not optional fields. Hope it works.
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'
On Sat, Nov 23, 2013 at 2:49 PM, Simone Dalla <simo...@gmail.com> wrote:New Error.
> 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)
Traceback (most recent call last):File "/home/harjot/Automation/../Automation/tcc/tests.py", line 22,
in test_profile
self.assertEqual(self.userprofile.user_id, 1)
AttributeError: 'QuerySet' object has no attribute 'user_id'