예제 #1
0
    def test_extract_featured_for(self):
        collection = collection_factory()
        featured_collection = FeaturedCollection.objects.create(
            collection=collection, application=amo.FIREFOX.id)
        collection.add_addon(self.addon)
        extracted = self._extract()
        assert extracted['featured_for'] == [
            {'application': [amo.FIREFOX.id], 'locales': [None]}]

        # Even if the locale for the FeaturedCollection is an empty string
        # instead of None, we extract it as None so that it keeps its special
        # meaning.
        featured_collection.update(locale='')
        extracted = self._extract()
        assert extracted['featured_for'] == [
            {'application': [amo.FIREFOX.id], 'locales': [None]}]

        collection = collection_factory()
        FeaturedCollection.objects.create(collection=collection,
                                          application=amo.FIREFOX.id,
                                          locale='fr')
        collection.add_addon(self.addon)
        extracted = self._extract()
        assert extracted['featured_for'] == [
            {'application': [amo.FIREFOX.id], 'locales': [None, 'fr']}]

        collection = collection_factory()
        FeaturedCollection.objects.create(collection=collection,
                                          application=amo.ANDROID.id,
                                          locale='de-DE')
        collection.add_addon(self.addon)
        extracted = self._extract()
        assert extracted['featured_for'] == [
            {'application': [amo.FIREFOX.id], 'locales': [None, 'fr']},
            {'application': [amo.ANDROID.id], 'locales': ['de-DE']}]
예제 #2
0
    def test_extract_featured_for(self):
        collection = collection_factory()
        FeaturedCollection.objects.create(collection=collection,
                                          application=amo.FIREFOX.id)
        collection.add_addon(self.addon)
        extracted = self._extract()
        assert extracted['featured_for'] == [
            {'application': [amo.FIREFOX.id], 'locales': [None]}]

        collection = collection_factory()
        FeaturedCollection.objects.create(collection=collection,
                                          application=amo.FIREFOX.id,
                                          locale='fr')
        collection.add_addon(self.addon)
        extracted = self._extract()
        assert extracted['featured_for'] == [
            {'application': [amo.FIREFOX.id], 'locales': [None, 'fr']}]

        collection = collection_factory()
        FeaturedCollection.objects.create(collection=collection,
                                          application=amo.ANDROID.id,
                                          locale='de-DE')
        collection.add_addon(self.addon)
        extracted = self._extract()
        assert extracted['featured_for'] == [
            {'application': [amo.FIREFOX.id], 'locales': [None, 'fr']},
            {'application': [amo.ANDROID.id], 'locales': ['de-DE']}]
예제 #3
0
 def test_valid_collection(self):
     bagpuss = user_factory(username='******')
     collection_factory(slug='stuff', author=bagpuss)
     form = ReplacementAddonAdmin(ReplacementAddon, None).get_form(None)(
         {'guid': 'foo', 'path': '/collections/bagpuss/stuff/'})
     assert form.is_valid(), form.errors
     assert form.cleaned_data['path'] == '/collections/bagpuss/stuff/'
예제 #4
0
 def test_slug_unique(self):
     collection_factory(author=self.user, slug='edam')
     self.client.login_api(self.user)
     data = dict(self.data)
     data.update(slug=u'edam')
     response = self.send(data=data)
     assert response.status_code == 400
     assert u'This custom URL is already in use' in (
         ','.join(json.loads(response.content)['non_field_errors']))
예제 #5
0
    def test_different_user(self):
        random_user = user_factory()
        other_url = reverse_ns('collection-list',
                               kwargs={'user_pk': random_user.pk})
        collection_factory(author=random_user)

        self.client.login_api(self.user)
        response = self.client.get(other_url)
        assert response.status_code == 403
