Ejemplo n.º 1
0
    def test_impala_reviews_link(self):
        a = Addon(average_rating=4, total_reviews=37, id=1, type=1, slug='xx')
        s = self.render('{{ impala_reviews_link(myaddon) }}', {'myaddon': a})
        eq_(pq(s)('a').text(), '(37)')

        # without collection uuid
        eq_(pq(s)('a').attr('href'), '/en-US/firefox/addon/xx/#reviews')

        # with collection uuid
        myuuid = 'f19a8822-1ee3-4145-9440-0a3640201fe6'
        s = self.render('{{ impala_reviews_link(myaddon, myuuid) }}', {
            'myaddon': a,
            'myuuid': myuuid
        })
        eq_(
            pq(s)('a').attr('href'),
            '/en-US/firefox/addon/xx/?collection_uuid=%s#reviews' % myuuid)

        z = Addon(average_rating=0, total_reviews=0, id=1, type=1, slug='xx')
        s = self.render('{{ impala_reviews_link(myaddon) }}', {'myaddon': z})
        eq_(pq(s)('b').text(), 'Not yet rated')

        # with link
        u = reverse('addons.reviews.list', args=['xx'])
        s = self.render(
            '{{ impala_reviews_link(myaddon, link_to_list=True) }}',
            {'myaddon': a})
        eq_(pq(s)('a').attr('href'), u)
Ejemplo n.º 2
0
    def test_impala_reviews_link(self):
        a = addon_factory(average_rating=4, total_ratings=37, id=1, slug='xx')
        s = self.render('{{ impala_reviews_link(myaddon) }}', {'myaddon': a})
        assert pq(s)('a').text() == '(37)'

        # without collection uuid
        assert pq(s)('a').attr('href') == '/en-US/firefox/addon/xx/reviews/'

        # with collection uuid
        myuuid = 'f19a8822-1ee3-4145-9440-0a3640201fe6'
        s = self.render('{{ impala_reviews_link(myaddon, myuuid) }}', {
            'myaddon': a,
            'myuuid': myuuid
        })
        assert pq(s)('a').attr('href') == (
            '/en-US/firefox/addon/xx/reviews/?collection_uuid=%s' % myuuid)

        z = Addon(average_rating=0, total_ratings=0, id=1, type=1, slug='xx')
        s = self.render('{{ impala_reviews_link(myaddon) }}', {'myaddon': z})
        assert pq(s)('b').text() == 'Not yet rated'

        # with link
        u = reverse('addons.ratings.list', args=['xx'])
        s = self.render('{{ impala_reviews_link(myaddon) }}', {'myaddon': a})
        assert pq(s)('a').attr('href') == u
Ejemplo n.º 3
0
 def test_attach_translations_missing_key(self):
     data = {
         'foo_translations': None
     }
     self.addon = Addon()
     self.field_class().attach_translations(self.addon, data, 'foo')
     assert self.addon.foo_translations == {}
Ejemplo n.º 4
0
 def test_field_null(self):
     field = self.field_class()
     self.addon = Addon()
     result = field.field_to_native(self.addon, 'name')
     assert result is None
     result = field.field_to_native(self.addon, 'description')
     assert result is None
Ejemplo n.º 5
0
    def fake_object(self, data):
        """Create a fake instance of Addon and related models from ES data."""
        obj = Addon(id=data['id'], slug=data['slug'], is_listed=True)

        if data['current_version'] and data['current_version']['files']:
            data_version = data['current_version']
            obj._current_version = Version(id=data_version['id'],
                                           reviewed=self.handle_date(
                                               data_version['reviewed']),
                                           version=data_version['version'])
            obj._current_version.all_files = [
                File(id=file_['id'],
                     created=self.handle_date(file_['created']),
                     hash=file_['hash'],
                     filename=file_['filename'],
                     size=file_['size'],
                     status=file_['status']) for file_ in data_version['files']
            ]

        # Attach base attributes that have the same name/format in ES and in
        # the model.
        self._attach_fields(
            obj, data,
            ('average_daily_users', 'bayesian_rating', 'created',
             'default_locale', 'guid', 'hotness', 'is_listed', 'last_updated',
             'public_stats', 'slug', 'status', 'type', 'weekly_downloads'))

        # Attach attributes that do not have the same name/format in ES.
        obj.tag_list = data['tags']
        obj.disabled_by_user = data['is_disabled']  # Not accurate, but enough.

        # Attach translations (they require special treatment).
        self._attach_translations(obj, data, self.translated_fields)

        return obj
