Beispiel #1
0
    def test_app_slug_collision(self):
        Webapp(app_slug='slug').save()
        w2 = Webapp(app_slug='slug')
        w2.save()
        eq_(w2.app_slug, 'slug-1')

        w3 = Webapp(app_slug='slug')
        w3.save()
        eq_(w3.app_slug, 'slug-2')
Beispiel #2
0
 def test_field_null(self):
     field = TranslationSerializerField()
     app = Webapp()
     result = field.field_to_native(app, 'name')
     eq_(result, None)
     result = field.field_to_native(app, 'description')
     eq_(result, None)
Beispiel #3
0
 def test_field_null(self):
     field = self.field_class()
     self.app = Webapp()
     result = field.field_to_native(self.app, 'name')
     eq_(result, None)
     result = field.field_to_native(self.app, 'description')
     eq_(result, None)
Beispiel #4
0
    def create_fake_app(self, data):
        """Create a fake instance of Webapp and related models from ES data."""
        is_packaged = data['app_type'] != amo.ADDON_WEBAPP_HOSTED
        is_privileged = data['app_type'] == amo.ADDON_WEBAPP_PRIVILEGED

        obj = Webapp(id=data['id'], app_slug=data['app_slug'],
                     is_packaged=is_packaged, type=amo.ADDON_WEBAPP,
                     icon_type='image/png')

        # Set relations and attributes we need on those relations.
        # The properties set on latest_version and current_version differ
        # because we are only setting what the serializer is going to need.
        # In particular, latest_version.is_privileged needs to be set because
        # it's used by obj.app_type_id.
        obj.listed_authors = []
        obj._current_version = Version()
        obj._current_version.addon = obj
        obj._current_version._developer_name = data['author']
        obj._current_version.supported_locales = data['supported_locales']
        obj._current_version.version = data['current_version']
        obj._latest_version = Version()
        obj._latest_version.is_privileged = is_privileged
        obj._geodata = Geodata()
        obj.all_categories = [Category(slug=cat) for cat in data['category']]
        obj.all_previews = [Preview(id=p['id'], modified=p['modified'],
            filetype=p['filetype']) for p in data['previews']]
        obj._device_types = [DEVICE_TYPES[d] for d in data['device']]

        # Set base attributes on the "fake" app using the data from ES.
        # It doesn't mean they'll get exposed in the serializer output, that
        # depends on what the fields/exclude attributes in Meta.
        for field_name in ('created', 'modified', 'default_locale',
                           'icon_hash', 'is_escalated', 'is_offline',
                           'manifest_url', 'premium_type', 'regions',
                           'reviewed', 'status', 'weekly_downloads'):
            setattr(obj, field_name, data.get(field_name))

        # Attach translations for all translated attributes.
        for field_name in ('name', 'description', 'homepage', 'support_email',
                           'support_url'):
            ESTranslationSerializerField.attach_translations(obj,
                data, field_name)
        ESTranslationSerializerField.attach_translations(obj._geodata,
            data, 'banner_message')
        ESTranslationSerializerField.attach_translations(obj._current_version,
            data, 'release_notes', target_name='releasenotes')

        # Set attributes that have a different name in ES.
        obj.public_stats = data['has_public_stats']

        # Override obj.get_region() with a static list of regions generated
        # from the region_exclusions stored in ES.
        obj.get_regions = obj.get_regions(obj.get_region_ids(restofworld=True,
            excluded=data['region_exclusions']))

        # Some methods below will need the raw data from ES, put it on obj.
        obj.es_data = data

        return obj
Beispiel #5
0
    def test_has_premium(self):
        webapp = Webapp(premium_type=amo.ADDON_PREMIUM)
        webapp._premium = mock.Mock()
        webapp._premium.price = 1
        eq_(webapp.has_premium(), True)

        webapp._premium.price = 0
        eq_(webapp.has_premium(), True)
Beispiel #6
0
 def test_assign_uuid_max_tries(self, mock_uuid4):
     guid = 'abcdef12-abcd-abcd-abcd-abcdef123456'
     mock_uuid4.return_value = uuid.UUID(guid)
     # Create another webapp with and set the guid.
     Webapp.objects.create(guid=guid)
     # Now `assign_uuid()` should fail.
     app = Webapp()
     with self.assertRaises(ValueError):
         app.save()
