diff --git a/src/postorius/forms.py b/src/postorius/forms.py index 75f7f65..ea1cafd 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -17,7 +17,7 @@ # Postorius. If not, see . from django import forms -from django.core.validators import validate_email +from django.core.validators import validate_email, URLValidator from django.utils.translation import gettext as _ from fieldset_forms import FieldsetForm from django.forms.models import modelformset_factory @@ -56,7 +56,7 @@ def clean_web_host(self): web_host = self.cleaned_data['web_host'] try: - validate_email('mail@' + web_host) + URLValidator()(web_host) except: raise forms.ValidationError(_("Please enter a valid Web Host")) return web_host diff --git a/src/postorius/tests/test_forms.py b/src/postorius/tests/test_forms.py index 6dc36cc..50c7697 100644 --- a/src/postorius/tests/test_forms.py +++ b/src/postorius/tests/test_forms.py @@ -16,7 +16,7 @@ # Postorius. If not, see . from django.utils import unittest -from postorius.forms import UserPreferences +from postorius.forms import UserPreferences, DomainNew class UserPreferencesTest(unittest.TestCase): @@ -28,3 +28,23 @@ 'receive_own_postings': 'False', }) self.assertTrue(form.is_valid()) + +class DomainNewTest(unittest.TestCase): + + def test_form_fields_webhost(self): + form = DomainNew({ + 'mail_host': 'mailman.most-desirable.org', + 'web_host': 'http://mailman.most-desirable.org', + 'description': 'The Most Desirable organization', + 'contact_address': 'contact@mailman.most-desirable.org', + }) + self.assertTrue(form.is_valid()) + + def test_form_fields_webhost_invalid(self): + form = DomainNew({ + 'mail_host': 'mailman.most-desirable.org', + 'web_host': 'mailman.most-desirable.org', + 'description': 'The Most Desirable organization', + 'contact_address': 'contact@mailman.most-desirable.org', + }) + self.assertFalse(form.is_valid())