예제 #1
0
def test_ordering():
    """Given a specific set of primary keys, assure that we return addons
    in that order."""

    app1id = app_factory().id
    app2id = app_factory().id
    app3id = app_factory().id
    semi_arbitrary_order = [app2id, app3id, app1id]
    addons = manual_order(Webapp.objects.all(), semi_arbitrary_order)
    eq_(semi_arbitrary_order, [addon.id for addon in addons])
예제 #2
0
    def test_with_existing_cert_valid(self):
        # Set up. app1 has no rating descriptors, app2 has one.
        data = setup_mock_response('GetRatingChanges')
        cert_id_1 = data['CertList'][0]['CertID']
        cert_id_2 = data['CertList'][1]['CertID']
        app1 = app_factory()
        app2 = app_factory()
        IARCCert.objects.create(app=app1, cert_id=UUID(cert_id_1))
        IARCCert.objects.create(app=app2, cert_id=UUID(cert_id_2))
        eq_(RatingDescriptors.objects.filter(addon=app1).count(), 0)
        RatingDescriptors.objects.create(addon=app2, has_esrb_lang=True)
        eq_(app2.rating_descriptors.to_keys(), ['has_esrb_lang'])
        expected_end_date = datetime.datetime.utcnow()
        expected_start_date = expected_end_date - datetime.timedelta(days=1)

        # GetRatingChanges Call.
        res = get_rating_changes()

        # Check that we called IARC as expected.
        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.headers.get('StorePassword'),
            settings.IARC_V2_STORE_PASSWORD)
        eq_(responses.calls[0].request.headers.get('StoreID'),
            settings.IARC_V2_STORE_ID)
        eq_(
            json.loads(responses.calls[0].request.body), {
                'StartDate': expected_start_date.strftime('%Y-%m-%d'),
                'EndDate': expected_end_date.strftime('%Y-%m-%d'),
                'MaxRows': 500,
                'StartRowIndex': 0
            })
        eq_(res['Result']['ResponseCode'], 'Success')

        # Check that Cert IDs are still correct.
        eq_(UUID(app1.iarc_cert.cert_id), UUID(cert_id_1))
        eq_(UUID(app2.iarc_cert.cert_id), UUID(cert_id_2))

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching. App1 should have gained
        # a descriptor, and app2 should have lost its original descriptor and
        # gained a few.
        app1 = Webapp.objects.get(pk=app1.pk)
        app2 = Webapp.objects.get(pk=app2.pk)
        eq_(app1.rating_descriptors.to_keys(), ['has_esrb_violence_ref'])
        self.assertSetEqual(app2.rating_descriptors.to_keys(), [
            'has_classind_violence', 'has_generic_moderate_violence',
            'has_pegi_moderate_violence', 'has_esrb_violence',
            'has_usk_violence'
        ])
        eq_(app1.content_ratings.all()[0].get_rating_class(), ESRB_10)
        eq_(app2.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
예제 #3
0
    def test_with_existing_cert_valid(self):
        # Set up. app1 has no rating descriptors, app2 has one.
        data = setup_mock_response('GetRatingChanges')
        cert_id_1 = data['CertList'][0]['CertID']
        cert_id_2 = data['CertList'][1]['CertID']
        app1 = app_factory()
        app2 = app_factory()
        IARCCert.objects.create(app=app1, cert_id=UUID(cert_id_1))
        IARCCert.objects.create(app=app2, cert_id=UUID(cert_id_2))
        eq_(RatingDescriptors.objects.filter(addon=app1).count(), 0)
        RatingDescriptors.objects.create(addon=app2, has_esrb_lang=True)
        eq_(app2.rating_descriptors.to_keys(), ['has_esrb_lang'])
        expected_end_date = datetime.datetime.utcnow()
        expected_start_date = expected_end_date - datetime.timedelta(days=1)

        # GetRatingChanges Call.
        res = get_rating_changes()

        # Check that we called IARC as expected.
        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.headers.get('StorePassword'),
            settings.IARC_V2_STORE_PASSWORD)
        eq_(responses.calls[0].request.headers.get('StoreID'),
            settings.IARC_V2_STORE_ID)
        eq_(json.loads(responses.calls[0].request.body), {
            'StartDate': expected_start_date.strftime('%Y-%m-%d'),
            'EndDate': expected_end_date.strftime('%Y-%m-%d'),
            'MaxRows': 500,
            'StartRowIndex': 0
        })
        eq_(res['Result']['ResponseCode'], 'Success')

        # Check that Cert IDs are still correct.
        eq_(UUID(app1.iarc_cert.cert_id), UUID(cert_id_1))
        eq_(UUID(app2.iarc_cert.cert_id), UUID(cert_id_2))

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching. App1 should have gained
        # a descriptor, and app2 should have lost its original descriptor and
        # gained a few.
        app1 = Webapp.objects.get(pk=app1.pk)
        app2 = Webapp.objects.get(pk=app2.pk)
        eq_(app1.rating_descriptors.to_keys(), ['has_esrb_violence_ref'])
        self.assertSetEqual(
            app2.rating_descriptors.to_keys(),
            ['has_classind_violence', 'has_generic_moderate_violence',
             'has_pegi_moderate_violence', 'has_esrb_violence',
             'has_usk_violence'])
        eq_(app1.content_ratings.all()[0].get_rating_class(), ESRB_10)
        eq_(app2.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
예제 #4
0
    def test_events_webapps(self):
        self.app = app_factory()
        self.check_event(mkt.STATUS_PENDING, mkt.REVIEWED_WEBAPP_HOSTED)

        RereviewQueue.objects.create(addon=self.app)
        self.check_event(mkt.STATUS_PUBLIC,
                         mkt.REVIEWED_WEBAPP_REREVIEW,
                         in_rereview=True)
        self.check_event(mkt.STATUS_UNLISTED,
                         mkt.REVIEWED_WEBAPP_REREVIEW,
                         in_rereview=True)
        self.check_event(mkt.STATUS_APPROVED,
                         mkt.REVIEWED_WEBAPP_REREVIEW,
                         in_rereview=True)
        RereviewQueue.objects.all().delete()

        self.app.is_packaged = True
        self.check_event(mkt.STATUS_PENDING, mkt.REVIEWED_WEBAPP_PACKAGED)
        self.check_event(mkt.STATUS_PUBLIC, mkt.REVIEWED_WEBAPP_UPDATE)
        self.check_event(mkt.STATUS_UNLISTED, mkt.REVIEWED_WEBAPP_UPDATE)
        self.check_event(mkt.STATUS_APPROVED, mkt.REVIEWED_WEBAPP_UPDATE)

        self.app.latest_version.is_privileged = True
        self.check_event(mkt.STATUS_PENDING, mkt.REVIEWED_WEBAPP_PRIVILEGED)
        self.check_event(mkt.STATUS_PUBLIC,
                         mkt.REVIEWED_WEBAPP_PRIVILEGED_UPDATE)
        self.check_event(mkt.STATUS_UNLISTED,
                         mkt.REVIEWED_WEBAPP_PRIVILEGED_UPDATE)
        self.check_event(mkt.STATUS_APPROVED,
                         mkt.REVIEWED_WEBAPP_PRIVILEGED_UPDATE)
예제 #5
0
    def test_search_and_attach_cert(self):
        setup_mock_response('AttachToCert')
        setup_mock_response('SearchCerts')

        app = app_factory()
        cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80'
        data = search_and_attach_cert(app, cert_id)
        eq_(data, {
            'ResultCode': 'Success',
            'ErrorMessage': None,
            'ErrorID': None
        })
        eq_(UUID(app.iarc_cert.cert_id), UUID(cert_id))
        self.assertSetEqual(app.rating_descriptors.to_keys(), [
            'has_classind_lang', 'has_generic_parental_guidance_recommended',
            'has_pegi_parental_guidance_recommended'
        ])
        self.assertSetEqual(app.rating_interactives.to_keys(), [
            'has_shares_location', 'has_digital_purchases',
            'has_users_interact'
        ])
        eq_(
            app.get_content_ratings_by_body(), {
                'generic': '12',
                'esrb': '13',
                'classind': '12',
                'usk': '12',
                'pegi': 'parental-guidance'
            })
예제 #6
0
    def test_refresh(self):
        setup_mock_response('SearchCerts')
        cert = UUID('adb3261b-c657-4fd2-a057-bc9f85310b80')
        app = app_factory()
        IARCCert.objects.create(app=app, cert_id=cert.get_hex())
        refresh(app)
        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.headers.get('StorePassword'),
            settings.IARC_V2_STORE_PASSWORD)
        eq_(responses.calls[0].request.headers.get('StoreID'),
            settings.IARC_V2_STORE_ID)
        eq_(json.loads(responses.calls[0].request.body),
            {'CertID': unicode(cert)})

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching.
        app = Webapp.objects.get(pk=app.pk)
        self.assertSetEqual(app.rating_descriptors.to_keys(), [
            'has_classind_lang', 'has_generic_parental_guidance_recommended',
            'has_pegi_parental_guidance_recommended'
        ])
        self.assertSetEqual(app.rating_interactives.to_keys(), [
            'has_shares_location', 'has_digital_purchases',
            'has_users_interact'
        ])
        eq_(app.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
예제 #7
0
    def _create_group_of_games(self):
        content = [app_factory(), website_factory(), app_factory(),
                   website_factory()]
        # Add tags.
        for i, cat in enumerate(GAME_CATEGORIES):
            tag = Tag.objects.get_or_create(tag_text=GAME_CATEGORIES[i])[0]
            if hasattr(content[i], 'tags'):
                content[i].tags.add(tag)
            else:
                content[i].keywords.add(tag)

        self.reindex(Webapp)
        self.reindex(Website)
        self.refresh(('webapp', 'website'))

        return content
예제 #8
0
 def setUp(self):
     self.saved_cb = models._on_change_callbacks.copy()
     models._on_change_callbacks.clear()
     self.cb = Mock()
     self.cb.__name__ = 'testing_mock_callback'
     Webapp.on_change(self.cb)
     self.testapp = app_factory(public_stats=True)
예제 #9
0
    def setUp(self):
        self.app = app_factory(name='XXX')
        eq_(EscalationQueue.objects.filter(webapp=self.app).count(), 0)

        patcher = mock.patch.object(settings, 'TASK_USER_ID', 4043307)
        patcher.start()
        self.addCleanup(patcher.stop)
예제 #10
0
    def test_refresh(self):
        setup_mock_response('SearchCerts')
        cert = UUID('adb3261b-c657-4fd2-a057-bc9f85310b80')
        app = app_factory()
        IARCCert.objects.create(app=app, cert_id=cert.get_hex())
        refresh(app)
        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.headers.get('StorePassword'),
            settings.IARC_V2_STORE_PASSWORD)
        eq_(responses.calls[0].request.headers.get('StoreID'),
            settings.IARC_V2_STORE_ID)
        eq_(json.loads(responses.calls[0].request.body), {
            'CertID': unicode(cert)
        })

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching.
        app = Webapp.objects.get(pk=app.pk)
        self.assertSetEqual(
            app.rating_descriptors.to_keys(),
            ['has_classind_lang', 'has_generic_parental_guidance_recommended',
             'has_pegi_parental_guidance_recommended'])
        self.assertSetEqual(
            app.rating_interactives.to_keys(),
            ['has_shares_location', 'has_digital_purchases',
             'has_users_interact'])
        eq_(app.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
예제 #11
0
    def setUp(self):
        self.app = app_factory(name='XXX')
        eq_(EscalationQueue.objects.filter(addon=self.app).count(), 0)

        patcher = mock.patch.object(settings, 'TASK_USER_ID', 4043307)
        patcher.start()
        self.addCleanup(patcher.stop)
예제 #12
0
    def test_events_webapps(self):
        self.app = app_factory()
        self.check_event(mkt.STATUS_PENDING,
                         mkt.REVIEWED_WEBAPP_HOSTED)

        RereviewQueue.objects.create(addon=self.app)
        self.check_event(mkt.STATUS_PUBLIC,
                         mkt.REVIEWED_WEBAPP_REREVIEW, in_rereview=True)
        self.check_event(mkt.STATUS_UNLISTED,
                         mkt.REVIEWED_WEBAPP_REREVIEW, in_rereview=True)
        self.check_event(mkt.STATUS_APPROVED,
                         mkt.REVIEWED_WEBAPP_REREVIEW, in_rereview=True)
        RereviewQueue.objects.all().delete()

        self.app.is_packaged = True
        self.check_event(mkt.STATUS_PENDING,
                         mkt.REVIEWED_WEBAPP_PACKAGED)
        self.check_event(mkt.STATUS_PUBLIC,
                         mkt.REVIEWED_WEBAPP_UPDATE)
        self.check_event(mkt.STATUS_UNLISTED,
                         mkt.REVIEWED_WEBAPP_UPDATE)
        self.check_event(mkt.STATUS_APPROVED,
                         mkt.REVIEWED_WEBAPP_UPDATE)

        self.app.latest_version.is_privileged = True
        self.check_event(mkt.STATUS_PENDING,
                         mkt.REVIEWED_WEBAPP_PRIVILEGED)
        self.check_event(mkt.STATUS_PUBLIC,
                         mkt.REVIEWED_WEBAPP_PRIVILEGED_UPDATE)
        self.check_event(mkt.STATUS_UNLISTED,
                         mkt.REVIEWED_WEBAPP_PRIVILEGED_UPDATE)
        self.check_event(mkt.STATUS_APPROVED,
                         mkt.REVIEWED_WEBAPP_PRIVILEGED_UPDATE)
예제 #13
0
def homescreen_factory(self):
    # Homescreens may not be added to feed collections.
    homescreen = app_factory(name=u'Elegant Waffle',
                                  description=u'homescreen runner',
                                  created=self.days_ago(5),
                                  manifest_url='http://h.testmanifest.com')
    Tag(tag_text='homescreen').save_tag(homescreen)
    return homescreen
예제 #14
0
def homescreen_factory(self):
    # Homescreens may not be added to feed collections.
    homescreen = app_factory(name=u'Elegant Waffle',
                             description=u'homescreen runner',
                             created=self.days_ago(5),
                             manifest_url='http://h.testmanifest.com')
    Tag(tag_text='homescreen').save_tag(homescreen)
    return homescreen
예제 #15
0
    def test_empty(self):
        self.webapp = app_factory()
        self.website = website_factory()
        self.refresh(('webapp', 'website'))

        res = self.anon.get(self.url)
        eq_(res.status_code, 200)
        eq_(len(res.json['objects']), 0)
예제 #16
0
 def setUp(self):
     self.app = app_factory(status=mkt.STATUS_PENDING)
     self.website = website_factory()
     self.user = user_factory(email='editor')
     self.grant_permission(self.user, 'Apps:Review')
     self.admin_user = user_factory(email='admin')
     self.grant_permission(self.admin_user, '*:*', name='Admins')
     user_factory(email='regular')
예제 #17
0
    def test_empty(self):
        self.webapp = app_factory()
        self.website = website_factory()
        self.refresh(('webapp', 'website'))

        res = self.anon.get(self.url)
        eq_(res.status_code, 200)
        eq_(len(res.json['objects']), 0)
예제 #18
0
 def setUp(self):
     self.app = app_factory(status=mkt.STATUS_PENDING)
     self.website = website_factory()
     self.user = user_factory(email='editor')
     self.grant_permission(self.user, 'Apps:Review')
     self.admin_user = user_factory(email='admin')
     self.grant_permission(self.admin_user, '*:*', name='Admins')
     user_factory(email='regular')
예제 #19
0
 def setUp(self):
     super(TestUserHasPermNoteApps, self).setUp()
     self.app = app_factory()
     self.developer = user_factory()
     self.developer.addonuser_set.create(addon=self.app)
     self.reviewer = user_factory()
     self.grant_permission(self.reviewer, "Apps", "Review")
     self.thread = CommunicationThread.objects.create(_addon=self.app, _version=self.app.latest_version)
예제 #20
0
def make_packaged_app():
    ap = app_factory()
    ap.update(is_packaged=True)
    f = ap.latest_version.all_files[0]
    fp = os.path.join(ap.latest_version.path_prefix, f.filename)
    with private_storage.open(fp, 'w') as out:
        out.write('.')
    return ap
예제 #21
0
def make_packaged_app():
    ap = app_factory()
    ap.update(is_packaged=True)
    f = ap.latest_version.all_files[0]
    fp = os.path.join(ap.latest_version.path_prefix, f.filename)
    with private_storage.open(fp, 'w') as out:
        out.write('.')
    return ap
예제 #22
0
 def test_indexable(self):
     homescreen = app_factory(name=u'Elegant Waffle',
                              description=u'homescreen runner',
                              created=self.days_ago(5),
                              manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(homescreen)
     homescreen.save()
     q = WebappIndexer.get_indexable()
     eq_(list(q), [self.app])
예제 #23
0
    def test_lang(self):
        app = app_factory(description={'fr': 'Le blah', 'en-US': 'Blah'})
        url = reverse('app-detail', args=[app.pk])

        res = self.client.get(url + '?lang=en')
        eq_(json.loads(res.content)['description'], 'Blah')

        res = self.client.get(url + '?lang=fr')
        eq_(json.loads(res.content)['description'], 'Le blah')
예제 #24
0
 def test_indexable(self):
     homescreen = app_factory(name=u'Elegant Waffle',
                              description=u'homescreen runner',
                              created=self.days_ago(5),
                              manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(homescreen)
     homescreen.save()
     q = WebappIndexer.get_indexable()
     eq_(list(q), [self.app])
예제 #25
0
    def test_lang(self):
        app = app_factory(description={"fr": "Le blah", "en-US": "Blah"})
        url = reverse("app-detail", args=[app.pk])

        res = self.client.get(url + "?lang=en")
        eq_(json.loads(res.content)["description"], "Blah")

        res = self.client.get(url + "?lang=fr")
        eq_(json.loads(res.content)["description"], "Le blah")
예제 #26
0
    def test_lang(self):
        app = app_factory(description={'fr': 'Le blah', 'en-US': 'Blah'})
        url = reverse('app-detail', args=[app.pk])

        res = self.client.get(url + '?lang=en')
        eq_(json.loads(res.content)['description'], 'Blah')

        res = self.client.get(url + '?lang=fr')
        eq_(json.loads(res.content)['description'], 'Le blah')
예제 #27
0
 def setUp(self):
     super(TestUserHasPermNoteApps, self).setUp()
     self.app = app_factory()
     self.developer = user_factory()
     self.developer.addonuser_set.create(addon=self.app)
     self.reviewer = user_factory()
     self.grant_permission(self.reviewer, 'Apps', 'Review')
     self.thread = CommunicationThread.objects.create(
         _addon=self.app, _version=self.app.latest_version)
예제 #28
0
 def test_with_user_purchased(self, region_from_request, purchase_ids):
     region_from_request.return_value = mkt.regions.BRA
     purchased_app = app_factory()
     purchase_ids.return_value = [purchased_app.pk]
     res = self.client.get(self.url)
     data = json.loads(res.content)
     eq_(data['region'], 'br')
     eq_(data['apps']['installed'], [])
     eq_(data['apps']['developed'], [])
     eq_(data['apps']['purchased'], [purchased_app.pk])
예제 #29
0
 def test_with_user_purchased(self, region_from_request, purchase_ids):
     region_from_request.return_value = mkt.regions.BRA
     purchased_app = app_factory()
     purchase_ids.return_value = [purchased_app.pk]
     res = self.client.get(self.url)
     data = json.loads(res.content)
     eq_(data["region"], "br")
     eq_(data["apps"]["installed"], [])
     eq_(data["apps"]["developed"], [])
     eq_(data["apps"]["purchased"], [purchased_app.pk])
예제 #30
0
 def test_with_user_installed(self, region_from_request):
     region_from_request.return_value = mkt.regions.BRA
     installed_app = app_factory()
     Installed.objects.create(user=self.user, addon=installed_app)
     res = self.client.get(self.url)
     data = json.loads(res.content)
     eq_(data["region"], "br")
     eq_(data["apps"]["installed"], [installed_app.pk])
     eq_(data["apps"]["developed"], [])
     eq_(data["apps"]["purchased"], [])
예제 #31
0
 def test_with_user_purchased(self, region_from_request, purchase_ids):
     region_from_request.return_value = mkt.regions.BRA
     purchased_app = app_factory()
     purchase_ids.return_value = [purchased_app.pk]
     res = self.client.get(self.url)
     data = json.loads(res.content)
     eq_(data['region'], 'br')
     eq_(data['apps']['installed'], [])
     eq_(data['apps']['developed'], [])
     eq_(data['apps']['purchased'], [purchased_app.pk])
예제 #32
0
 def test_with_user_installed(self, region_from_request):
     region_from_request.return_value = mkt.regions.BRA
     installed_app = app_factory()
     Installed.objects.create(user=self.user, webapp=installed_app)
     res = self.client.get(self.url)
     data = json.loads(res.content)
     eq_(data['region'], 'br')
     eq_(data['apps']['installed'], [installed_app.pk])
     eq_(data['apps']['developed'], [])
     eq_(data['apps']['purchased'], [])
예제 #33
0
 def test_with_user_installed(self, region_from_request):
     region_from_request.return_value = mkt.regions.BRA
     installed_app = app_factory()
     Installed.objects.create(user=self.user, addon=installed_app)
     res = self.client.get(self.url)
     data = json.loads(res.content)
     eq_(data['region'], 'br')
     eq_(data['apps']['installed'], [installed_app.pk])
     eq_(data['apps']['developed'], [])
     eq_(data['apps']['purchased'], [])
예제 #34
0
    def test_with_existing_cert_valid(self):
        data = setup_mock_response('GetRatingChanges')
        cert_id_1 = data['CertList'][0]['CertID']
        cert_id_2 = data['CertList'][1]['CertID']
        app1 = app_factory()
        app2 = app_factory()
        IARCCert.objects.create(app=app1, cert_id=UUID(cert_id_1))
        IARCCert.objects.create(app=app2, cert_id=UUID(cert_id_2))
        eq_(RatingDescriptors.objects.filter(addon=app1).count(), 0)
        RatingDescriptors.objects.create(addon=app2, has_esrb_lang=True)
        eq_(app2.rating_descriptors.to_keys(), ['has_esrb_lang'])
        expected_start_date = datetime.datetime.utcnow()
        expected_end_date = expected_start_date - datetime.timedelta(days=1)

        res = get_rating_changes()

        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.url,
            urljoin(settings.IARC_V2_SERVICE_ENDPOINT, 'GetRatingChanges'))
        eq_(
            json.loads(responses.calls[0].request.body), {
                'StartDate': expected_start_date.strftime('%Y-%m-%d'),
                'EndDate': expected_end_date.strftime('%Y-%m-%d'),
                'MaxRows': 500,
                'StartRowIndex': 0
            })

        eq_(UUID(app1.iarc_cert.cert_id), UUID(cert_id_1))
        eq_(UUID(app2.iarc_cert.cert_id), UUID(cert_id_2))

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching.
        app1 = Webapp.objects.get(pk=app1.pk)
        app2 = Webapp.objects.get(pk=app2.pk)
        eq_(app1.rating_descriptors.to_keys(), ['has_esrb_violence_ref'])
        eq_(app2.rating_descriptors.to_keys(),
            ['has_classind_violence', 'has_esrb_violence', 'has_usk_violence'])
        eq_(res['Result']['ResponseCode'], 'Success')
        eq_(app1.content_ratings.all()[0].get_rating_class(), ESRB_10)
        eq_(app2.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
예제 #35
0
 def test_upsell(self):
     app = self.create_app()
     upsell = app_factory()
     self.make_premium(upsell)
     AddonUpsell.objects.create(free=app, premium=upsell)
     res = self.client.get(self.get_url)
     eq_(res.status_code, 200)
     obj = json.loads(res.content)["upsell"]
     eq_(obj["id"], upsell.id)
     eq_(obj["app_slug"], upsell.app_slug)
     eq_(obj["name"], upsell.name)
     eq_(obj["icon_url"], upsell.get_icon_url(128))
     eq_(obj["resource_uri"], reverse("app-detail", kwargs={"pk": upsell.id}))
예제 #36
0
 def test_iarc_app_data(self):
     self.app = app_factory()
     self.profile = user_factory()
     self.app.addonuser_set.create(user=self.profile)
     eq_(_iarc_app_data(self.app),
         {'StoreProductID': self.app.guid,
          'StoreProductURL': absolutify(self.app.get_url_path()),
          'EmailAddress': self.profile.email,
          'CompanyName': u'',
          'StoreDeveloperID': self.app.pk,
          'DeveloperEmail': self.profile.email,
          'Publish': True,
          'ProductName': unicode(self.app.name)})
예제 #37
0
 def make_homescreen(self):
     self.homescreen = app_factory(name=u'Elegant Waffle',
                                   description=u'homescreen runner',
                                   created=self.days_ago(5),
                                   manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(self.homescreen)
     self.homescreen.addondevicetype_set.create(
         device_type=mkt.DEVICE_GAIA.id)
     self.homescreen.update(categories=['health-fitness', 'productivity'])
     self.homescreen.update_version()
     HomescreenIndexer.index_ids([self.homescreen.pk], no_delay=True)
     self.refresh(('webapp', 'website', 'extension', 'homescreen'))
     return self.homescreen
예제 #38
0
 def make_homescreen(self):
     self.homescreen = app_factory(name=u'Elegant Waffle',
                                   description=u'homescreen runner',
                                   created=self.days_ago(5),
                                   manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(self.homescreen)
     self.homescreen.addondevicetype_set.create(
         device_type=mkt.DEVICE_GAIA.id)
     self.homescreen.update(categories=['health-fitness', 'productivity'])
     self.homescreen.update_version()
     HomescreenIndexer.index_ids([self.homescreen.pk], no_delay=True)
     self.refresh(('webapp', 'website', 'extension', 'homescreen'))
     return self.homescreen
예제 #39
0
 def test_app_data(self):
     self.app = app_factory()
     self.profile = user_factory()
     self.app.addonuser_set.create(user=self.profile)
     eq_(app_data(self.app),
         {'StoreProductID': self.app.guid,
          'StoreProductURL': absolutify(self.app.get_url_path()),
          'EmailAddress': self.profile.email,
          'CompanyName': u'',
          'StoreDeveloperID': self.app.pk,
          'DeveloperEmail': self.profile.email,
          'Publish': True,
          'ProductName': unicode(self.app.name)})
예제 #40
0
    def test_with_existing_cert_valid(self):
        data = setup_mock_response('GetRatingChanges')
        cert_id_1 = data['CertList'][0]['CertID']
        cert_id_2 = data['CertList'][1]['CertID']
        app1 = app_factory()
        app2 = app_factory()
        IARCCert.objects.create(app=app1, cert_id=UUID(cert_id_1))
        IARCCert.objects.create(app=app2, cert_id=UUID(cert_id_2))
        eq_(RatingDescriptors.objects.filter(addon=app1).count(), 0)
        RatingDescriptors.objects.create(addon=app2, has_esrb_lang=True)
        eq_(app2.rating_descriptors.to_keys(), ['has_esrb_lang'])
        expected_start_date = datetime.datetime.utcnow()
        expected_end_date = expected_start_date - datetime.timedelta(days=1)

        res = get_rating_changes()

        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.url,
            urljoin(settings.IARC_V2_SERVICE_ENDPOINT, 'GetRatingChanges'))
        eq_(json.loads(responses.calls[0].request.body), {
            'StartDate': expected_start_date.strftime('%Y-%m-%d'),
            'EndDate': expected_end_date.strftime('%Y-%m-%d'),
            'MaxRows': 500,
            'StartRowIndex': 0
        })

        eq_(UUID(app1.iarc_cert.cert_id), UUID(cert_id_1))
        eq_(UUID(app2.iarc_cert.cert_id), UUID(cert_id_2))

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching.
        app1 = Webapp.objects.get(pk=app1.pk)
        app2 = Webapp.objects.get(pk=app2.pk)
        eq_(app1.rating_descriptors.to_keys(), ['has_esrb_violence_ref'])
        eq_(app2.rating_descriptors.to_keys(),
            ['has_classind_violence', 'has_esrb_violence', 'has_usk_violence'])
        eq_(res['Result']['ResponseCode'], 'Success')
        eq_(app1.content_ratings.all()[0].get_rating_class(), ESRB_10)
        eq_(app2.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
예제 #41
0
 def test_attach_to_cert_uuid_hex_string(self):
     setup_mock_response('AttachToCert')
     fake_app = app_factory()
     fake_cert = uuid4()
     data = _attach_to_cert(fake_app, fake_cert.get_hex())
     eq_(data,
         {'ResultCode': 'Success', 'ErrorMessage': None, 'ErrorID': None})
     expected_json = app_data(fake_app)
     expected_json['CertID'] = unicode(fake_cert)
     eq_(len(responses.calls), 1)
     eq_(responses.calls[0].request.url,
         urljoin(settings.IARC_V2_SERVICE_ENDPOINT, 'AttachToCert'))
     eq_(json.loads(responses.calls[0].request.body), expected_json)
예제 #42
0
 def make_homescreen(self):
     post_request_task._start_queuing_tasks()
     self.homescreen = app_factory(name=u'Elegant Waffle',
                                   description=u'homescreen runner',
                                   created=self.days_ago(5),
                                   manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(self.homescreen)
     self.homescreen.addondevicetype_set.create(
         device_type=mkt.DEVICE_GAIA.id)
     self.homescreen.update_version()
     self.homescreen.update(categories=['health-fitness', 'productivity'])
     post_request_task._send_tasks_and_stop_queuing()
     self.refresh(('webapp', 'extension', 'homescreen'))
     return self.homescreen
예제 #43
0
 def test_upsell(self):
     app = self.create_app()
     upsell = app_factory()
     self.make_premium(upsell)
     AddonUpsell.objects.create(free=app, premium=upsell)
     res = self.client.get(self.get_url)
     eq_(res.status_code, 200)
     obj = json.loads(res.content)['upsell']
     eq_(obj['id'], upsell.id)
     eq_(obj['app_slug'], upsell.app_slug)
     eq_(obj['name'], upsell.name)
     eq_(obj['icon_url'], upsell.get_icon_url(128))
     eq_(obj['resource_uri'], reverse('app-detail',
                                      kwargs={'pk': upsell.id}))
예제 #44
0
 def make_homescreen(self):
     post_request_task._start_queuing_tasks()
     self.homescreen = app_factory(name=u'Elegant Waffle',
                                   description=u'homescreen runner',
                                   created=self.days_ago(5),
                                   manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(self.homescreen)
     self.homescreen.addondevicetype_set.create(
         device_type=mkt.DEVICE_GAIA.id)
     self.homescreen.update_version()
     self.homescreen.update(categories=['health-fitness', 'productivity'])
     post_request_task._send_tasks_and_stop_queuing()
     self.refresh(('webapp', 'website', 'extension', 'homescreen'))
     return self.homescreen
예제 #45
0
    def _create_group_of_games(self):
        content = [
            app_factory(),
            website_factory(),
            app_factory(),
            website_factory()
        ]
        # Add tags.
        game_tag = Tag.objects.get_or_create(tag_text='featured-game')[0]
        for i, cat in enumerate(GAME_CATEGORIES):
            tag = Tag.objects.get_or_create(tag_text=GAME_CATEGORIES[i])[0]
            if hasattr(content[i], 'tags'):
                content[i].tags.add(game_tag)
                content[i].tags.add(tag)
            else:
                content[i].keywords.add(game_tag)
                content[i].keywords.add(tag)

        self.reindex(Webapp)
        self.reindex(Website)
        self.refresh(('webapp', 'website'))

        return content
예제 #46
0
 def test_upsell(self):
     app = self.create_app()
     upsell = app_factory()
     self.make_premium(upsell)
     AddonUpsell.objects.create(free=app, premium=upsell)
     res = self.client.get(self.get_url)
     eq_(res.status_code, 200)
     obj = json.loads(res.content)['upsell']
     eq_(obj['id'], upsell.id)
     eq_(obj['app_slug'], upsell.app_slug)
     eq_(obj['name'], upsell.name)
     eq_(obj['icon_url'], upsell.get_icon_url(128))
     eq_(obj['resource_uri'],
         reverse('app-detail', kwargs={'pk': upsell.id}))
예제 #47
0
 def test_iarc_app_data_not_public(self):
     self.app = app_factory()
     self.profile = user_factory()
     self.app.addonuser_set.create(user=self.profile)
     with mock.patch.object(self.app, 'is_public') as is_public_mock:
         is_public_mock.return_value = False
         eq_(_iarc_app_data(self.app),
             {'StoreProductID': self.app.guid,
              'StoreProductURL': absolutify(self.app.get_url_path()),
              'EmailAddress': self.profile.email,
              'CompanyName': u'',
              'StoreDeveloperID': self.app.pk,
              'DeveloperEmail': self.profile.email,
              'Publish': False,
              'ProductName': unicode(self.app.name)})
예제 #48
0
 def test_attach_to_cert_uuid_hex_string(self):
     setup_mock_response('AttachToCert')
     fake_app = app_factory()
     fake_cert = uuid4()
     data = _attach_to_cert(fake_app, fake_cert.get_hex())
     eq_(data,
         {'ResultCode': 'Success', 'ErrorMessage': None, 'ErrorID': None})
     expected_json = _iarc_app_data(fake_app)
     expected_json['CertID'] = unicode(fake_cert)
     eq_(len(responses.calls), 1)
     eq_(responses.calls[0].request.headers.get('StorePassword'),
         settings.IARC_V2_STORE_PASSWORD)
     eq_(responses.calls[0].request.headers.get('StoreID'),
         settings.IARC_V2_STORE_ID)
     eq_(json.loads(responses.calls[0].request.body), expected_json)
예제 #49
0
 def test_attach_to_cert_uuid_hex_string(self):
     setup_mock_response('AttachToCert')
     fake_app = app_factory()
     fake_cert = uuid4()
     data = _attach_to_cert(fake_app, fake_cert.get_hex())
     eq_(data,
         {'ResultCode': 'Success', 'ErrorMessage': None, 'ErrorID': None})
     expected_json = _iarc_app_data(fake_app)
     expected_json['CertID'] = unicode(fake_cert)
     eq_(len(responses.calls), 1)
     eq_(responses.calls[0].request.headers.get('StorePassword'),
         settings.IARC_V2_STORE_PASSWORD)
     eq_(responses.calls[0].request.headers.get('StoreID'),
         settings.IARC_V2_STORE_ID)
     eq_(json.loads(responses.calls[0].request.body), expected_json)
예제 #50
0
 def test_app_data_not_public(self):
     self.app = app_factory()
     self.profile = user_factory()
     self.app.addonuser_set.create(user=self.profile)
     with mock.patch.object(self.app, 'is_public') as is_public_mock:
         is_public_mock.return_value = False
         eq_(app_data(self.app),
             {'StoreProductID': self.app.guid,
              'StoreProductURL': absolutify(self.app.get_url_path()),
              'EmailAddress': self.profile.email,
              'CompanyName': u'',
              'StoreDeveloperID': self.app.pk,
              'DeveloperEmail': self.profile.email,
              'Publish': False,
              'ProductName': unicode(self.app.name)})
예제 #51
0
    def test_search_and_attach_cert_invalid(self):
        setup_mock_response('SearchCerts', '{}')  # Invalid data.
        setup_mock_response('AttachToCert')
        app = app_factory()
        cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80'
        with self.assertRaises(IARCException):
            search_and_attach_cert(app, cert_id)

        # Just to make sure we didn't do anything. There should have been only
        # one call to SearchCerts, none to AttachToCert.
        eq_(len(responses.calls), 1)
        eq_(RatingDescriptors.objects.filter(addon=app).exists(), False)
        eq_(RatingInteractives.objects.filter(addon=app).exists(), False)
        eq_(IARCCert.objects.filter(app=app).exists(), False)
        eq_(app.content_ratings.count(), 0)
예제 #52
0
    def test_search_and_attach_cert_invalid(self):
        setup_mock_response('SearchCerts', '{}')  # Invalid data.
        setup_mock_response('AttachToCert')
        app = app_factory()
        cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80'
        with self.assertRaises(IARCException):
            search_and_attach_cert(app, cert_id)

        # Just to make sure we didn't do anything. There should have been only
        # one call to SearchCerts, none to AttachToCert.
        eq_(len(responses.calls), 1)
        eq_(RatingDescriptors.objects.filter(addon=app).exists(), False)
        eq_(RatingInteractives.objects.filter(addon=app).exists(), False)
        eq_(IARCCert.objects.filter(app=app).exists(), False)
        eq_(app.content_ratings.count(), 0)
예제 #53
0
 def test_attach_to_cert_uuid_hex_string(self):
     setup_mock_response('AttachToCert')
     fake_app = app_factory()
     fake_cert = uuid4()
     data = _attach_to_cert(fake_app, fake_cert.get_hex())
     eq_(data, {
         'ResultCode': 'Success',
         'ErrorMessage': None,
         'ErrorID': None
     })
     expected_json = app_data(fake_app)
     expected_json['CertID'] = unicode(fake_cert)
     eq_(len(responses.calls), 1)
     eq_(responses.calls[0].request.url,
         urljoin(settings.IARC_V2_SERVICE_ENDPOINT, 'AttachToCert'))
     eq_(json.loads(responses.calls[0].request.body), expected_json)
예제 #54
0
    def setUp(self):
        super(TestRecommendationViewMocked, self).setUp()
        self.url = reverse('api-v2:apps-recommend')

        self.requests_patcher = patch('mkt.recommendations.views.requests')
        self.patched_requests = self.requests_patcher.start()
        self.patched_requests.patcher = self.requests_patcher
        self.addCleanup(self.requests_patcher.stop)

        self.apps = [app_factory() for i in range(2)]
        resp_value = json.dumps({
            'user': self.profile.recommendation_hash,
            'recommendations': [a.pk for a in self.apps],
        })
        self.patched_requests.get.return_value = Response(200, resp_value)
        self.refresh('webapp')
예제 #55
0
    def setUp(self):
        super(TestRecommendationViewMocked, self).setUp()
        self.url = reverse('api-v2:apps-recommend')

        self.requests_patcher = patch('mkt.recommendations.views.requests')
        self.patched_requests = self.requests_patcher.start()
        self.patched_requests.patcher = self.requests_patcher
        self.addCleanup(self.requests_patcher.stop)

        self.apps = [app_factory() for i in range(2)]
        resp_value = json.dumps({
            'user': self.profile.recommendation_hash,
            'recommendations': [a.pk for a in self.apps],
        })
        self.patched_requests.get.return_value = Response(200, resp_value)
        self.refresh('webapp')
예제 #56
0
    def test_with_existing_descriptors_that_should_be_kept(self):
        data = setup_mock_response('GetRatingChanges')
        cert_id = data['CertList'][0]['CertID']
        app = app_factory()
        IARCCert.objects.create(app=app, cert_id=UUID(cert_id))
        RatingDescriptors.objects.create(addon=app, has_classind_violence=True)

        get_rating_changes()

        eq_(UUID(app.iarc_cert.cert_id), UUID(cert_id))
        app = Webapp.objects.get(pk=app.pk)
        # Original descriptor belongs to a rating body that wasn't part of the
        # changes returned by GetRatingChanges for this cert, so it should have
        # been kept.
        self.assertSetEqual(app.rating_descriptors.to_keys(),
                            ['has_classind_violence', 'has_esrb_violence_ref'])
예제 #57
0
 def test_unpublish(self):
     setup_mock_response('UpdateCerts')
     app = app_factory()
     IARCCert.objects.create(
         app=app, cert_id='adb3261bc6574fd2a057bc9f85310b80')
     res = unpublish(app.pk)
     eq_(res['ResultList'][0]['ResultCode'], 'Success')
     eq_(len(responses.calls), 1)
     eq_(responses.calls[0].request.headers.get('StorePassword'),
         settings.IARC_V2_STORE_PASSWORD)
     eq_(responses.calls[0].request.headers.get('StoreID'),
         settings.IARC_V2_STORE_ID)
     eq_(json.loads(responses.calls[0].request.body), {
         'UpdateList': [{
             'Action': 'RemoveProduct',
             'CertID': 'adb3261b-c657-4fd2-a057-bc9f85310b80'
         }]
     })
예제 #58
0
    def test_search_and_attach_cert(self):
        setup_mock_response('AttachToCert')
        setup_mock_response('SearchCerts')

        app = app_factory()
        cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80'
        data = search_and_attach_cert(app, cert_id)
        eq_(data,
            {'ResultCode': 'Success', 'ErrorMessage': None, 'ErrorID': None})
        eq_(UUID(app.iarc_cert.cert_id), UUID(cert_id))
        # Note: the mock also contains PEGI_ParentalGuidanceRecommended but we
        # don't currently map it to a descriptor, because it didn't exist in
        # v1.
        eq_(app.rating_descriptors.to_keys(), ['has_classind_lang'])
        eq_(app.rating_interactives.to_keys(),
            ['has_shares_location', 'has_digital_purchases',
             'has_users_interact'])
        eq_(app.content_ratings.count(), 5)