diff options
| author | Tim Graham <timograham@gmail.com> | 2015-09-30 14:19:52 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-10-02 08:32:41 -0400 |
| commit | 008a0374e6bc8f465cf95fa72582edf68e6d1ba3 (patch) | |
| tree | bf227bd168cd4b22bc0e3ab8d9ec422fd97d124c /aggregator | |
| parent | 8924336f78549f32c5779c961545a38225cee58f (diff) | |
Fixed #510 -- Prevented stackoverflow questions in the aggregator.
Diffstat (limited to 'aggregator')
| -rw-r--r-- | aggregator/forms.py | 9 | ||||
| -rw-r--r-- | aggregator/tests.py | 19 |
2 files changed, 27 insertions, 1 deletions
diff --git a/aggregator/forms.py b/aggregator/forms.py index 01e91da3..90c455d7 100644 --- a/aggregator/forms.py +++ b/aggregator/forms.py @@ -29,3 +29,12 @@ class FeedModelForm(forms.ModelForm): class Meta: model = Feed exclude = ('feed_type', 'owner', 'approval_status') + + def clean_feed_url(self): + feed_url = self.cleaned_data.get('feed_url') + if feed_url and '//stackoverflow.com' in feed_url: + raise forms.ValidationError( + "Stack Overflow questions tagged with 'django' will appear " + "here automatically." + ) + return feed_url diff --git a/aggregator/tests.py b/aggregator/tests.py index 075266a4..97aecda8 100644 --- a/aggregator/tests.py +++ b/aggregator/tests.py @@ -6,11 +6,12 @@ from django.contrib.auth.models import Group, User from django.core import mail from django.core.management import call_command from django.core.urlresolvers import reverse -from django.test import TestCase +from django.test import SimpleTestCase, TestCase from docs.models import DocumentRelease from . import models +from .forms import FeedModelForm class AggregatorTests(TestCase): @@ -89,3 +90,19 @@ class AggregatorTests(TestCase): self.assertEqual(1, len(mail.outbox)) self.assertEqual(mail.outbox[0].to, [self.user.email]) + + +class TestForms(SimpleTestCase): + def test_rejects_stackoverflow_questions(self): + form = FeedModelForm({ + 'title': 'Asynchronous processing of file upload in Django', + 'feed_url': 'http://stackoverflow.com/questions/11752148/', + 'public_url': 'http://stackoverflow.com/questions/11752148/', + }) + self.assertEqual( + form.errors, + {'feed_url': [ + "Stack Overflow questions tagged with 'django' will appear " + "here automatically." + ]} + ) |
