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

This commit is contained in:
Pēteris Caune 2015-12-11 18:34:40 +02:00
parent 88818c94b5
commit 7f1f177a55
2 changed files with 16 additions and 0 deletions

View File

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

View File

@ -24,6 +24,18 @@ class AddChannelTestCase(TestCase):
assert r.status_code == 302
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": " alice@example.org "}
self.client.login(username="alice", password="password")
self.client.post(url, form)
q = Channel.objects.filter(value="alice@example.org")
self.assertEqual(q.count(), 1)
def test_it_rejects_bad_kind(self):
url = "/integrations/add/"
form = {"kind": "dog", "value": "Lassie"}