예제 #6
0
    def test_sort(self):
        col_a = collection_factory(author=self.user)
        col_b = collection_factory(author=self.user)
        col_c = collection_factory(author=self.user)
        col_a.update(modified=self.days_ago(3))
        col_b.update(modified=self.days_ago(1))
        col_c.update(modified=self.days_ago(6))

        self.client.login_api(self.user)
        response = self.client.get(self.url)
        assert response.status_code == 200
        # should be b a c because 1, 3, 6 days ago.
        assert response.data['results'][0]['uuid'] == col_b.uuid.hex
        assert response.data['results'][1]['uuid'] == col_a.uuid.hex
        assert response.data['results'][2]['uuid'] == col_c.uuid.hex
예제 #7
0
파일: test_tasks.py 프로젝트: diox/olympia
    def test_add_static_theme_from_lwt(self):
        author = user_factory()
        persona = addon_factory(
            type=amo.ADDON_PERSONA, users=[author], name='Firefox Theme')
        persona.update(
            created=self.create_date, modified=self.modify_date,
            last_updated=self.update_date)
        persona.persona.license = licenses.LICENSE_CC_BY_ND.id
        Tag.objects.create(tag_text='themey').save_tag(persona)
        License.objects.create(builtin=licenses.LICENSE_CC_BY_ND.builtin)
        rating_user = user_factory()
        rating = Rating.objects.create(
            addon=persona, version=persona.current_version, user=rating_user,
            rating=2, body=u'fooooo', user_responsible=rating_user)
        ThemeUpdateCount.objects.create(
            addon_id=persona.id, date=datetime(2018, 1, 1), count=123)
        ThemeUpdateCount.objects.create(
            addon_id=persona.id, date=datetime(2018, 2, 1), count=456)
        # Create a count for an addon that shouldn't be migrated too.
        ThemeUpdateCount.objects.create(
            addon_id=addon_factory().id, date=datetime(2018, 2, 1), count=45)
        # And add it to a collection
        collection = collection_factory()
        collection.add_addon(persona)
        collection.add_addon(addon_factory())

        static_theme = add_static_theme_from_lwt(persona)

        self._check_result(
            static_theme, [author], list(persona.tags.all()),
            persona.all_categories, licenses.LICENSE_CC_BY_ND.builtin,
            [rating], collection)
예제 #8
0
    def test_invalid_collections(self):
        """Broken paths, invalid users or collections, should fail gracefully
        to None."""
        rep = ReplacementAddon.objects.create(
            guid=u'legacy@mozilla', path=u'/collections/me/bag/')
        result = self.serialize(rep)
        assert result['guid'] == u'legacy@mozilla'
        assert result['replacement'] == []

        # Create the user but not the collection.
        me = user_factory(username=u'me')
        result = self.serialize(rep)
        assert result['guid'] == u'legacy@mozilla'
        assert result['replacement'] == []

        # Create the collection but make the add-on invalid.
        addon = addon_factory(slug=u'stuff', guid=u'newstuff@mozilla',
                              status=amo.STATUS_NULL)
        collection = collection_factory(slug=u'bag', author=me)
        collection.add_addon(addon)
        result = self.serialize(rep)
        assert result['guid'] == u'legacy@mozilla'
        assert result['replacement'] == []

        # Double check that the test is good and it will work once public.
        addon.update(status=amo.STATUS_PUBLIC)
        result = self.serialize(rep)
        assert result['replacement'] == [u'newstuff@mozilla']
 def setUp(self):
     self.collection = collection_factory()
     self.addon = addon_factory()
     self.collection.add_addon(self.addon)
     self.item = CollectionAddon.objects.get(addon=self.addon,
                                             collection=self.collection)
     self.item.comments = u'Dis is nice'
     self.item.save()
예제 #10
0
 def test_extract_is_featured(self):
     collection = collection_factory()
     FeaturedCollection.objects.create(collection=collection,
                                       application=collection.application)
     collection.add_addon(self.addon)
     assert self.addon.is_featured()
     extracted = self._extract()
     assert extracted['is_featured'] is True
예제 #11
0
 def test_signal_only_with_featured(self):
     with mock.patch(self.MOCK_TARGET) as function_mock:
         addon = addon_factory()
         collection = collection_factory()
         collection.add_addon(addon)
         collection.remove_addon(addon)
         collection.delete()
         function_mock.assert_not_called()
