Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit 815a3e1

Browse files
author
Andy McKay
committed
add in fireplace endpoint that is almost identical to apps, once client is updated we can move stuff over (bug 875547)
1 parent 35cce54 commit 815a3e1

File tree

11 files changed

+106
-18
lines changed

11 files changed

+106
-18
lines changed

docs/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This documentation covers interacting with the `Firefox Marketplace`_.
2121
topics/apps.rst
2222
topics/comm.rst
2323
topics/export.rst
24+
topics/fireplace.rst
2425
topics/payment.rst
2526
topics/ratings.rst
2627
topics/reviewers.rst

docs/api/topics/fireplace.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. _fireplace:
2+
3+
=========
4+
Fireplace
5+
=========
6+
7+
Fireplace is the consumer client for the Marketplace. It has some special
8+
API's. These are *not recommended* for consumption by other clients and can
9+
change in conjunction with the Fireplace client.
10+
11+
.. http:get:: /api/v1/fireplace/app/
12+
13+
A copy of :ref:`the app API <app-response-label>`.

mkt/api/tests/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
from amo.tests import TestCase
3+
4+
5+
class BaseAPI(TestCase):
6+
"""
7+
A base test case useful for API testing.
8+
"""
9+
10+
def _allowed_verbs(self, url, allowed):
11+
"""
12+
Will run through all the verbs except the ones specified in allowed
13+
and ensure that hitting those produces a 405. Otherwise the test will
14+
fail.
15+
"""
16+
verbs = ['get', 'post', 'put', 'patch', 'delete']
17+
for verb in verbs:
18+
if verb in allowed:
19+
continue
20+
try:
21+
res = getattr(self.client, verb)(url)
22+
except AttributeError:
23+
# Not all clients have patch.
24+
if verb != 'patch':
25+
raise
26+
assert res.status_code in (401, 405), (
27+
'%s: %s not 401 or 405' % (verb.upper(), res.status_code))
28+
29+
def get_error(self, response):
30+
return json.loads(response.content)['error_message']
31+

mkt/api/tests/nose.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tests=mkt.abuse.tests.test_resources,
1515
mkt.api.tests.test_throttle,
1616
mkt.developers.tests.test_api,
1717
mkt.developers.tests.test_api_payments,
18+
mkt.fireplace.tests.test_api,
1819
mkt.ratings.tests.test_resources,
1920
mkt.receipts.tests.test_api,
2021
mkt.regions.tests.test_api,

mkt/api/tests/test_oauth.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from mkt.api import authentication
2121
from mkt.api.base import CORSResource, MarketplaceResource
2222
from mkt.api.models import Access, Token, generate, REQUEST_TOKEN, ACCESS_TOKEN
23+
from mkt.api.tests import BaseAPI
2324
from mkt.site.fixtures import fixture
2425

2526

@@ -126,7 +127,7 @@ def patch(self, url, data='', **kw):
126127
return response
127128

128129

129-
class BaseOAuth(TestCase):
130+
class BaseOAuth(BaseAPI):
130131
fixtures = fixture('user_2519', 'group_admin', 'group_editor',
131132
'group_support')
132133

@@ -140,23 +141,6 @@ def setUp(self, api_name='apps'):
140141
self.client = OAuthClient(self.access, api_name=api_name)
141142
self.anon = OAuthClient(None, api_name=api_name)
142143

143-
def _allowed_verbs(self, url, allowed):
144-
"""
145-
Will run through all the verbs except the ones specified in allowed
146-
and ensure that hitting those produces a 405. Otherwise the test will
147-
fail.
148-
"""
149-
verbs = ['get', 'post', 'put', 'patch', 'delete']
150-
for verb in verbs:
151-
if verb in allowed:
152-
continue
153-
res = getattr(self.client, verb)(url)
154-
assert res.status_code in (401, 405), (
155-
'%s: %s not 401 or 405' % (verb.upper(), res.status_code))
156-
157-
def get_error(self, response):
158-
return json.loads(response.content)['error_message']
159-
160144

161145
class RestOAuthClient(OAuthClient):
162146

mkt/fireplace/__init__.py

Whitespace-only changes.

mkt/fireplace/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from mkt.api.resources import AppResource as BaseAppResource
2+
3+
4+
class AppResource(BaseAppResource):
5+
6+
class Meta(BaseAppResource.Meta):
7+
list_allowed_methods = []
8+
detail_allowed_methods = ['get']

mkt/fireplace/tests/__init__.py

Whitespace-only changes.

mkt/fireplace/tests/test_api.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import json
2+
3+
from nose.tools import eq_
4+
5+
from mkt.api.base import get_url, list_url
6+
from mkt.api.tests import BaseAPI
7+
from mkt.api.tests.test_oauth import get_absolute_url
8+
from mkt.webapps.models import Webapp
9+
from mkt.site.fixtures import fixture
10+
11+
12+
class TestAppDetail(BaseAPI):
13+
fixtures = fixture('webapp_337141')
14+
15+
def setUp(self):
16+
super(TestAppDetail, self).setUp()
17+
self.url = get_absolute_url(get_url('app', pk=337141),
18+
api_name='fireplace')
19+
20+
def test_get(self):
21+
res = self.client.get(self.url)
22+
data = json.loads(res.content)
23+
eq_(data['id'], '337141')
24+
25+
def test_get_slug(self):
26+
Webapp.objects.get(pk=337141).update(app_slug='foo')
27+
res = self.client.get(get_absolute_url(('api_dispatch_detail',
28+
{'resource_name': 'app', 'app_slug': 'foo'}),
29+
api_name='fireplace'))
30+
data = json.loads(res.content)
31+
eq_(data['id'], '337141')
32+
33+
def test_others(self):
34+
print self.url
35+
url = get_absolute_url(list_url('app'), api_name='fireplace')
36+
print url
37+
self._allowed_verbs(self.url, ['get'])
38+
self._allowed_verbs(url, [])

mkt/fireplace/urls.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.conf.urls import include, patterns, url
2+
3+
from tastypie.api import Api
4+
from mkt.fireplace.api import AppResource
5+
6+
fireplace = Api(api_name='fireplace')
7+
fireplace.register(AppResource())
8+
9+
urlpatterns = patterns('',
10+
url(r'', include(fireplace.urls)),
11+
)

0 commit comments

Comments
 (0)