Beispiel #7
0
    def test_has_price(self):
        webapp = Webapp(premium_type=amo.ADDON_PREMIUM)
        webapp._premium = mock.Mock()
        webapp._premium.price = None
        webapp._premium.has_price.return_value = True
        eq_(webapp.has_price(), True)

        webapp._premium.has_price.return_value = False
        eq_(webapp.has_price(), False)
Beispiel #8
0
    def test_get_stats_url(self):
        webapp = Webapp(app_slug='woo')

        eq_(webapp.get_stats_url(), '/app/woo/statistics/')

        url = webapp.get_stats_url(
            action='installs_series',
            args=['day', '20120101', '20120201', 'json'])
        eq_(url, '/app/woo/statistics/installs-day-20120101-20120201.json')
Beispiel #9
0
    def test_get_stats_url(self):
        self.skip_if_disabled(settings.REGION_STORES)
        webapp = Webapp(app_slug='woo')

        eq_(webapp.get_stats_url(), '/app/woo/statistics/')

        url = webapp.get_stats_url(action='installs_series',
            args=['day', '20120101', '20120201', 'json'])
        eq_(url, '/app/woo/statistics/installs-day-20120101-20120201.json')
Beispiel #10
0
 def test_field_null(self):
     field = self.field_class()
     self.app = Webapp()
     field.bind('name', None)
     result = field.to_representation(field.get_attribute(self.app))
     eq_(result, None)
     field.source = None
     field.bind('description', None)
     result = field.to_representation(field.get_attribute(self.app))
     eq_(result, None)
Beispiel #11
0
 def setUp(self):
     self.factory = APIRequestFactory()
     self.app = Webapp()
     self.app.default_locale = 'en-US'
     self.app.name_translations = {
         'en-US': u'English Name',
         'es': u'Spànish Name'
     }
     self.app.description_translations = {
         'en-US': u'English Description',
         'fr': u'Frençh Description'
     }
Beispiel #12
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': Webapp()},
                             remove_locale_url='some/url/')
    assert 'data-rm-locale="/developers/app/None/rmlocale"' in menu, menu
Beispiel #13
0
    def test_initial(self):
        app = Webapp(status=amo.STATUS_PUBLIC)
        eq_(self.form(None, addon=app).fields['publish_type'].initial,
            amo.PUBLISH_IMMEDIATE)
        eq_(self.form(None, addon=app).fields['limited'].initial, False)

        app.status = amo.STATUS_UNLISTED
        eq_(self.form(None, addon=app).fields['publish_type'].initial,
            amo.PUBLISH_HIDDEN)
        eq_(self.form(None, addon=app).fields['limited'].initial, False)

        app.status = amo.STATUS_APPROVED
        eq_(self.form(None, addon=app).fields['publish_type'].initial,
            amo.PUBLISH_HIDDEN)
        eq_(self.form(None, addon=app).fields['limited'].initial, True)
Beispiel #14
0
 def to_native(self, obj):
     # fake_app is a fake instance because we need to access a couple
     # properties and methods on Webapp. It should never hit the database.
     fake_app = Webapp(
         id=obj['id'], icon_type='image/png', type=amo.ADDON_WEBAPP,
         default_locale=obj.get('default_locale', settings.LANGUAGE_CODE),
         icon_hash=obj.get('icon_hash'),
         modified=datetime.strptime(obj['modified'], '%Y-%m-%dT%H:%M:%S'))
     ESTranslationSerializerField.attach_translations(fake_app, obj, 'name')
     return {
         'name': self.fields['name'].field_to_native(fake_app, 'name'),
         'icon': fake_app.get_icon_url(64),
         'slug': obj['slug'],
         'manifest_url': obj['manifest_url'],
     }
Beispiel #15
0
 def test_attach_translations(self):
     data = {
         'foo_translations': [{
             'lang': 'testlang',
             'string': 'teststring'
         }, {
             'lang': 'testlang2',
             'string': 'teststring2'
         }]
     }
     self.app = Webapp()
     self.field_class().attach_translations(self.app, data, 'foo')
     eq_(self.app.foo_translations, {
         'testlang': 'teststring',
         'testlang2': 'teststring2'
     })
