django test RequestFactory cannot get route parameter to work
<p>I have a problem that I don't know how to make it work. </p>

<p>urls.py:</p>

<pre><code>urlpatterns = [
    url(r'athletes/search$', SearchAthletes.as_view()),
    url(r'athletes/([0-9]+)$', ViewAthlete.as_view())
]
</code></pre>

<p>views.py:</p>

<pre><code>class ViewAthlete(APIView):

    def get(self, request, id, format=None):
        athlete = Athlete.objects.get(id=id)
        serializer = AthleteSerializer(athlete)
        return Response(serializer.data)
</code></pre>

<p>test.py:</p>

<pre><code>def test_view_athlete(self):
    tmp = Athlete.objects.order_by('?')[0]

    request = self.factory.get('/_api/v1/athletes/' + str(tmp.id))
    request.user = AnonymousUser()

    response = ViewAthlete.as_view()(request)
    self.assertEquals(response.data.id, tmp.id)
</code></pre>

<p>I keep getting the following error:</p>

<blockquote>
  <p>Traceback (most recent call last):
    File "/tests.py", line 44, in test_view_athlete
      response = ViewAthlete.as_view()(request)</p>
  
  <p>File "/venv/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
      return view_func(*args, **kwargs)</p>
  
  <p>File "/venv/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
      return self.dispatch(request, *args, **kwargs)</p>
  
  <p>File "/venv/lib/python3.5/site-packages/rest_framework/views.py", line 474, in dispatch
      response = self.handle_exception(exc)</p>
  
  <p>File "/venv/lib/python3.5/site-packages/rest_framework/views.py", line 471, in dispatch
      response = handler(request, *args, **kwargs)
  TypeError: get() missing 1 required positional argument: 'id'</p>
</blockquote>

<p>To my understanding, the problem is that, there is no <code>id</code> parameter passed to <code>get</code> function of <code>ViewAthelete</code> view class. What is the reason for this? In development environment (not testing), it displays the data but testing environment doesn't recognize the arguments from the route.</p>