Exemple #1
0
    def test_banner_regions_initial(self):
        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        eq_(self.webapp.geodata.banner_regions, None)
        eq_(form.initial['banner_regions'], [])

        self.webapp.geodata.update(banner_regions=[])
        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        eq_(form.initial['banner_regions'], [])
Exemple #2
0
    def test_exclude_unrated_games_with_waffle(self):
        """
        Removing a content rating for a game in Brazil should exclude that
        game in Brazil only. Include all ratings bodies in the form choices.
        """
        self.create_switch('iarc')
        self.log_in_with('Apps:Configure')

        rb_br = mkt.regions.BR.ratingsbody
        self.webapp.content_ratings.create(ratings_body=rb_br.id,
                                          rating=rb_br.ratings[0].id)

        rb_de = mkt.regions.DE.ratingsbody
        self.webapp.content_ratings.create(ratings_body=rb_de.id,
                                           rating=rb_de.ratings[0].id)

        games = Category.objects.create(type=amo.ADDON_WEBAPP, slug='games')
        AddonCategory.objects.create(addon=self.webapp, category=games)

        # Remove Brazil but keep Germany.
        de_0_idx = mkt.ratingsbodies.ALL_RATINGS().index(rb_de.ratings[0])
        self.data['app_ratings'] = [de_0_idx]

        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        regions = self.webapp.get_region_ids()
        assert mkt.regions.BR.id not in regions
        assert mkt.regions.DE.id in regions
Exemple #3
0
 def test_banner_regions_disabled(self):
     self.data.update({'banner_regions': [mkt.regions.BR.id]})
     AddonExcludedRegion.objects.create(addon=self.webapp,
                                        region=mkt.regions.BR.id)
     form = forms.AdminSettingsForm(self.data, **self.kwargs)
     assert not form.is_valid(), form.errors
     assert 'banner_regions' in form.errors
Exemple #4
0
    def test_adding_tags(self):
        self.data.update({'tags': 'tag one, tag two'})
        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        eq_(self.webapp.tags.count(), 2)
        self.assertSetEqual(
            self.webapp.tags.values_list('tag_text', flat=True),
            ['tag one', 'tag two'])
Exemple #5
0
    def test_reinclude_rated_games(self):
        """
        Adding a content rating for a game in a region should remove the
        regional exclusion for that region.
        """
        # List it in the Games category.
        cat = Category.objects.create(type=amo.ADDON_WEBAPP, slug='games')
        self.webapp.addoncategory_set.create(category=cat)

        self.log_in_with('Apps:Configure')

        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        excluded_regions = [
            x.id for x in mkt.regions.ALL_REGIONS_WITH_CONTENT_RATINGS
        ]

        # After the form was saved, it should be excluded in Brazil.
        self.assertSetEqual(
            self.webapp.addonexcludedregion.values_list('region', flat=True),
            excluded_regions)

        # Add Brazil content rating.
        rb_br = mkt.regions.BR.ratingsbody
        br_0_idx = mkt.ratingsbodies.ALL_RATINGS().index(rb_br.ratings[0])
        self.data['app_ratings'] = [br_0_idx]

        # Post the form again.
        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        # Notice the Brazilian region exclusion is now gone.
        excluded_regions.remove(mkt.regions.BR.id)
        eq_(len(self.webapp.content_ratings_in(region=mkt.regions.DE)), 0)
        eq_(len(self.webapp.content_ratings_in(region=mkt.regions.BR)), 1)

        self.assertSetEqual(
            self.webapp.addonexcludedregion.values_list('region', flat=True),
            excluded_regions)
Exemple #6
0
    def test_removing_all_tags(self):
        Tag(tag_text='tag one').save_tag(self.webapp)
        eq_(self.webapp.tags.count(), 1)

        self.data.update({'tags': ''})
        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        eq_(self.webapp.tags.count(), 0)
        self.assertSetEqual(
            self.webapp.tags.values_list('tag_text', flat=True), [])
Exemple #7
0
 def test_banner_regions_valid(self):  # Use strings
     self.data.update({
         'banner_regions':
         [unicode(mkt.regions.BR.id), mkt.regions.SPAIN.id]
     })
     self.webapp.geodata.update(banner_regions=[mkt.regions.RS.id])
     form = forms.AdminSettingsForm(self.data, **self.kwargs)
     eq_(form.initial['banner_regions'], [mkt.regions.RS.id])
     assert form.is_valid(), form.errors
     eq_(form.cleaned_data['banner_regions'],
         [mkt.regions.BR.id, mkt.regions.SPAIN.id])
     form.save(self.webapp)
     geodata = self.webapp.geodata.reload()
     eq_(geodata.banner_regions, [mkt.regions.BR.id, mkt.regions.SPAIN.id])
Exemple #8
0
    def test_banner_message(self):
        self.data.update({
            'banner_message_en-us': u'Oh Hai.',
            'banner_message_es': u'¿Dónde está la biblioteca?',
        })
        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        geodata = self.webapp.geodata.reload()
        trans_id = geodata.banner_message_id
        eq_(geodata.banner_message, self.data['banner_message_en-us'])
        eq_(unicode(Translation.objects.get(id=trans_id, locale='es')),
            self.data['banner_message_es'])
        eq_(unicode(Translation.objects.get(id=trans_id, locale='en-us')),
            self.data['banner_message_en-us'])
Exemple #9
0
    def test_exclude_brazil_games_when_removing_content_rating(self):
        """
        Removing a content rating for a game in Brazil should exclude that
        game in Brazil.
        """

        self.log_in_with('Apps:Configure')
        rb = mkt.regions.BR.ratingsbodies[0]
        ContentRating.objects.create(addon=self.webapp,
                                     ratings_body=rb.id,
                                     rating=rb.ratings[0].id)

        games = Category.objects.create(type=amo.ADDON_WEBAPP, slug='games')
        AddonCategory.objects.create(addon=self.webapp, category=games)

        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        regions = self.webapp.get_region_ids()
        assert regions
        assert mkt.regions.BR.id not in regions
Exemple #10
0
    def test_update_content_rating(self):
        """
        Test changing the content rating of a rating body to a different
        rating.
        """
        self.create_switch('iarc')
        self.log_in_with('Apps:Configure')

        self.webapp.set_content_ratings(
            {mkt.ratingsbodies.CLASSIND: mkt.ratingsbodies.CLASSIND_L})

        # Change CLASSIND rating from L to 18.
        classind_18_idx = mkt.ratingsbodies.ALL_RATINGS().index(
            mkt.ratingsbodies.CLASSIND_18)
        self.data['app_ratings'] = [classind_18_idx]

        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        eq_(
            self.webapp.content_ratings.get(
                ratings_body=mkt.ratingsbodies.CLASSIND.id).rating,
            mkt.ratingsbodies.CLASSIND_18.id)
Exemple #11
0
 def test_reindexed(self, index_webapps_mock):
     form = forms.AdminSettingsForm(self.data, **self.kwargs)
     assert form.is_valid(), form.errors
     form.save(self.webapp)
     index_webapps_mock.assert_called_with([self.webapp.id])
Exemple #12
0
 def test_banner_regions_garbage(self):
     self.data.update({'banner_regions': ['LOL']})
     form = forms.AdminSettingsForm(self.data, **self.kwargs)
     assert not form.is_valid(), form.errors