예제 #12
0
 def setUp(self):
     self.user = user_factory()
     self.collection = collection_factory(author=self.user)
     self.url = reverse_ns(
         'collection-addon-list', api_version='v4dev', kwargs={
             'user_pk': self.user.pk,
             'collection_slug': self.collection.slug})
     self.addon = addon_factory()
     super(TestCollectionAddonViewSetCreate, self).setUp()
예제 #13
0
    def test_basic(self):
        collection_factory(author=self.user)
        collection_factory(author=self.user)
        collection_factory(author=self.user)
        collection_factory(author=user_factory())  # Not our collection.
        Collection.objects.all().count() == 4

        self.client.login_api(self.user)
        response = self.client.get(self.url)
        assert response.status_code == 200
        assert len(response.data['results']) == 3
예제 #14
0
    def test_can_delete_with_related_objects_with_admin_advanced_permission(
            self):
        # Add related instances...
        addon = addon_factory()
        addon_with_other_authors = addon_factory()
        AddonUser.objects.create(
            addon=addon_with_other_authors, user=user_factory())
        relations_that_should_be_deleted = [
            AddonUser.objects.create(
                addon=addon_with_other_authors, user=self.user),
            Rating.objects.create(
                addon=addon_factory(), rating=5, user=self.user),
            addon,  # Has no other author, should be deleted.
            collection_factory(author=self.user)
        ]
        relations_that_should_survive = [
            AbuseReport.objects.create(reporter=self.user),
            AbuseReport.objects.create(user=self.user),
            ActivityLog.create(user=self.user, action=amo.LOG.USER_EDITED),
            ReviewerScore.objects.create(user=self.user, score=42),
            addon_with_other_authors,  # Has other authors, should be kept.

            # Bit of a weird case, but because the user was the only author of
            # this add-on, the addonuser relation is kept, and both the add-on
            # and the user are soft-deleted. This is in contrast with the case
            # where the user is *not* the only author, in which case the
            # addonuser relation is deleted, but the add-on is left intact.
            AddonUser.objects.create(addon=addon, user=self.user),
        ]

        # Now test as normal.
        user = user_factory()
        assert not self.user.deleted
        self.grant_permission(user, 'Admin:Tools')
        self.grant_permission(user, 'Admin:Advanced')
        self.client.login(email=user.email)
        core.set_user(user)
        response = self.client.get(self.delete_url, follow=True)
        assert response.status_code == 200
        assert b'Cannot delete user' not in response.content
        response = self.client.post(self.delete_url, {'post': 'yes'},
                                    follow=True)
        assert response.status_code == 200
        self.user.reload()
        assert self.user.deleted
        assert self.user.email is None
        alog = ActivityLog.objects.filter(
            action=amo.LOG.ADMIN_USER_ANONYMIZED.id).get()
        assert alog.arguments == [self.user]

        # Test the related instances we created earlier.
        for obj in relations_that_should_be_deleted:
            assert not obj.__class__.objects.filter(pk=obj.pk).exists()

        for obj in relations_that_should_survive:
            assert obj.__class__.objects.filter(pk=obj.pk).exists()
예제 #15
0
    def test_admin(self):
        random_user = user_factory()
        other_url = reverse_ns('collection-list',
                               kwargs={'user_pk': random_user.pk})
        collection_factory(author=random_user)

        self.grant_permission(self.user, 'Collections:Edit')
        self.client.login_api(self.user)
        response = self.client.get(other_url)
        assert response.status_code == 403

        self.grant_permission(self.user, 'Collections:Contribute')
        self.client.login_api(self.user)
        response = self.client.get(other_url)
        assert response.status_code == 403

        self.grant_permission(self.user, 'Admin:Curation')
        response = self.client.get(other_url)
        assert response.status_code == 403