Ejemplo n.º 6
0
    def test_attach_translations_target_name(self):
        data = {
            'foo_translations': [
                {
                    'lang': 'en-US',
                    'string': 'teststring'
                },
                {
                    'lang': 'es',
                    'string': 'teststring-es'
                },
            ]
        }

        self.addon = Addon()
        with self.activate('es'):
            self.field_class().attach_translations(self.addon,
                                                   data,
                                                   'foo',
                                                   target_name='bar')
        assert self.addon.bar_translations, {
            'en-US': 'teststring',
            'es': 'teststring-es',
        }
        assert self.addon.bar.localized_string == 'teststring-es'
Ejemplo n.º 7
0
 def test_attach_translations_missing_key(self):
     # data mimics what the field will receive from elasticsearch_dsl
     # result object.
     data = Mock()
     data.foo_translations = None
     self.addon = Addon()
     self.field_class().attach_translations(self.addon, data, 'foo')
     assert self.addon.foo_translations == {}
Ejemplo n.º 8
0
def test_version_status():
    addon = Addon()
    version = Version()
    version.all_files = [File(status=amo.STATUS_PUBLIC),
                         File(status=amo.STATUS_UNREVIEWED)]
    assert u'Fully Reviewed,Awaiting Review' == (
        helpers.version_status(addon, version))

    version.all_files = [File(status=amo.STATUS_UNREVIEWED)]
    assert u'Awaiting Review' == helpers.version_status(addon, version)
Ejemplo n.º 9
0
def test_version_status():
    addon = Addon()
    version = Version()
    version.all_files = [File(status=amo.STATUS_PUBLIC),
                         File(status=amo.STATUS_AWAITING_REVIEW)]
    assert u'Approved,Awaiting Review' == (
        helpers.version_status(addon, version))

    version.all_files = [File(status=amo.STATUS_AWAITING_REVIEW)]
    assert u'Awaiting Review' == helpers.version_status(addon, version)
Ejemplo n.º 10
0
    def test_field_null(self):
        field = self.field_class()
        self.addon = Addon()

        field.bind('name', None)
        result = field.to_representation(field.get_attribute(self.addon))
        assert result is None

        field.bind('description', None)
        result = field.to_representation(field.get_attribute(self.addon))
        assert result is None
Ejemplo n.º 11
0
    def setUp(self):
        super(TestCategoriesFeed, self).setUp()
        self.feed = feeds.CategoriesRss()
        self.unicode_string = u'Ελληνικά'

        self.feed.request = mock.Mock()
        self.feed.request.APP.pretty = self.unicode_string

        self.addon = Addon(name=self.unicode_string, id=2, type=1, slug='xx')
        self.addon._current_version = Version(version=u'v%s' %
                                              self.unicode_string)
Ejemplo n.º 12
0
def test_version_status():
    addon = Addon()
    version = Version()
    version.all_files = [
        File(status=amo.STATUS_APPROVED),
        File(status=amo.STATUS_AWAITING_REVIEW),
    ]
    assert 'Approved,Awaiting Review' == (jinja_helpers.version_status(addon, version))

    version.all_files = [File(status=amo.STATUS_AWAITING_REVIEW)]
    assert 'Awaiting Review' == jinja_helpers.version_status(addon, version)
Ejemplo n.º 13
0
 def setUp(self):
     self.factory = APIRequestFactory()
     self.addon = Addon()
     self.addon.default_locale = 'en-US'
     self.addon.name_translations = {
         'en-US': 'English Name',
         'es': 'Name in Español',
     }
     self.addon.description_translations = {
         'en-US': 'English Description',
         'fr': 'Frençh Description',
     }
Ejemplo n.º 14
0
    def create_file(self, **kwargs):
        addon = Addon()
        addon.save()
        ver = Version(version='0.1')
        ver.addon = addon
        ver.save()

        f = File(**kwargs)
        f.version = ver
        f.save()

        return f
Ejemplo n.º 15
0
def test_l10n_menu():
    # No remove_locale_url provided.
    menu = helpers.l10n_menu({})
    assert 'data-rm-locale=""' in menu, menu

    # Specific remove_locale_url provided (eg for user).
    menu = helpers.l10n_menu({}, remove_locale_url='/some/url/')
    assert 'data-rm-locale="/some/url/"' in menu, menu

    # Use the remove_locale_url taken from the addon in the context.
    menu = helpers.l10n_menu({'addon': Addon()}, remove_locale_url='some/url/')
    assert 'data-rm-locale="/en-US/developers/addon/None/rmlocale"' in menu
