Example #1
0
 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.')
Example #2
0
 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.')
Example #3
0
 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))
Example #4
0
 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))
Example #5
0
 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)
Example #6
0
 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))
Example #7
0
 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)
Example #8
0
 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))
Example #9
0
 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/')
Example #10
0
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,
    })
Example #11
0
 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'])
Example #12
0
 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/')
Example #13
0
 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']
     )
Example #14
0
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,
    })
Example #15
0
 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')
Example #16
0
 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')