Browse Source

Get rid of leading/trailing whitespace in channel values. This is a typical problem when copy-pasting Slack URLs.

pull/20/head
Pēteris Caune 9 years ago
parent
commit
7f1f177a55
2 changed files with 16 additions and 0 deletions
  1. +4
    -0
      hc/front/forms.py
  2. +12
    -0
      hc/front/tests/test_add_channel.py

+ 4
- 0
hc/front/forms.py View File

@ -12,3 +12,7 @@ class AddChannelForm(forms.ModelForm):
class Meta: class Meta:
model = Channel model = Channel
fields = ['kind', 'value'] fields = ['kind', 'value']
def clean_value(self):
value = self.cleaned_data["value"]
return value.strip()

+ 12
- 0
hc/front/tests/test_add_channel.py View File

@ -24,6 +24,18 @@ class AddChannelTestCase(TestCase):
assert r.status_code == 302 assert r.status_code == 302
assert Channel.objects.count() == 1 assert Channel.objects.count() == 1
def test_it_trims_whitespace(self):
""" Leading and trailing whitespace should get trimmed. """
url = "/integrations/add/"
form = {"kind": "email", "value": " [email protected] "}
self.client.login(username="alice", password="password")
self.client.post(url, form)
q = Channel.objects.filter(value="[email protected]")
self.assertEqual(q.count(), 1)
def test_it_rejects_bad_kind(self): def test_it_rejects_bad_kind(self):
url = "/integrations/add/" url = "/integrations/add/"
form = {"kind": "dog", "value": "Lassie"} form = {"kind": "dog", "value": "Lassie"}


Loading…
Cancel
Save