URLField serializer is not playing nice with "built in" test server address http://testserver #9705
-
Initially encountered in our
with such minimal reproducer depicting the issue: from rest_framework import serializers
class MySerializer(serializers.Serializer):
url = serializers.URLField()
def test_valid_url():
serializer = MySerializer(data={'url': 'http://testserver/path'})
serializer.is_valid() running pytest on which would give you an ugly excepted demanding configuration since i18n would not yet be configured to give a proper localized error... but replacing that simple hostname
So
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
you should have open a discussion first |
Beta Was this translation helpful? Give feedback.
-
It does. I was able to reproduce the problem with a simpler test case: from django.core.validators import URLValidator
def test_url_validator():
validator = URLValidator()
assert validator("http://testserver/path") is None # fails
Change the base URL to something with a TLD? I usually have a constant in my settings to be able to switch it between test/dev/staging/prod. Django has the standard Not much specific to DRF, basically, it's all Django. |
Beta Was this translation helpful? Give feedback.
It does. I was able to reproduce the problem with a simpler test case:
Change the base URL to something with a TLD? I usually have a constant in my settings to be able to switch it between test/dev/staging/prod. Django has the standard
MEDIA_URL
for media file, you can make up your own to fit your use case. Thistestserver
doesn't come from DRF either, it's vanilla Django too.Not much specific t…