def test_signup(self, subscribe): res = self.client.post(list_url('newsletter')) eq_(res.status_code, 400) res = self.client.post(list_url('newsletter'), data=json.dumps({'email': '*****@*****.**'})) eq_(res.status_code, 204) subscribe.assert_called_with( '*****@*****.**', 'marketplace', lang='en-US', country='us', trigger_welcome='Y', optin='Y', format='H')
def setUp(self): self.create_switch('search-api-es') self.create_switch('buchets') self.client = OAuthClient(None) self.url = list_url('search') self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name='test', type=amo.ADDON_WEBAPP) # A typical desktop profile on Firefox with the following features: # {'apps': True, # 'audio': True, # 'battery': True, # 'device_storage': True, # 'fullscreen': True, # 'geolocation': True, # 'idle': True, # 'indexeddb': True, # 'light_events': True, # 'network_info': True, # 'orientation': True, # 'proximity': True, # 'push': True, # 'sms': True, # 'vibrate': True, # 'video_webm': True, # 'webaudio': True} self.profile = '8a7dd46c.32.1' self.qs = {'q': 'something', 'pro': self.profile, 'dev': 'firefoxos'}
class TestCategoriesWithCreatured(BaseOAuth, ESTestCase): fixtures = fixture('webapp_337141', 'user_2519') list_url = list_url('search/creatured') def test_creatured_plus_category(self): cat = Category.objects.create(type=amo.ADDON_WEBAPP, slug='shiny') app2 = amo.tests.app_factory() AddonCategory.objects.get_or_create(addon=app2, category=cat) AddonCategory.objects.get_or_create(addon_id=337141, category=cat) self.make_featured(app=app2, category=cat, region=mkt.regions.US) self.refresh() res = self.client.get(self.list_url + ({'cat': 'shiny'}, )) eq_(res.status_code, 200) data = json.loads(res.content) eq_(len(data['objects']), 2) eq_(len(data['creatured']), 1) eq_(int(data['creatured'][0]['id']), app2.pk) def test_no_category(self): cat = Category.objects.create(type=amo.ADDON_WEBAPP, slug='shiny') app = amo.tests.app_factory() AddonCategory.objects.get_or_create(addon=app, category=cat) self.make_featured(app=app, category=cat, region=mkt.regions.US) self.refresh() res = self.client.get(self.list_url) eq_(res.status_code, 200) data = json.loads(res.content) eq_(len(data['objects']), 2) eq_(len(data['creatured']), 0)
def setUp(self): super(TestAccount, self).setUp(api_name='reviewers') self.list_url = list_url('reviewing') self.anon = OAuthClient(None, api_name='reviewers') self.user = UserProfile.objects.get(pk=2519) self.req = RequestFactory().get('/') self.req.amo_user = self.user
def setUp(self): super(TestFeaturedHomeHandler, self).setUp(api_name='home') self.list_url = list_url('featured') self.cat = Category.objects.create(name='awesome', type=amo.ADDON_WEBAPP, slug='awesome') # App, no category, worldwide region. self.app1 = Webapp.objects.create(status=amo.STATUS_PUBLIC, name='App 1') f1 = FeaturedApp.objects.create(app=self.app1, category=None) FeaturedAppRegion.objects.create(featured_app=f1, region=mkt.regions.WORLDWIDE.id) # App, with category, worldwide region. Mostly to ensure category # specific featured apps don't slip into the results. self.app2 = Webapp.objects.create(status=amo.STATUS_PUBLIC, name='App 2') AddonCategory.objects.create(category=self.cat, addon=self.app2) f2 = FeaturedApp.objects.create(app=self.app2, category=self.cat) FeaturedAppRegion.objects.create(featured_app=f2, region=mkt.regions.WORLDWIDE.id) # App, no category, US region. self.app3 = Webapp.objects.create(status=amo.STATUS_PUBLIC, name='App 3') f3 = FeaturedApp.objects.create(app=self.app3) FeaturedAppRegion.objects.create(featured_app=f3, region=mkt.regions.US.id)
def test_delete(self, client): rdel = self.client.delete(get_url('account', self.account.pk)) eq_(rdel.status_code, 204) client.api.bango.package().get.return_value = {"full": payment_data} rget = self.client.get(list_url('account')) eq_(json.loads(rget.content)['objects'], [])
def setUp(self): self.client = OAuthClient(None) self.url = list_url("search") self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name="test", type=amo.ADDON_WEBAPP) self.webapp.save() self.refresh()
def setUp(self): super(TestDevhubAPI, self).setUp(api_name='receipts') self.data = json.dumps({ 'manifest_url': 'http://foo.com', 'receipt_type': 'expired' }) self.url = list_url('test')
def test_add_fail(self, client): err = {'broken': True} client.api.bango.package.post.side_effect = HttpClientError( content=err) r = self.client.post(list_url('account'), data=json.dumps(payment_data)) eq_(r.status_code, 500) eq_(json.loads(r.content), err)
def setUp(self): super(TestGlobalStatsResource, self).setUp('stats') self.list_url = list_url('global') self.get_url = self.get_detail_url('global', STATS.keys()[0]) self.create_switch('stats-api') self.data = {'start': '2013-04-01', 'end': '2013-04-15', 'interval': 'day'}
def setUp(self): self.create_switch('soft_delete') self.client = OAuthClient(None) self.url = list_url('search') self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name='test', slug='test', type=amo.ADDON_WEBAPP) self.webapp.save() self.refresh('webapp')
def setUp(self): super(TestPrices, self).setUp(api_name='webpay') self.price = Price.objects.create(name='1', price=Decimal(1)) self.currency = self.make_currency(3, self.price, 'CAD') self.list_url = list_url('prices') self.get_url = get_url('prices', self.price.pk) # If regions change, this will blow up. assert regions.BR.default_currency == 'BRL'
def setUp(self): self.client = OAuthClient(None) self.url = list_url('search') self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name='test', slug='test', type=amo.ADDON_WEBAPP) self.webapp.save() self.refresh('webapp')
def setUp(self): super(TestGlobalStatsResource, self).setUp('stats') self.list_url = list_url('global') self.get_url = self.get_detail_url('global', STATS.keys()[0]) self.create_switch('stats-api') self.data = { 'start': '2013-04-01', 'end': '2013-04-15', 'interval': 'day' }
def test_add(self, client): r = self.client.post(list_url('account'), data=json.dumps(payment_data)) eq_(r.status_code, 201) pa = PaymentAccount.objects.get(name='account') eq_(pa.user.pk, self.user.pk) d = client.api.bango.package.post.call_args[1]['data'] for k, v in d.iteritems(): if k not in ['paypalEmailAddress', 'seller']: eq_(payment_data[k], v)
def setUp(self): self.create_switch("buchets") self.client = OAuthClient(None) self.url = list_url("search") self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name="test", type=amo.ADDON_WEBAPP) # Pick a few common device features. self.profile = FeatureProfile( apps=True, audio=True, fullscreen=True, geolocation=True, indexeddb=True, sms=True ).to_signature() self.qs = {"q": "something", "pro": self.profile, "dev": "firefoxos"}
def setUp(self): super(TestProductIconResource, self).setUp(api_name='webpay') self.list_url = list_url('product/icon') p = patch('mkt.webpay.resources.tasks.fetch_product_icon') self.fetch_product_icon = p.start() self.addCleanup(p.stop) self.data = { 'ext_size': 128, 'ext_url': 'http://someappnoreally.com/icons/icon_128.png', 'size': 64 }
def setUp(self): self.client = OAuthClient(None) self.url = list_url('search') self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name='test', type=amo.ADDON_WEBAPP) # Pick a few common device features. self.profile = FeatureProfile(apps=True, audio=True, fullscreen=True, geolocation=True, indexeddb=True, sms=True).to_signature() self.qs = {'q': 'something', 'pro': self.profile, 'dev': 'firefoxos'}
def setUp(self): self.create_switch('buchets') self.client = OAuthClient(None) self.url = list_url('search') self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name='test', type=amo.ADDON_WEBAPP) # Pick a few common device features. self.profile = FeatureProfile(apps=True, audio=True, fullscreen=True, geolocation=True, indexeddb=True, sms=True).to_signature() self.qs = {'q': 'something', 'pro': self.profile, 'dev': 'firefoxos'}
def test_get_list(self, client): client.api.bango.package().get.return_value = {"full": payment_data} app2 = app_factory(premium_type=amo.ADDON_FREE_INAPP) AddonUser.objects.create(addon=app2, user=self.other) setup_payment_account(app2, self.other) r = self.client.get(list_url('account')) eq_(r.status_code, 200) data = json.loads(r.content) pkg = package_data.copy() pkg['resource_uri'] = '/api/v1/payments/account/%s/' % self.account.pk eq_(data['objects'], [pkg])
def setUp(self, api_name="apps"): self.user = User.objects.get(pk=2519) self.profile = self.user.get_profile() self.profile.update(read_dev_agreement=datetime.now()) self.grant_permission(self.profile, "Apps:Review") self.access = Access.objects.create(key="foo", secret=generate(), user=self.user) self.client = OAuthClient(self.access, api_name=api_name) self.url = list_url("search") self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name="test", type=amo.ADDON_WEBAPP) self.webapp.save() self.refresh()
def setUp(self): super(TestFeedbackHandler, self).setUp(api_name='account') self.list_url = list_url('feedback') self.user = UserProfile.objects.get(pk=2519) self.default_data = { 'chromeless': 'no', 'feedback': 'Here is what I really think.', 'platform': 'Desktop', 'from_url': '/feedback', 'sprout': 'potato' } self.headers = { 'HTTP_USER_AGENT': 'Fiiia-fox', 'REMOTE_ADDR': '48.151.623.42' }
def _create(self, data=None): default_data = { 'app': self.app.id, 'body': 'Rocking the free web.', 'rating': 5 } if data: default_data.update(data) json_data = json.dumps(default_data) res = self.client.post(list_url('rating'), data=json_data) try: res_data = json.loads(res.content) except ValueError: res_data = res.content return res, res_data
def setUp(self, api_name="reviewers"): super(TestApiReviewer, self).setUp(api_name=api_name) self.user = User.objects.get(pk=2519) self.profile = self.user.get_profile() self.profile.update(read_dev_agreement=datetime.now()) self.grant_permission(self.profile, "Apps:Review") self.access = Access.objects.create(key="test_oauth_key", secret=generate(), user=self.user) self.client = OAuthClient(self.access, api_name=api_name) self.url = list_url("search") self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name="test", type=amo.ADDON_WEBAPP) self.webapp.update(status=amo.STATUS_PENDING) self.refresh("webapp")
def _create(self, data=None, anonymous=False): default_data = { 'app': self.app.id, 'body': 'Rocking the free web.', 'rating': 5 } if data: default_data.update(data) json_data = json.dumps(default_data) client = self.anon if anonymous else self.client res = client.post(list_url('rating'), data=json_data) try: res_data = json.loads(res.content) except ValueError: res_data = res.content return res, res_data
def setUp(self, api_name='apps'): self.create_switch('search-api-es') self.user = User.objects.get(pk=2519) self.profile = self.user.get_profile() self.profile.update(read_dev_agreement=datetime.now()) self.grant_permission(self.profile, 'Apps:Review') self.access = Access.objects.create( key='test_oauth_key', secret=generate(), user=self.user) self.client = OAuthClient(self.access, api_name=api_name) self.url = list_url('search') self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name='test', type=amo.ADDON_WEBAPP) self.webapp.save() self.refresh('webapp')
def _create(self, data=None, anonymous=False): default_data = { 'app': self.app.id, 'body': 'Rocking the free web.', 'rating': 5, 'version': self.app.latest_version.id } if data: default_data.update(data) json_data = json.dumps(default_data) client = self.anon if anonymous else self.client res = client.post(list_url('rating'), data=json_data) try: res_data = json.loads(res.content) except ValueError: res_data = res.content return res, res_data
def setUp(self, api_name='reviewers'): super(TestApiReviewer, self).setUp(api_name=api_name) self.user = User.objects.get(pk=2519) self.profile = self.user.get_profile() self.profile.update(read_dev_agreement=datetime.now()) self.grant_permission(self.profile, 'Apps:Review') self.access = Access.objects.create( key='test_oauth_key', secret=generate(), user=self.user) self.client = OAuthClient(self.access, api_name=api_name) self.url = list_url('search') self.webapp = Webapp.objects.get(pk=337141) self.category = Category.objects.create(name='test', type=amo.ADDON_WEBAPP) self.webapp.update(status=amo.STATUS_PENDING) self.refresh('webapp')
class BaseFeaturedTests(BaseOAuth, ESTestCase): fixtures = fixture('user_2519', 'webapp_337141') list_url = list_url('search/featured') def setUp(self, api_name=None): super(BaseFeaturedTests, self).setUp(api_name='fireplace') self.cat = Category.objects.create(type=amo.ADDON_WEBAPP, slug='shiny') self.app = Webapp.objects.get(pk=337141) AddonDeviceType.objects.create( addon=self.app, device_type=DEVICE_CHOICES_IDS['firefoxos']) AddonCategory.objects.get_or_create(addon=self.app, category=self.cat) self.profile = FeatureProfile(apps=True, audio=True, fullscreen=True, geolocation=True, indexeddb=True, sms=True).to_signature() self.qs = {'cat': 'shiny', 'pro': self.profile, 'dev': 'firefoxos'}
def test_anonymous_get_list(self): res = self.anon.get(list_url('rating')) data = json.loads(res.content) eq_(res.status_code, 200) assert 'user' not in data
def setUp(self): self.url = list_url('suggest') self.refresh('webapp') self.client = OAuthClient(None)
def test_carriers_list(self): res = self.client.get(list_url('carrier')) data = json.loads(res.content) eq_(set(r['slug'] for r in data['objects']), set(r.slug for r in carriers.CARRIERS))
def test_others(self): url = get_absolute_url(list_url('app'), api_name='fireplace') self._allowed_verbs(self.url, ['get']) self._allowed_verbs(url, [])
def setUp(self): super(TestLoginHandler, self).setUp() self.list_url = get_absolute_url(list_url('login'), api_name='account')
def setUp(self): super(TestInstalled, self).setUp(api_name='account') self.list_url = list_url('installed/mine') self.user = UserProfile.objects.get(pk=2519)
def setUp(self): super(TestAccount, self).setUp(api_name='account') self.list_url = list_url('settings') self.get_url = get_url('settings', '2519') self.user = UserProfile.objects.get(pk=2519)
def test_regions_list(self): res = self.client.get(list_url('region')) data = json.loads(res.content) eq_(set(r['slug'] for r in data['objects']), set(r.slug for r in regions.ALL_REGIONS))
def test_filter_not_mine(self): res = self.anon.get(list_url('rating') + ({'user': '******'},)) eq_(res.status_code, 401)
def _get_filter(self, client, key): Review.objects.create(addon=self.app, user=self.user, body='yes') res = client.get(list_url('rating') + ({'user': key},)) eq_(res.status_code, 200) eq_(json.loads(res.content)['meta']['total_count'], 1)
def test_add_fail2(self, client): client.api.bango.package.post.side_effect = HttpServerError() r = self.client.post(list_url('account'), data=json.dumps(payment_data)) eq_(r.status_code, 500)
def _get_filter(self, client, key): Review.objects.create(addon=self.app, user=self.user, body='yes') res = client.get(list_url('rating') + ({'user': key}, )) eq_(res.status_code, 200) eq_(json.loads(res.content)['meta']['total_count'], 1)
def setUp(self): super(TestDevhubAPI, self).setUp(api_name='receipts') self.data = json.dumps({'manifest_url': 'http://foo.com', 'receipt_type': 'expired'}) self.url = list_url('test')
def test_filter_not_mine(self): res = self.anon.get(list_url('rating') + ({'user': '******'}, )) eq_(res.status_code, 401)
class TestFeaturedNoCategories(BaseOAuth, ESTestCase): fixtures = fixture('user_2519', 'webapp_337141') list_url = list_url('search/featured') def setUp(self): super(TestFeaturedNoCategories, self).setUp(api_name='fireplace') self.create_switch('buchets') self.cat = Category.objects.create(type=amo.ADDON_WEBAPP, slug='shiny') self.app = Webapp.objects.get(pk=337141) AddonCategory.objects.get_or_create(addon=self.app, category=self.cat) self.make_featured(app=self.app, category=None, region=mkt.regions.US) self.profile = FeatureProfile(apps=True, audio=True, fullscreen=True, geolocation=True, indexeddb=True, sms=True).to_signature() self.qs = {'pro': self.profile, 'dev': 'firefoxos'} def test_no_category(self): app2 = app_factory() self.make_featured(app=app2, category=self.cat) self.reindex(Webapp, 'webapp') res = self.client.get(self.list_url + (self.qs, )) eq_(res.status_code, 200) eq_(len(res.json['featured']), 1) eq_(int(res.json['featured'][0]['id']), self.app.pk) unindex_webapps([app2.id]) app2.delete() def test_one_good_feature_no_category(self): """Enable an app feature that matches one in our profile.""" self.app.current_version.features.update(has_geolocation=True) self.reindex(Webapp, 'webapp') res = self.client.get(self.list_url + (self.qs, )) eq_(res.status_code, 200) eq_(len(res.json['featured']), 1) eq_(int(res.json['featured'][0]['id']), self.app.pk) def test_one_bad_feature_no_category(self): """Enable an app feature that doesn't match one in our profile.""" self.app.current_version.features.update(has_pay=True) self.reindex(Webapp, 'webapp') res = self.client.get(self.list_url + (self.qs, )) eq_(res.status_code, 200) eq_(len(res.json['featured']), 0) def test_all_good_features_no_category(self): """Enable app features so they exactly match our device profile.""" fp = FeatureProfile.from_signature(self.profile) self.app.current_version.features.update(**dict( ('has_%s' % k, v) for k, v in fp.items())) self.reindex(Webapp, 'webapp') res = self.client.get(self.list_url + (self.qs, )) eq_(res.status_code, 200) eq_(len(res.json['featured']), 1) eq_(int(res.json['featured'][0]['id']), self.app.pk) def test_non_matching_profile_desktop_no_category(self): """Enable unmatched feature but desktop should find it.""" self.app.current_version.features.update(has_pay=True) self.reindex(Webapp, 'webapp') self.qs.update({'dev': ''}) res = self.client.get(self.list_url + (self.qs, )) eq_(res.status_code, 200) eq_(len(res.json['featured']), 1) eq_(int(res.json['featured'][0]['id']), self.app.pk)
def setUp(self): super(TestAPI, self).setUp(api_name='receipts') self.addon = Addon.objects.get(pk=337141) self.url = list_url('install') self.data = json.dumps({'app': self.addon.pk}) self.profile = self.user.get_profile()