Ejemplo n.º 16
0
 def test_attach_translations(self):
     # data mimics what the field will receive from elasticsearch_dsl
     # result object.
     data = Mock()
     data.foo_translations = [
         Mock(lang='testlang', string='teststring'),
         Mock(lang='testlang2', string='teststring2'),
     ]
     self.addon = Addon()
     self.field_class().attach_translations(self.addon, data, 'foo')
     assert self.addon.foo_translations == {
         'testlang': 'teststring', 'testlang2': 'teststring2'}
Ejemplo n.º 17
0
 def test_attach_translations(self):
     data = {
         'foo_translations': [
             {'lang': 'en-US', 'string': 'teststring'},
             {'lang': 'es', 'string': 'teststring-es'},
         ]
     }
     self.addon = Addon()
     self.field_class().attach_translations(self.addon, data, 'foo')
     assert self.addon.foo_translations == {
         'en-US': 'teststring',
         'es': 'teststring-es',
     }
Ejemplo n.º 18
0
    def test_mobile_reviews_link(self):
        def s(a):
            return pq(
                self.render('{{ mobile_reviews_link(myaddon) }}',
                            {'myaddon': a}))

        a = Addon(total_reviews=0, id=1, type=1, slug='xx')
        doc = s(a)
        eq_(doc('a').attr('href'), reverse('addons.reviews.add', args=['xx']))

        u = reverse('addons.reviews.list', args=['xx'])

        a = Addon(average_rating=4, total_reviews=37, id=1, type=1, slug='xx')
        doc = s(a)
        eq_(doc('a').attr('href'), u)
        eq_(doc('a').text(), 'Rated 4 out of 5 stars See All 37 Reviews')

        a = Addon(average_rating=4, total_reviews=1, id=1, type=1, slug='xx')
        doc = s(a)
        doc.remove('div')
        eq_(doc('a').attr('href'), u)
        eq_(doc('a').text(), 'See All Reviews')
Ejemplo n.º 19
0
    def fake_object(self, data):
        """Create a fake instance of Addon and related models from ES data."""
        obj = Addon(id=data.id, slug=data.slug)

        # Set base attributes that have the same name/format in ES and in the
        # model.
        self._attach_fields(obj, data,
                            ('default_locale', 'last_updated', 'status'))

        # Attach translations (they require special treatment).
        self._attach_translations(obj, data, ('name', 'description'))

        return obj
Ejemplo n.º 20
0
    def setUp(self):
        super(TestCategoriesFeed, self).setUp()
        self.feed = feeds.CategoriesRss()
        self.u = u'Ελληνικά'
        self.wut = Translation(localized_string=self.u, locale='el')

        self.feed.request = mock.Mock()
        self.feed.request.APP.pretty = self.u

        self.category = Category(db_name=self.u)

        self.addon = Addon(name=self.u, id=2, type=1, slug='xx')
        self.addon._current_version = Version(version='v%s' % self.u)
Ejemplo n.º 21
0
    def test_statusflags(self):
        ctx = {'APP': amo.FIREFOX, 'LANG': 'en-US'}

        # unreviewed
        a = Addon(status=amo.STATUS_UNREVIEWED)
        eq_(statusflags(ctx, a), 'unreviewed')

        # featured
        featured = Addon.objects.get(pk=1003)
        eq_(statusflags(ctx, featured), 'featuredaddon')

        # category featured
        featured = Addon.objects.get(pk=1001)
        eq_(statusflags(ctx, featured), 'featuredaddon')
Ejemplo n.º 22
0
    def test_statusflags(self):
        ctx = {'APP': amo.FIREFOX, 'LANG': 'en-US'}

        # unreviewed
        a = Addon(status=amo.STATUS_NOMINATED)
        assert statusflags(ctx, a) == 'unreviewed'

        # featured
        featured = Addon.objects.get(pk=1003)
        assert statusflags(ctx, featured) == 'featuredaddon'

        # category featured
        featured = Addon.objects.get(pk=1001)
        assert statusflags(ctx, featured) == 'featuredaddon'
Ejemplo n.º 23
0
    def test_flags(self):
        ctx = {'APP': amo.FIREFOX, 'LANG': 'en-US'}

        # unreviewed
        a = Addon(status=amo.STATUS_NOMINATED)
        assert flag(ctx, a) == '<h5 class="flag">Not Reviewed</h5>'

        # featured
        featured = Addon.objects.get(pk=1003)
        assert flag(ctx, featured) == '<h5 class="flag">Featured</h5>'

        # category featured
        featured = Addon.objects.get(pk=1001)
        assert flag(ctx, featured) == '<h5 class="flag">Featured</h5>'
