Url not parsed when testing a ModelViewSet

Solution 1:

When testing the view directly as you are doing, you are bypassing the url resolving/mapping logic. Therefore, you should pass the parameters as args/kwargs, in the end you are calling the foo function:

def test_foo(client: Client, db):
    request = factory.post(f'/api/resource/1/foo/')
    view = ResourceViewSet.as_view({'post': 'foo'})
    response = view(request, pk=1)

If you'd like to test the whole stack, also the urls, I'd recommend you use the APIClient.