Skip to content

Commit

Permalink
Inherit from faked classes in tests to satisfy mypy (#8859)
Browse files Browse the repository at this point in the history
* tests: inherit FakeResolverMatcher from django.urls.ResolverMatcher in tests/test_versioning.py

* tests: inherit from rest_framework.versioning.BaseVersioning in tests/test_reverse.py

* fix: isort

---------

Co-authored-by: Piotr Szyma <pszyma@opera.com>
  • Loading branch information
piotrszyma and Piotr Szyma committed Jan 28, 2023
1 parent 2db0c0b commit 22d206c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion tests/test_reverse.py
Expand Up @@ -3,6 +3,7 @@

from rest_framework.reverse import reverse
from rest_framework.test import APIRequestFactory
from rest_framework.versioning import BaseVersioning

factory = APIRequestFactory()

Expand All @@ -16,7 +17,7 @@ def null_view(request):
]


class MockVersioningScheme:
class MockVersioningScheme(BaseVersioning):

def __init__(self, raise_error=False):
self.raise_error = raise_error
Expand Down
8 changes: 4 additions & 4 deletions tests/test_versioning.py
@@ -1,6 +1,6 @@
import pytest
from django.test import override_settings
from django.urls import include, path, re_path
from django.urls import ResolverMatch, include, path, re_path

from rest_framework import serializers, status, versioning
from rest_framework.decorators import APIView
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_url_path_versioning(self):
assert response.data == {'version': None}

def test_namespace_versioning(self):
class FakeResolverMatch:
class FakeResolverMatch(ResolverMatch):
namespace = 'v1'

scheme = versioning.NamespaceVersioning
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_reverse_url_path_versioning(self):
assert response.data == {'url': 'http://testserver/another/'}

def test_reverse_namespace_versioning(self):
class FakeResolverMatch:
class FakeResolverMatch(ResolverMatch):
namespace = 'v1'

scheme = versioning.NamespaceVersioning
Expand Down Expand Up @@ -250,7 +250,7 @@ def test_invalid_url_path_versioning(self):
assert response.status_code == status.HTTP_404_NOT_FOUND

def test_invalid_namespace_versioning(self):
class FakeResolverMatch:
class FakeResolverMatch(ResolverMatch):
namespace = 'v3'

scheme = versioning.NamespaceVersioning
Expand Down

0 comments on commit 22d206c

Please sign in to comment.