Inherit from faked classes in tests to satisfy mypy (#8859)

* 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>
This commit is contained in:
piotrszyma 2023-01-28 12:18:58 +01:00 committed by GitHub
parent 2db0c0bf0a
commit 22d206c1e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -3,6 +3,7 @@ from django.urls import NoReverseMatch, path
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from rest_framework.versioning import BaseVersioning
factory = APIRequestFactory() factory = APIRequestFactory()
@ -16,7 +17,7 @@ urlpatterns = [
] ]
class MockVersioningScheme: class MockVersioningScheme(BaseVersioning):
def __init__(self, raise_error=False): def __init__(self, raise_error=False):
self.raise_error = raise_error self.raise_error = raise_error

View File

@ -1,6 +1,6 @@
import pytest import pytest
from django.test import override_settings 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 import serializers, status, versioning
from rest_framework.decorators import APIView from rest_framework.decorators import APIView
@ -126,7 +126,7 @@ class TestRequestVersion:
assert response.data == {'version': None} assert response.data == {'version': None}
def test_namespace_versioning(self): def test_namespace_versioning(self):
class FakeResolverMatch: class FakeResolverMatch(ResolverMatch):
namespace = 'v1' namespace = 'v1'
scheme = versioning.NamespaceVersioning scheme = versioning.NamespaceVersioning
@ -199,7 +199,7 @@ class TestURLReversing(URLPatternsTestCase, APITestCase):
assert response.data == {'url': 'http://testserver/another/'} assert response.data == {'url': 'http://testserver/another/'}
def test_reverse_namespace_versioning(self): def test_reverse_namespace_versioning(self):
class FakeResolverMatch: class FakeResolverMatch(ResolverMatch):
namespace = 'v1' namespace = 'v1'
scheme = versioning.NamespaceVersioning scheme = versioning.NamespaceVersioning
@ -250,7 +250,7 @@ class TestInvalidVersion:
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
def test_invalid_namespace_versioning(self): def test_invalid_namespace_versioning(self):
class FakeResolverMatch: class FakeResolverMatch(ResolverMatch):
namespace = 'v3' namespace = 'v3'
scheme = versioning.NamespaceVersioning scheme = versioning.NamespaceVersioning