def test_tags_error(self): self.add_restricted('restartless', 'sdk') data = self.data.copy() data.update({'tags': 'restartless'}) form = forms.AddonFormBasic(data=data, request=None, instance=self.addon) eq_(form.errors['tags'][0], '"restartless" is a reserved tag and cannot be used.') data.update({'tags': 'restartless, sdk'}) form = forms.AddonFormBasic(data=data, request=None, instance=self.addon) eq_(form.errors['tags'][0], '"restartless", "sdk" are reserved tags and cannot be used.')
def test_slug_isdigit(self): delicious = Addon.objects.get() form = forms.AddonFormBasic({'slug': '123'}, request=None, instance=delicious) assert not form.is_valid() eq_(form.errors['slug'], [u'The slug cannot be: 123.'])
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.'])
def add_tags(self, tags): data = self.data.copy() data.update({'tags': tags}) form = forms.AddonFormBasic(data=data, request=None, instance=self.addon) assert form.is_valid() form.save(self.addon) return form
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=None, instance=delicious) eq_(f.errors.get('name'), None)
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=None, instance=a) assert not f.is_valid() eq_(f.errors.get('name')[0][1], self.error_msg)
def test_tags_long(self): tag = ' -%s' % ('t' * 128) data = self.data.copy() data.update({"tags": tag}) form = forms.AddonFormBasic(data=data, request=None, instance=self.addon) assert not form.is_valid() eq_(form.errors['tags'], ['All tags must be 128 characters or less' ' after invalid characters are removed.'])
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')
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'])