Ejemplo n.º 24
0
    def test_flags(self):
        ctx = {'APP': amo.FIREFOX, 'LANG': 'en-US'}

        # unreviewed
        a = Addon(status=amo.STATUS_UNREVIEWED)
        eq_(flag(ctx, a), '<h5 class="flag">Not Reviewed</h5>')

        # featured
        featured = Addon.objects.get(pk=1003)
        eq_(flag(ctx, featured), '<h5 class="flag">Featured</h5>')

        # category featured
        featured = Addon.objects.get(pk=1001)
        eq_(flag(ctx, featured), '<h5 class="flag">Featured</h5>')
Ejemplo n.º 25
0
    def fake_object(self, data):
        """Create a fake instance of Addon and related models from ES data."""
        obj = Addon(id=data['id'], slug=data['slug'], is_listed=True)

        data_version = data.get('current_version')
        if data_version:
            obj._current_version = Version(addon=obj,
                                           id=data_version['id'],
                                           reviewed=self.handle_date(
                                               data_version['reviewed']),
                                           version=data_version['version'])
            data_files = data_version.get('files', [])
            obj._current_version.all_files = [
                File(id=file_['id'],
                     created=self.handle_date(file_['created']),
                     hash=file_['hash'],
                     filename=file_['filename'],
                     platform=file_['platform'],
                     size=file_['size'],
                     status=file_['status'],
                     version=obj._current_version) for file_ in data_files
            ]

            # In ES we store integers for the appversion info, we need to
            # convert it back to strings.
            compatible_apps = {}
            for app_id, compat_dict in data['appversion'].items():
                app_name = APPS_ALL[int(app_id)]
                compatible_apps[app_name] = ApplicationsVersions(
                    min=AppVersion(version=compat_dict.get('min_human', '')),
                    max=AppVersion(version=compat_dict.get('max_human', '')))

            obj._current_version.compatible_apps = compatible_apps

        # Attach base attributes that have the same name/format in ES and in
        # the model.
        self._attach_fields(
            obj, data,
            ('average_daily_users', 'bayesian_rating', 'created',
             'default_locale', 'guid', 'hotness', 'is_listed', 'last_updated',
             'public_stats', 'slug', 'status', 'type', 'weekly_downloads'))

        # Attach attributes that do not have the same name/format in ES.
        obj.tag_list = data['tags']
        obj.disabled_by_user = data['is_disabled']  # Not accurate, but enough.

        # Attach translations (they require special treatment).
        self._attach_translations(obj, data, self.translated_fields)

        return obj
Ejemplo n.º 26
0
    def test_attach_translations_target_name(self):
        data = {
            'foo_translations': [{
                'lang': 'testlang',
                'string': 'teststring'
            }, {
                'lang': 'testlang2',
                'string': 'teststring2'
            }]
        }

        self.addon = Addon()
        self.field_class().attach_translations(
            self.addon, data, 'foo', target_name='bar')
        assert self.addon.bar_translations, {
            'testlang': 'teststring', 'testlang2': 'teststring2'}
Ejemplo n.º 27
0
    def create_addon(self, license=None):
        data = self.cleaned_data
        a = Addon(guid=data['guid'],
                  name=data['name'],
                  type=data['type'],
                  status=amo.STATUS_UNREVIEWED,
                  homepage=data['homepage'],
                  summary=data['summary'])
        a.save()
        AddonUser(addon=a, user=self.request.user).save()

        self.addon = a
        # Save Version, attach License
        self.create_version(license=license)
        amo.log(amo.LOG.CREATE_ADDON, a)
        log.info('Addon %d saved' % a.id)
        return a
Ejemplo n.º 28
0
 def create_personas(self, number, persona_extras=None):
     persona_extras = persona_extras or {}
     addon = Addon.objects.get(id=15679)
     for i in xrange(number):
         a = Addon(type=amo.ADDON_PERSONA)
         a.name = 'persona-%s' % i
         a.all_categories = []
         a.save()
         v = Version.objects.get(addon=addon)
         v.addon = a
         v.pk = None
         v.save()
         p = Persona(addon_id=a.id, persona_id=i, **persona_extras)
         p.save()
         a.persona = p
         a._current_version = v
         a.status = amo.STATUS_PUBLIC
         a.save()
