Skip to content

Commit

Permalink
Fixup URL - default blank to False
Browse files Browse the repository at this point in the history
  • Loading branch information
santos22 committed Apr 30, 2020
1 parent 1caf663 commit 55e7cf3
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 33 deletions.
14 changes: 0 additions & 14 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,6 @@ def save(self, commit=True):
self.project.webhook_notifications.add(self.webhook)
return self.project

def clean_url(self):
url = self.cleaned_data.get('url')
if not url:
raise forms.ValidationError(
_('This field is required.')
)
parsed_url = urlparse(url)

if parsed_url.scheme not in ('http', 'https'):
raise forms.ValidationError(
_('Please provide an http or https URL.')
)
return url

class Meta:
model = WebHook
fields = ['url']
Expand Down
1 change: 0 additions & 1 deletion readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,6 @@ def __str__(self):
class WebHook(Notification):
url = models.URLField(
max_length=600,
blank=True,
help_text=_('URL to send the webhook to'),
)

Expand Down
19 changes: 1 addition & 18 deletions readthedocs/rtd_tests/tests/test_project_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def test_webhookform(self):
form = WebHookForm(data=data, project=self.project)
self.assertTrue(form.is_valid())
form.save()
self.assertEqual(self.project.webhook_notifications.all().count(), 1)
self.assertEqual(self.project.webhook_notifications.all().count(), 2)

def test_wrong_inputs_in_webhookform(self):
self.assertEqual(self.project.webhook_notifications.all().count(), 0)
Expand All @@ -718,22 +718,6 @@ def test_wrong_inputs_in_webhookform(self):
self.assertDictEqual(form.errors, {'url': ['Enter a valid URL.']})
self.assertEqual(self.project.webhook_notifications.all().count(), 0)

data = {
'url': 'example.com'
}
form = WebHookForm(data=data, project=self.project)
self.assertFalse(form.is_valid())
self.assertDictEqual(form.errors, {'url': ['Please provide an http or https URL.']})
self.assertEqual(self.project.webhook_notifications.all().count(), 0)

data = {
'url': 'www.example.com'
}
form = WebHookForm(data=data, project=self.project)
self.assertFalse(form.is_valid())
self.assertDictEqual(form.errors, {'url': ['Please provide an http or https URL.']})
self.assertEqual(self.project.webhook_notifications.all().count(), 0)

def test_emailhookform(self):
self.assertEqual(self.project.emailhook_notifications.all().count(), 0)

Expand Down Expand Up @@ -764,7 +748,6 @@ def test_wrong_inputs_in_emailhookform(self):
self.assertDictEqual(form.errors, {'email': ['This field is required.']})
self.assertEqual(self.project.emailhook_notifications.all().count(), 0)


class TestProjectEnvironmentVariablesForm(TestCase):

def setUp(self):
Expand Down

0 comments on commit 55e7cf3

Please sign in to comment.