Beispiel #1
0
 def test_tags_error(self):
     self.add_restricted('i_am_a_restricted_tag', 'sdk')
     data = self.data.copy()
     data.update({'tags': 'i_am_a_restricted_tag'})
     form = forms.AddonFormBasic(data=data,
                                 request=self.request,
                                 instance=self.addon)
     assert form.errors['tags'][0] == (
         '"i_am_a_restricted_tag" is a reserved tag and cannot be used.')
     data.update({'tags': 'i_am_a_restricted_tag, sdk'})
     form = forms.AddonFormBasic(data=data,
                                 request=self.request,
                                 instance=self.addon)
     assert form.errors['tags'][0] == (
         '"i_am_a_restricted_tag", "sdk" are reserved tags and'
         ' cannot be used.')
Beispiel #2
0
    def test_name_no_trademark(self):
        delicious = Addon.objects.get()
        form = forms.AddonFormBasic(
            {'name': 'Delicious Dumdidum', 'summary': 'foo', 'slug': 'bar'},
            request=self.request,
            instance=delicious)

        assert form.is_valid()
Beispiel #3
0
 def add_tags(self, tags):
     data = self.data.copy()
     data.update({'tags': tags})
     form = forms.AddonFormBasic(data=data, request=self.request,
                                 instance=self.addon)
     assert form.is_valid()
     form.save(self.addon)
     return form
Beispiel #4
0
 def test_slug_blacklist(self):
     delicious = Addon.objects.get()
     form = forms.AddonFormBasic({'slug': 'submit'},
                                 request=None,
                                 instance=delicious)
     assert not form.is_valid()
     eq_(form.errors['slug'],
         [u'The slug cannot be "submit". Please choose another.'])
Beispiel #5
0
 def test_update_addon_non_existing_name(self):
     """An add-on edit can change the name to any non-existing name."""
     addon = addon_factory(name='some name')
     form = forms.AddonFormBasic(dict(name=self.non_existing_name),
                                 request=self.request,
                                 instance=addon)
     form.is_valid()
     assert 'name' not in form.errors
Beispiel #6
0
 def test_update_addon_existing_name(self):
     """An add-on edit can't change the name to an existing add-on name."""
     addon = addon_factory(name='some name')
     form = forms.AddonFormBasic(dict(name=self.existing_name),
                                 request=self.request,
                                 instance=addon)
     assert not form.is_valid()
     assert form.errors['name'][0][1] == self.error_msg
Beispiel #7
0
    def test_name_trademark_allowed_for_prefix(self):
        delicious = Addon.objects.get()
        form = forms.AddonFormBasic(
            {'name': 'Delicious for Mozilla', 'summary': 'foo', 'slug': 'bar'},
            request=self.request,
            instance=delicious)

        assert form.is_valid()
Beispiel #8
0
 def test_update_addon_existing_name_used_by_other_type(self):
     """An add-on edit can change the name to an existing name used by
     another add-on type."""
     addon = addon_factory(name='some name', type=amo.ADDON_PERSONA)
     form = forms.AddonFormBasic(dict(name=self.existing_name),
                                 request=self.request,
                                 instance=addon)
     form.is_valid()
     assert 'name' not in form.errors
Beispiel #9
0
 def test_update_addon_existing_name_used_by_listed(self):
     """An unlisted add-on edit can change the name to an existing name used
     by an listed add-on."""
     addon = addon_factory(name='some name', is_listed=False)
     form = forms.AddonFormBasic(dict(name=self.existing_name),
                                 request=self.request,
                                 instance=addon)
     form.is_valid()
     assert 'name' not in form.errors
Beispiel #10
0
 def test_name_trademark_firefox(self):
     delicious = Addon.objects.get()
     form = forms.AddonFormBasic(
         {'name': 'Delicious Firefox', 'summary': 'foo', 'slug': 'bar'},
         request=self.request,
         instance=delicious)
     assert not form.is_valid()
     assert dict(form.errors['name'])['en-us'].startswith(
         u'Add-on names cannot contain the Mozilla or Firefox trademarks.')
