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])
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)
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)
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)
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' })
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)
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
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)
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)
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)
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)
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
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)
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')
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)
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
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])
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')
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")
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)
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])
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])
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"], [])
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'], [])
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'], [])
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)
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}))
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)})
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
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)})
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)
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)
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
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}))
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
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
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)})
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)
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)})
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)
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)
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')
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'])
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' }] })
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)