Beispiel #16
0
 def to_representation(self, obj):
     # fake_app is a fake instance because we need to access a couple
     # properties and methods on Webapp. It should never hit the database.
     self.fake_app = Webapp(
         id=obj['id'], icon_type='image/png',
         default_locale=obj.get('default_locale', settings.LANGUAGE_CODE),
         icon_hash=obj.get('icon_hash'),
         modified=es_to_datetime(obj['modified']))
     ESTranslationSerializerField.attach_translations(
         self.fake_app, obj, 'name')
     return {
         'name': self.fields['name'].to_representation(
             self.fields['name'].get_attribute(self.fake_app)),
         'icon': self.fake_app.get_icon_url(64),
         'slug': obj['slug'],
         'manifest_url': obj['manifest_url'],
     }
Beispiel #17
0
    def test_is_premium_type_upgrade_check(self):
        app = Webapp()
        ALL = set(amo.ADDON_FREES + amo.ADDON_PREMIUMS)
        free_upgrade = ALL - set([amo.ADDON_FREE])
        free_inapp_upgrade = ALL - set([amo.ADDON_FREE, amo.ADDON_FREE_INAPP])

        # Checking ADDON_FREE changes.
        app.premium_type = amo.ADDON_FREE
        for pt in ALL:
            eq_(app.is_premium_type_upgrade(pt), pt in free_upgrade)

        # Checking ADDON_FREE_INAPP changes.
        app.premium_type = amo.ADDON_FREE_INAPP
        for pt in ALL:
            eq_(app.is_premium_type_upgrade(pt), pt in free_inapp_upgrade)

        # All else is false.
        for pt_old in ALL - set([amo.ADDON_FREE, amo.ADDON_FREE_INAPP]):
            app.premium_type = pt_old
            for pt_new in ALL:
                eq_(app.is_premium_type_upgrade(pt_new), False)
Beispiel #18
0
 def test_app_slug_blocklist(self):
     BlacklistedSlug.objects.create(name='slug')
     w = Webapp(app_slug='slug')
     w.save()
     eq_(w.app_slug, 'slug~')
Beispiel #19
0
 def test_app_slugs_separate_from_addon_slugs(self):
     Addon.objects.create(type=1, slug='slug')
     webapp = Webapp(app_slug='slug')
     webapp.save()
     eq_(webapp.slug, 'app-%s' % webapp.id)
     eq_(webapp.app_slug, 'slug')
Beispiel #20
0
 def test_no_version(self):
     eq_(Webapp().get_latest_file(), None)
Beispiel #21
0
 def test_webapp_type(self):
     webapp = Webapp()
     webapp.save()
     eq_(webapp.type, amo.ADDON_WEBAPP)
Beispiel #22
0
 def test_get_region_ids_no_exclusions(self):
     # This returns IDs for the *included* regions.
     eq_(Webapp().get_region_ids(), mkt.regions.REGION_IDS)
Beispiel #23
0
 def test_get_regions_no_exclusions(self):
     # This returns the class definitions for the *included* regions.
     eq_(sorted(Webapp().get_regions()),
         sorted(mkt.regions.REGIONS_CHOICES_ID_DICT.values()))
Beispiel #24
0
 def test_has_no_premium(self):
     webapp = Webapp(premium_type=amo.ADDON_PREMIUM)
     webapp._premium = None
     eq_(webapp.has_price(), False)
Beispiel #25
0
 def test_not_premium(self):
     eq_(Webapp().has_price(), False)
Beispiel #26
0
 def test_no_version(self):
     webapp = Webapp()
     eq_(webapp.get_manifest_json(), None)
     eq_(webapp.current_version, None)
Beispiel #27
0
 def test_has_icon_in_manifest(self, get_manifest_json):
     webapp = Webapp()
     get_manifest_json.return_value = {'icons': {}}
     eq_(webapp.has_icon_in_manifest(), True)
Beispiel #28
0
 def test_no_icon_in_manifest(self, get_manifest_json):
     webapp = Webapp()
     get_manifest_json.return_value = {}
     eq_(webapp.has_icon_in_manifest(), False)
Beispiel #29
0
 def test_mark_done_pending(self):
     w = Webapp()
     eq_(w.status, amo.STATUS_NULL)
     w.mark_done()
     eq_(w.status, amo.WEBAPPS_UNREVIEWED_STATUS)
Beispiel #30
0
    def test_can_be_purchased(self):
        w = Webapp(status=amo.STATUS_PUBLIC, premium_type=True)
        eq_(w.can_be_purchased(), True)

        w = Webapp(status=amo.STATUS_PUBLIC, premium_type=False)
        eq_(w.can_be_purchased(), False)