Get to self.request.user in test python
<p>I want to make tests for app, and I just can't make it right.
I have such function:</p>

<pre><code>def get_queryset(self):
    return User.objects.filter(id=self.request.user.id)
</code></pre>

<p>And I wrote such test:</p>

<pre><code> 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")
</code></pre>

<p>But I get this </p>

<pre><code>AttributeError: 'User' object has no attribute 'request'
</code></pre>

<p>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.</p>

<p>@Edit</p>

<p>Sorry guys I didn't give this information. I'm using Django, and class in which is this function looks like this: </p>

<pre><code>class UzytkownikViewSet(viewsets.ModelViewSet): 
    def get_queryset(self): return  
        User.objects.filter(id=self.request.user.id)
</code></pre>