From 22d206c1e0dbc03840c4d190f7eda537c0f2010a Mon Sep 17 00:00:00 2001 From: piotrszyma Date: Sat, 28 Jan 2023 12:18:58 +0100 Subject: [PATCH] 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 --- tests/test_reverse.py | 3 ++- tests/test_versioning.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_reverse.py b/tests/test_reverse.py index b26b448c9..b89f5be43 100644 --- a/tests/test_reverse.py +++ b/tests/test_reverse.py @@ -3,6 +3,7 @@ from django.urls import NoReverseMatch, path from rest_framework.reverse import reverse from rest_framework.test import APIRequestFactory +from rest_framework.versioning import BaseVersioning factory = APIRequestFactory() @@ -16,7 +17,7 @@ urlpatterns = [ ] -class MockVersioningScheme: +class MockVersioningScheme(BaseVersioning): def __init__(self, raise_error=False): self.raise_error = raise_error diff --git a/tests/test_versioning.py b/tests/test_versioning.py index d40d54229..93f61d2be 100644 --- a/tests/test_versioning.py +++ b/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 @@ -126,7 +126,7 @@ class TestRequestVersion: assert response.data == {'version': None} def test_namespace_versioning(self): - class FakeResolverMatch: + class FakeResolverMatch(ResolverMatch): namespace = 'v1' scheme = versioning.NamespaceVersioning @@ -199,7 +199,7 @@ class TestURLReversing(URLPatternsTestCase, APITestCase): assert response.data == {'url': 'http://testserver/another/'} def test_reverse_namespace_versioning(self): - class FakeResolverMatch: + class FakeResolverMatch(ResolverMatch): namespace = 'v1' scheme = versioning.NamespaceVersioning @@ -250,7 +250,7 @@ class TestInvalidVersion: 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