예제 #16
0
    def test_is_featured(self):
        self.addon = addon_factory()
        collection = collection_factory()
        FeaturedCollection.objects.create(collection=collection,
                                          application=collection.application)
        collection.add_addon(self.addon)
        assert self.addon.is_featured()

        result = self.serialize()
        assert result['is_featured'] is True
예제 #17
0
    def setUp(self):
        super(TestPromos, self).setUp()
        # Create a few add-ons...
        self.addon1 = addon_factory()
        self.addon2 = addon_factory()
        self.addon3 = addon_factory()
        # Create a user for the collection.
        user = UserProfile.objects.create(username='******')
        games_collection = collection_factory(author=user, slug='games')
        games_collection.set_addons(
            [self.addon1.pk, self.addon2.pk, self.addon3.pk])
        DiscoveryModule.objects.create(
            app=amo.FIREFOX.id, ordering=1, module='Games!')

        musthave_collection = collection_factory(
            author=user, slug='must-have-media')
        musthave_collection.set_addons(
            [self.addon1.pk, self.addon2.pk, self.addon3.pk])
        DiscoveryModule.objects.create(
            app=amo.FIREFOX.id, ordering=2, module='Must-Have Media')
예제 #18
0
 def setUp(self):
     self.user = user_factory()
     self.collection = collection_factory(author=self.user)
     self.addon = addon_factory()
     self.collection.add_addon(self.addon)
     self.url = reverse_ns(
         'collection-addon-detail', kwargs={
             'user_pk': self.user.pk,
             'collection_slug': self.collection.slug,
             'addon': self.addon.id})
     super(TestCollectionAddonViewSetDetail, self).setUp()
예제 #19
0
    def test_by_category_app(self):
        # Add an addon to the same category, but in a featured collection
        # for a different app: it should not be returned.
        extra_addon = addon_factory()
        extra_addon.addoncategory_set.create(category_id=self.category)
        collection = collection_factory()
        collection.add_addon(extra_addon)
        FeaturedCollection.objects.create(
            application=amo.THUNDERBIRD.id, collection=collection)

        assert set(get_creatured_ids(self.category, None)) == (
            set(self.no_locale))
예제 #20
0
 def test_no_id_lookup(self):
     collection = collection_factory(author=self.user, slug='999')
     id_url = reverse_ns(
         'collection-detail', kwargs={
             'user_pk': self.user.pk, 'slug': collection.id})
     response = self.client.get(id_url)
     assert response.status_code == 404
     slug_url = reverse_ns(
         'collection-detail', kwargs={
             'user_pk': self.user.pk, 'slug': collection.slug})
     response = self.client.get(slug_url)
     assert response.status_code == 200
     assert response.data['id'] == collection.id
예제 #21
0
    def test_by_category_app_and_locale(self):
        # Add an addon to the same category and locale, but in a featured
        # collection for a different app: it should not be returned.
        extra_addon = addon_factory(
            category=Category.objects.get(pk=self.category_id))
        collection = collection_factory()
        collection.add_addon(extra_addon)
        FeaturedCollection.objects.create(
            application=amo.ANDROID.id, collection=collection,
            locale='en-US')

        assert set(get_creatured_ids(self.category_id, 'en-US')) == (
            set(self.no_locale + self.en_us_locale))
예제 #22
0
 def setUp(self):
     self.validator = CollectionAkismetSpamValidator(
         ('name', 'description'))
     serializer = mock.Mock()
     serializer.instance = collection_factory(
         name='name', description='Big Cheese')
     request = mock.Mock()
     request.user = user_factory()
     request.META = {}
     serializer.context = {'request': request}
     self.validator.set_context(serializer)
     self.data = {
         'name': {'en-US': 'Collection', 'fr': u'Collection'},
         'description': {'en-US': 'Big Cheese', 'fr': u'une gránd fromagé'},
         'random_data': {'en-US': 'to ignore'},
         'slug': 'cheese'}
