def test_categories_error(self): data = self.data.copy() categories = ['news', 'music', 'games'] data.update({ 'categories': categories, }) form = WebsiteForm(request=self.request, instance=self.website, data=data) assert not form.is_valid() eq_(form.errors['categories'][0], u'You can have only 2 categories.')
def test_regions(self): data = self.data.copy() regions = ['1', '2', '8'] data.update({ 'preferred_regions': regions, }) form = WebsiteForm(request=self.request, instance=self.website, data=data) assert form.is_valid(), form.errors form.save() self.website.reload() self.assertSetEqual(self.website.preferred_regions, map(int, regions))
def test_devices(self): data = self.data.copy() devices = [str(DEVICE_DESKTOP.id), str(DEVICE_GAIA.id)] data.update({ 'devices': devices, }) form = WebsiteForm(request=self.request, instance=self.website, data=data) assert form.is_valid(), form.errors form.save() self.website.reload() self.assertSetEqual(self.website.devices, map(int, devices))
def test_categories(self): data = self.data.copy() categories = ['news', 'music'] data.update({ 'categories': categories, }) form = WebsiteForm(request=self.request, instance=self.website, data=data) assert form.is_valid(), form.errors form.save() self.website.reload() self.assertSetEqual(self.website.categories, categories)
def test_basic(self): data = self.data.copy() data.update({ 'title_en-us': u'Tëst', 'url': u'http://test.com/', }) form = WebsiteForm(request=self.request, instance=self.website, data=data) assert form.is_valid(), form.errors form.save() self.website.reload() eq_(unicode(self.website.title), u'Tëst') eq_(self.website.url, u'http://test.com/')
def website_edit(request, addon_id): website = get_object_or_404(Website, pk=addon_id) form = WebsiteForm(request.POST or None, request=request, instance=website) if request.method == 'POST' and form.is_valid(): form.save() messages.success(request, _('Website saved.')) return redirect(reverse('lookup.website_summary', args=[website.pk])) return render(request, 'lookup/website_edit.html', { 'website': website, 'form': form, })
def test_keywords(self): data = self.data.copy() data.update({ 'keywords': 'thing one, thing two', }) form = WebsiteForm(request=self.request, instance=self.website, data=data) assert form.is_valid(), form.errors form.save() self.website.reload() self.assertSetEqual( self.website.keywords.values_list('tag_text', flat=True), ['thing one', 'thing two'])
def test_keywords(self): data = self.data.copy() data.update({ 'keywords': 'thing one, thing two', }) form = WebsiteForm(request=self.request, instance=self.website, data=data) assert form.is_valid(), form.errors form.save() self.website.reload() self.assertSetEqual( self.website.keywords.values_list('tag_text', flat=True), ['thing one', 'thing two'] )
def website_edit(request, addon_id): website = get_object_or_404(Website, pk=addon_id) form = WebsiteForm(request.POST or None, request=request, instance=website) if request.method == 'POST' and form.is_valid(): form.save() messages.success(request, _('Website saved.')) return redirect( reverse('lookup.website_summary', args=[website.pk])) return render(request, 'lookup/website_edit.html', { 'website': website, 'form': form, })
def test_l10n(self): data = self.data.copy() data.update({ 'name_es': 'Spanish name', 'title_es': 'Spanish title', 'description_es': 'Spanish description', }) form = WebsiteForm(request=self.request, instance=self.website, data=data) assert form.is_valid(), form.errors form.save() with self.activate('es'): self.website.reload() eq_(unicode(self.website.name), 'Spanish name') eq_(unicode(self.website.title), 'Spanish title') eq_(unicode(self.website.description), 'Spanish description')