Ejemplo n.º 29
0
    def test_impala_reviews_link(self):
        addon = addon_factory(average_rating=4,
                              total_ratings=37,
                              id=1,
                              slug='xx')
        content = self.render('{{ impala_reviews_link(myaddon) }}',
                              {'myaddon': addon})
        assert pq(content)('a').text() == '(37)'

        # without collection uuid
        assert pq(content)('a').attr('href') == (
            'http://testserver/en-US/firefox/addon/xx/reviews/')

        # with collection uuid
        myuuid = 'f19a8822-1ee3-4145-9440-0a3640201fe6'
        content = self.render(
            '{{ impala_reviews_link(myaddon, myuuid) }}',
            {
                'myaddon': addon,
                'myuuid': myuuid
            },
        )
        assert pq(content)('a').attr('href') == (
            'http://testserver/en-US/firefox/addon/xx/reviews/'
            '?collection_uuid=%s' % myuuid)

        addon2 = Addon(average_rating=0,
                       total_ratings=0,
                       id=1,
                       type=1,
                       slug='xx')
        content = self.render('{{ impala_reviews_link(myaddon) }}',
                              {'myaddon': addon2})
        assert pq(content)('b').text() == 'Not yet rated'

        # with link
        link = reverse('addons.ratings.list', args=['xx'])
        content = self.render('{{ impala_reviews_link(myaddon) }}',
                              {'myaddon': addon})
        assert pq(content)('a').attr('href') == absolutify(link)
Ejemplo n.º 30
0
    def fake_object(self, data):
        """Create a fake instance of Addon and related models from ES data."""
        obj = Addon(id=data['id'], slug=data['slug'])

        # Attach base attributes that have the same name/format in ES and in
        # the model.
        self._attach_fields(
            obj, data,
            ('average_daily_users', 'bayesian_rating', 'created',
             'default_locale', 'guid', 'has_eula', 'has_privacy_policy',
             'hotness', 'icon_type', 'is_experimental', 'last_updated',
             'modified', 'public_stats', 'slug', 'status', 'type',
             'view_source', 'weekly_downloads'))

        # Attach attributes that do not have the same name/format in ES.
        obj.tag_list = data['tags']
        obj.disabled_by_user = data['is_disabled']  # Not accurate, but enough.
        obj.all_categories = [
            CATEGORIES_BY_ID[cat_id] for cat_id in data.get('category', [])
        ]

        # Attach translations (they require special treatment).
        self._attach_translations(obj, data, self.translated_fields)

        # Attach related models (also faking them). `current_version` is a
        # property we can't write to, so we use the underlying field which
        # begins with an underscore. `current_beta_version` and
        # `latest_unlisted_version` are writeable cached_property so we can
        # directly write to them.
        obj.current_beta_version = self.fake_version_object(
            obj, data.get('current_beta_version'), amo.RELEASE_CHANNEL_LISTED)
        obj._current_version = self.fake_version_object(
            obj, data.get('current_version'), amo.RELEASE_CHANNEL_LISTED)
        obj.latest_unlisted_version = self.fake_version_object(
            obj, data.get('latest_unlisted_version'),
            amo.RELEASE_CHANNEL_UNLISTED)

        data_authors = data.get('listed_authors', [])
        obj.listed_authors = [
            UserProfile(id=data_author['id'],
                        display_name=data_author['name'],
                        username=data_author['username'])
            for data_author in data_authors
        ]

        # We set obj.all_previews to the raw preview data because
        # ESPreviewSerializer will handle creating the fake Preview object
        # for us when its to_representation() method is called.
        obj.all_previews = data.get('previews', [])

        obj.average_rating = data.get('ratings', {}).get('average')
        obj.total_reviews = data.get('ratings', {}).get('count')

        if data['type'] == amo.ADDON_PERSONA:
            persona_data = data.get('persona')
            if persona_data:
                obj.persona = Persona(
                    addon=obj,
                    accentcolor=persona_data['accentcolor'],
                    display_username=persona_data['author'],
                    header=persona_data['header'],
                    footer=persona_data['footer'],
                    # "New" Persona do not have a persona_id, it's a relic from
                    # old ones.
                    persona_id=0 if persona_data['is_new'] else 42,
                    textcolor=persona_data['textcolor'])
            else:
                # Sadly, https://code.djangoproject.com/ticket/14368 prevents
                # us from setting obj.persona = None. This is fixed in
                # Django 1.9, but in the meantime, work around it by creating
                # a Persona instance with a custom attribute indicating that
                # it should not be used.
                obj.persona = Persona()
                obj.persona._broken = True

        return obj