Beispiel #11
0
 def test_slug_isdigit(self):
     delicious = Addon.objects.get()
     form = forms.AddonFormBasic({'slug': '123'},
                                 request=self.request,
                                 instance=delicious)
     assert not form.is_valid()
     assert form.errors['slug'] == ([
         u'The slug cannot be "123". Please choose another.'
     ])
Beispiel #12
0
 def test_old_same(self):
     """
     Exiting add-ons should be able to re-use their name.
     """
     delicious = Addon.objects.get()
     f = forms.AddonFormBasic(dict(name=self.existing_name),
                              request=self.request,
                              instance=delicious)
     f.is_valid()
     assert f.errors.get('name') is None
Beispiel #13
0
 def test_old(self):
     """
     Exiting add-ons shouldn't be able to use someone else's name.
     """
     a = Addon.objects.create(type=1)
     f = forms.AddonFormBasic(dict(name=self.existing_name),
                              request=self.request,
                              instance=a)
     assert not f.is_valid()
     assert f.errors.get('name')[0][1] == self.error_msg
Beispiel #14
0
    def test_tags_restricted(self):
        self.add_restricted()
        self.add_tags('foo, bar')
        form = forms.AddonFormBasic(data=self.data, request=self.request,
                                    instance=self.addon)

        assert form.fields['tags'].initial == 'bar, foo'
        assert self.get_tag_text() == ['bar', 'foo', 'i_am_a_restricted_tag']
        self.add_tags('')
        assert self.get_tag_text() == ['i_am_a_restricted_tag']
Beispiel #15
0
 def test_update_addon_existing_name_used_by_unlisted(self):
     """An add-on edit can change the name to an existing name used by an
     unlisted add-on."""
     Addon.objects.get(pk=3615).update(is_listed=False)
     addon = addon_factory(name='some name')
     form = forms.AddonFormBasic(dict(name=self.existing_name),
                                 request=None,
                                 instance=addon)
     form.is_valid()
     assert 'name' not in form.errors
Beispiel #16
0
 def test_tags_long(self):
     tag = ' -%s' % ('t' * 128)
     data = self.data.copy()
     data.update({"tags": tag})
     form = forms.AddonFormBasic(data=data, request=self.request,
                                 instance=self.addon)
     assert not form.is_valid()
     assert form.errors['tags'] == [
         'All tags must be 128 characters or less after invalid characters'
         ' are removed.']
Beispiel #17
0
    def test_tags_restricted(self):
        self.add_restricted()
        self.add_tags('foo, bar')
        form = forms.AddonFormBasic(data=self.data,
                                    request=None,
                                    instance=self.addon)

        eq_(form.fields['tags'].initial, 'bar, foo')
        eq_(self.get_tag_text(), ['bar', 'foo', 'restartless'])
        self.add_tags('')
        eq_(self.get_tag_text(), ['restartless'])
Beispiel #18
0
 def test_tags_admin_restricted(self, action_allowed):
     action_allowed.return_value = True
     self.add_restricted('restartless')
     self.add_tags('foo, bar')
     eq_(self.get_tag_text(), ['bar', 'foo'])
     self.add_tags('foo, bar, restartless')
     eq_(self.get_tag_text(), ['bar', 'foo', 'restartless'])
     form = forms.AddonFormBasic(data=self.data,
                                 request=None,
                                 instance=self.addon)
     eq_(form.fields['tags'].initial, 'bar, foo, restartless')
Beispiel #19
0
    def test_tags_admin_restricted(self, action_allowed):
        action_allowed.return_value = True
        self.add_restricted('i_am_a_restricted_tag')
        self.add_tags('foo, bar')
        assert self.get_tag_text() == ['bar', 'foo']
        self.add_tags('foo, bar, i_am_a_restricted_tag')

        assert self.get_tag_text() == ['bar', 'foo', 'i_am_a_restricted_tag']
        form = forms.AddonFormBasic(data=self.data, request=self.request,
                                    instance=self.addon)
        assert form.fields['tags'].initial == 'bar, foo, i_am_a_restricted_tag'