Hey Guys, I am trying to write some unit test cases for web application I am working on.
This unit test needs authentication so in my unit test I need to create a user and pass two extra parameters to get object of new model "UserProfile" which is using relation to django User class. Here is my model User profile: class UserProfile(models.Model): user = models.ForeignKey(User,unique=True) companyId = models.IntegerField(null=True,blank=True) # companyId of particular user role = models.CharField(null=True,blank=True,max_length=50) And here is my unit test case: class IngredientAllTestCase(InitialSetUp,TestCase): def setUp(self): Ingredient.objects.create(name='sugar3',status='published',description='no need',config='null') self.user=User(username='jimish') password = 'password' self.user.set_password(password) self.companyId = '227329282382' self.role = 'QA Manager' self.user.save() UserProfileObj = UserProfile.objects.create(user=self.user,companyId=self.companyId,role=self.role) self.client = Client() self.factory = RequestFactory() self.client.login(username=self.user.username, password=password) def test_IngredientAll(self): url = reverse('lib:ingredient-all') response = self.client.get(url) self.assertEqual(response.status_code,status.HTTP_200_OK) While running test case, I am getting error: MultipleObjectsReturned: get() returned more than one UserProfile -- it returned 2! Lookup parameters were {'user': u'537d804b041b00108380b861'} So, please help me. Any answers would be helpful and I would like to thank you guys in advance. -- 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+unsubscr...@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/9c80a08e-728d-49a1-8980-ffeb62c2d3a0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.