Esempio n. 1
0
def test_collections_form_unicode_slug():
    u = Mock()
    u.collections.filter.return_value.count.return_value = False
    f = forms.CollectionForm(dict(slug=u'Ελλην', listed=True, name='  '),
                             initial=dict(author=u))
    assert 'name' in f.errors
    assert 'slug' not in f.errors
Esempio n. 2
0
    def test_honeypot_not_required(self):
        author = UserProfile.objects.get(pk=9945)

        form = forms.CollectionForm(
            initial={'author': author},
            data={
                'name': 'test collection',
                'slug': 'test-collection',
                'listed': False,
            }
        )

        assert form.is_valid()
Esempio n. 3
0
 def test_icon(self, update_mock):
     collection = Collection.objects.get(pk=57181)
     # TODO(andym): altering this form is too complicated, can we simplify?
     form = forms.CollectionForm(
                     {'listed': collection.listed,
                      'slug': collection.slug,
                      'name': collection.name},
                     instance=collection,
                     files={'icon': get_uploaded_file('transparent.png')},
                     initial={'author': collection.author,
                              'application_id': collection.application.pk})
     assert form.is_valid()
     form.save()
     assert update_mock.called
Esempio n. 4
0
    def test_honeypot_fails_on_entry(self):
        author = UserProfile.objects.get(pk=9945)

        form = forms.CollectionForm(
            initial={'author': author},
            data={
                'name': 'test collection',
                'slug': 'test-collection',
                'listed': False,
                'your_name': "I'm a super dumb bot",
            }
        )

        assert not form.is_valid()
        assert 'spam' in form.errors['__all__'][0]
Esempio n. 5
0
    def test_honeypot_statsd_incr(self, mock_incr):
        author = UserProfile.objects.get(pk=9945)

        form = forms.CollectionForm(
            initial={'author': author},
            data={
                'name': 'test collection',
                'slug': 'test-collection',
                'listed': False,
                'your_name': "I'm a super dumb bot",
            }
        )

        assert not form.is_valid()

        mock_incr.assert_any_call('collections.honeypotted')
Esempio n. 6
0
    def test_clean_description(self):
        # No links, no problems.
        form = forms.CollectionForm()
        form.cleaned_data = {'description': 'some description, no links!'}
        eq_(form.clean_description(), 'some description, no links!')

        # No links allowed: raise on text links.
        form.cleaned_data = {'description': 'http://example.com'}
        with self.assertRaisesRegexp(ValidationError, 'No links are allowed'):
            form.clean_description()

        # No links allowed: raise on URLs.
        form.cleaned_data = {
            'description': '<a href="http://example.com">example.com</a>'}
        with self.assertRaisesRegexp(ValidationError, 'No links are allowed'):
            form.clean_description()
Esempio n. 7
0
 def test_icon(self, update_mock):
     collection = Collection.objects.get(pk=57181)
     # TODO(andym): altering this form is too complicated, can we simplify?
     form = forms.CollectionForm(
                     {'listed': collection.listed,
                      'slug': collection.slug,
                      'name': collection.name},
                     instance=collection,
                     files={'icon': get_uploaded_file('transparent.png')},
                     initial={'author': collection.author,
                              'application_id': collection.application.pk})
     dest = (path.path(settings.COLLECTIONS_ICON_PATH) / 'uploads' /
                       'collection_icons' / '57')
     if not os.path.exists(dest):
         os.makedirs(dest)
     assert form.is_valid()
     form.save()
     assert update_mock.called
Esempio n. 8
0
def test_collections_form_long_description():
    f = forms.CollectionForm(dict(description='&*' * 200))
    assert 'description' in f.errors
Esempio n. 9
0
def test_collections_form_bad_slug():
    f = forms.CollectionForm(dict(slug=' ', listed=True, name='  '))
    assert 'slug' in f.errors
    assert 'name' in f.errors
Esempio n. 10
0
 def test_blacklisted_name_contains(self):
     form = forms.CollectionForm()
     form.cleaned_data = {'name': 'IE6fanBoy'}
     with self.assertRaisesRegexp(ValidationError,
                                  'This name cannot be used.'):
         form.clean_name()