diff --git a/hc/front/forms.py b/hc/front/forms.py index 328caeeb..5cea3fc8 100644 --- a/hc/front/forms.py +++ b/hc/front/forms.py @@ -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() diff --git a/hc/front/tests/test_add_channel.py b/hc/front/tests/test_add_channel.py index 3944fb54..3d194cde 100644 --- a/hc/front/tests/test_add_channel.py +++ b/hc/front/tests/test_add_channel.py @@ -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"}