I want to make tests for app, and I just can't make it right. I have such function:
def get_queryset(self):
return User.objects.filter(id=self.request.user.id)
And I wrote such test:
def test_Uzytkownik_get_query(self):
self.c = Client()
self.user = User.objects.create_user(username='john', email='lennon@thebeatles.com', password='johnpassword')
self.c.login(username='john', password='johnpassword')
response = self.c.get('/')
self.assertEqual(UzytkownikViewSet.get_queryset(response.context['user']),"john")
But I get this
AttributeError: 'User' object has no attribute 'request'
I know that john isn't actually result of this queryset, but i can't do any test because of this: self.request.user.whatever.
@Edit
Sorry guys I didn't give this information. I'm using Django, and class in which is this function looks like this:
class UzytkownikViewSet(viewsets.ModelViewSet):
def get_queryset(self): return
User.objects.filter(id=self.request.user.id)