Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings raised during testing. #522

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,15 +1436,16 @@ def partial_update(self, request, *args, **kwargs):
assert 'required' in schema['components']['schemas']['X']


class M3(models.Model):
related_field = models.ForeignKey(SimpleModel, on_delete=models.PROTECT, editable=False)
many_related = models.ManyToManyField(SimpleModel, related_name='+')


@pytest.mark.parametrize('path', [
r'x/(?P<related_field>[0-9a-f-]{36})',
r'x/<related_field>',
])
def test_path_param_from_related_model_pk_without_primary_key_true(no_warnings, path):
class M3(models.Model):
related_field = models.ForeignKey(SimpleModel, on_delete=models.PROTECT, editable=False)
many_related = models.ManyToManyField(SimpleModel)

class M3Serializer(serializers.ModelSerializer):
class Meta:
fields = '__all__'
Expand Down Expand Up @@ -1813,19 +1814,19 @@ def test_categorized_choices(no_warnings):
('unknown', 'Unknown'),
]

class M6(models.Model):
class M9(models.Model):
cat_choice = models.CharField(max_length=10, choices=media_choices)

class M6Serializer(serializers.ModelSerializer):
class M9Serializer(serializers.ModelSerializer):
audio_choice = serializers.ChoiceField(choices=media_choices_audio)

class Meta:
fields = '__all__'
model = M6
model = M9

class XViewset(viewsets.ModelViewSet):
serializer_class = M6Serializer
queryset = M6.objects.none()
serializer_class = M9Serializer
queryset = M9.objects.none()

with mock.patch(
'drf_spectacular.settings.spectacular_settings.ENUM_NAME_OVERRIDES',
Expand Down Expand Up @@ -2317,6 +2318,10 @@ def pi(request, foo):
}


class PathParameterLookupModel(models.Model):
field = models.IntegerField()


@pytest.mark.parametrize(['path_func', 'path_str', 'pattern', 'parameter_types'], [
# django typed -> use
(path, '/{id}/', '<int:pk>/', ['integer']),
Expand All @@ -2331,9 +2336,6 @@ def pi(request, foo):
(re_path, '/{field}/t/{id}/', r'^(?P<field>[A-Z\(\)]+)/t/(?P<pk>[^/.]+)/', ['string', 'integer']),
])
def test_path_parameter_priority_matching(no_warnings, path_func, path_str, pattern, parameter_types):
class PathParameterLookupModel(models.Model):
field = models.IntegerField()

class LookupSerializer(serializers.ModelSerializer):
class Meta:
model = PathParameterLookupModel
Expand Down
7 changes: 4 additions & 3 deletions tests/test_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def test_namespace_versioning(no_warnings, viewset_cls, version):
assert_schema(schema, f'tests/test_versioning_{version}.yml')


class LookupModel(models.Model):
field = models.IntegerField()


@pytest.mark.parametrize(['path_func', 'path_str', 'pattern', ], [
(path, '{id}/', '<int:pk>/'),
(path, '{id}/', '<pk>/'),
Expand All @@ -113,9 +117,6 @@ def test_namespace_versioning(no_warnings, viewset_cls, version):
(re_path, '{field}/t/{id}/', r'^(?P<field>[A-Z\(\)]+)/t/(?P<pk>[^/.]+)/'),
])
def test_namespace_versioning_urlpatterns_simplification(no_warnings, path_func, path_str, pattern):
class LookupModel(models.Model):
field = models.IntegerField()

class LookupSerializer(serializers.ModelSerializer):
class Meta:
model = LookupModel
Expand Down