예제 #23
0
    def test_valid_collection_path(self):
        addon = addon_factory(slug=u'stuff', guid=u'newstuff@mozilla')
        me = user_factory(username=u'me')
        collection = collection_factory(slug=u'bag', author=me)
        collection.add_addon(addon)

        rep = ReplacementAddon.objects.create(
            guid=u'legacy@mozilla', path=u'/collections/me/bag/')
        result = self.serialize(rep)
        assert result['guid'] == u'legacy@mozilla'
        assert result['replacement'] == [u'newstuff@mozilla']

        # Edge case, but should accept numeric user IDs too
        rep.update(path=u'/collections/%s/bag/' % me.id)
        result = self.serialize(rep)
        assert result['guid'] == u'legacy@mozilla'
        assert result['replacement'] == [u'newstuff@mozilla']
예제 #24
0
    def setUp(self):
        self.user = user_factory()
        self.collection = collection_factory(author=self.user)
        self.addon_a = addon_factory(name=u'anteater')
        self.addon_b = addon_factory(name=u'baboon')
        self.addon_c = addon_factory(name=u'cheetah')
        self.addon_disabled = addon_factory(name=u'antelope_disabled')
        self.addon_deleted = addon_factory(name=u'buffalo_deleted')
        self.addon_pending = addon_factory(name=u'pelican_pending')

        # Set a few more languages on our add-ons to test sorting
        # a bit better. https://github.com/mozilla/addons-server/issues/8354
        self.addon_a.name = {'de': u'Ameisenbär'}
        self.addon_a.save()

        self.addon_b.name = {'de': u'Pavian'}
        self.addon_b.save()

        self.addon_c.name = {'de': u'Gepard'}
        self.addon_c.save()

        self.collection.add_addon(self.addon_a)
        self.collection.add_addon(self.addon_disabled)
        self.collection.add_addon(self.addon_b)
        self.collection.add_addon(self.addon_deleted)
        self.collection.add_addon(self.addon_c)
        self.collection.add_addon(self.addon_pending)

        # Set up our filtered-out-by-default addons
        self.addon_disabled.update(disabled_by_user=True)
        self.addon_deleted.delete()
        self.addon_pending.current_version.all_files[0].update(
            status=amo.STATUS_AWAITING_REVIEW)

        self.url = reverse_ns(
            'collection-addon-list', kwargs={
                'user_pk': self.user.pk,
                'collection_slug': self.collection.slug})
        super(TestCollectionAddonViewSetList, self).setUp()
예제 #25
0
    def test_not_listed_admin(self):
        random_user = user_factory()
        collection = collection_factory(author=random_user, listed=False)

        self.grant_permission(self.user, 'Collections:Edit')
        self.client.login_api(self.user)
        response = self.client.get(self._get_url(random_user, collection))
        assert response.status_code == 403

        self.grant_permission(self.user, 'Collections:Contribute')
        self.client.login_api(self.user)
        response = self.client.get(self._get_url(random_user, collection))
        assert response.status_code == 403

        self.grant_permission(self.user, 'Admin:Curation')
        response = self.client.get(self._get_url(random_user, collection))
        assert response.status_code == 403

        with override_settings(TASK_USER_ID=random_user.id):
            response = self.client.get(self._get_url(random_user, collection))
        assert response.status_code == 200
        assert response.data['id'] == collection.pk
예제 #26
0
 def setUp(self):
     super(TestCollectionSerializer, self).setUp()
     self.user = user_factory()
     self.collection = collection_factory()
     self.collection.update(author=self.user)
예제 #27
0
 def setUp(self):
     self.user = user_factory()
     self.collection = collection_factory(author=self.user)
     self.url = self.get_url(self.user)
     super(TestCollectionViewSetDelete, self).setUp()
예제 #28
0
 def setUp(self):
     super(TestFeaturedCollectionSignals, self).setUp()
     self.collection = collection_factory()
     self.addon = addon_factory()
     self.collection.add_addon(self.addon)
예제 #29
0
 def test_no_auth(self):
     collection_factory(author=self.user)
     response = self.client.get(self.url)
     assert response.status_code == 401
예제 #30
0
 def setUp(self):
     super(TestFeaturedCollectionSignals, self).setUp()
     self.collection = collection_factory()
     self.addon = addon_factory()
     self.collection.add_addon(self.addon)
예제 #31
0
    def setUpTestData(cls):
        super().setUpTestData()

        # Shouldn't be necessary, but just in case.
        cls.empty_index('default')

        addon_factory(
            name='test addon test01',
            type=amo.ADDON_EXTENSION,
            average_daily_users=46812,
            weekly_downloads=132,
            summary=None,
            tags=('foo', ),
        )
        addon_factory(
            name='test addon test02',
            type=amo.ADDON_STATICTHEME,
            average_daily_users=18981,
            weekly_downloads=145,
            summary=None,
            tags=('baa', ),
        )
        addon_factory(
            name='test addon test03',
            type=amo.ADDON_EXTENSION,
            average_daily_users=482,
            weekly_downloads=506,
            summary=None,
            promoted=RECOMMENDED,
            tags=('baa', ),
        )
        addon_factory(
            name='test addon test04',
            type=amo.ADDON_STATICTHEME,
            average_daily_users=8838,
            weekly_downloads=358,
            summary=None,
            promoted=RECOMMENDED,
            tags=('foo', ),
        )

        cls.mozilla_user = UserProfile.objects.create(pk=settings.TASK_USER_ID)
        collection = collection_factory(author=cls.mozilla_user,
                                        slug='privacy-matters')
        addon = addon_factory(name='test addon privacy01')
        CollectionAddon.objects.create(addon=addon, collection=collection)

        # add some extra extensions to test count limits
        addon_factory(
            name='test extra extension 1',
            type=amo.ADDON_EXTENSION,
            average_daily_users=4,
            weekly_downloads=1,
        )
        addon_factory(
            name='test extra extension 2',
            type=amo.ADDON_EXTENSION,
            average_daily_users=4,
            weekly_downloads=1,
        )
        addon_factory(
            name='test extra theme 1',
            type=amo.ADDON_STATICTHEME,
            average_daily_users=4,
            weekly_downloads=1,
        )
        addon_factory(
            name='test extra theme 2',
            type=amo.ADDON_STATICTHEME,
            average_daily_users=4,
            weekly_downloads=1,
        )

        cls.refresh()
예제 #32
0
 def test_with_addons_is_ignored(self):
     collection_factory(author=self.user)
     self.client.login_api(self.user)
     response = self.client.get(self.url + '?with_addons')
     assert response.status_code == 200, response.data
     assert 'addons' not in response.data['results'][0]
예제 #33
0
 def setUp(self):
     self.collection = collection_factory(author=self.user)
     super(TestCollectionViewSetPatch, self).setUp()
예제 #34
0
 def setUp(self):
     self.user = user_factory()
     self.collection = collection_factory(author=self.user)
     self.url = self.get_url(self.user)
     super(TestCollectionViewSetDelete, self).setUp()
예제 #35
0
 def setUp(self):
     self.user = user_factory()
     self.collection = collection_factory()
     self.collection.update(author=self.user)
 def setUp(self):
     super(TestCollectionSerializer, self).setUp()
     self.user = user_factory()
     self.collection = collection_factory()
     self.collection.update(author=self.user)
예제 #37
0
 def setUp(self):
     self.collection = collection_factory(author=self.user)
     super(TestCollectionViewSetPatch, self).setUp()
예제 #38
0
 def test_no_auth(self):
     collection_factory(author=self.user)
     response = self.client.get(self.url)
     assert response.status_code == 401
예제 #39
0
 def test_valid_collection(self):
     bagpuss = user_factory(username='******')
     collection_factory(slug='stuff', author=bagpuss)
     form = ReplacementAddonAdmin(ReplacementAddon, None).get_form(None)(
         {'guid': 'foo', 'path': '/collections/bagpuss/stuff/'})
     assert form.is_valid(), form.errors