Navigation Menu

Skip to content

Commit

Permalink
fixes bug 1253396 - Platforms pure implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Mar 3, 2016
1 parent 1c485ce commit 07d8a41
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 38 deletions.
1 change: 0 additions & 1 deletion socorro/middleware/middleware_app.py
Expand Up @@ -55,7 +55,6 @@
(r'/field/(.*)', 'field.Field'),
(r'/gccrashes/(.*)', 'gccrashes.GCCrashes'),
(r'/graphics_devices/(.*)', 'graphics_devices.GraphicsDevices'),
(r'/platforms/(.*)', 'platforms.Platforms'),
(r'/priorityjobs/(.*)', 'priorityjobs.Priorityjobs'),
(r'/products/build_types/(.*)', 'product_build_types.ProductBuildTypes'),
(r'/products/(.*)', 'products.Products'), # deprecated
Expand Down
11 changes: 0 additions & 11 deletions socorro/unittest/middleware/test_middleware_app.py
Expand Up @@ -807,17 +807,6 @@ def test_field(self):
'product': None
})

def test_platforms(self):
config_manager = self._setup_config_manager()

with config_manager.context() as config:
app = middleware_app.MiddlewareApp(config)
app.main()
server = middleware_app.application

response = self.get(server, '/platforms/')
eq_(response.data, {'hits': [], 'total': 0})

def test_priorityjobs(self):
config_manager = self._setup_config_manager()

Expand Down
7 changes: 6 additions & 1 deletion webapp-django/crashstats/crashstats/models.py
Expand Up @@ -19,6 +19,7 @@
from socorro.external.es.base import ElasticsearchConfig
from socorro.external.postgresql.crashstorage import PostgreSQLCrashStorage
from socorro.app import socorro_app
import socorro.external.postgresql.platforms
import socorro.external.postgresql.bugs
import socorro.external.postgresql.products
import socorro.external.postgresql.graphics_report
Expand Down Expand Up @@ -889,14 +890,18 @@ def get(self):

class Platforms(SocorroMiddleware):

URL_PREFIX = '/platforms/'
implementation = socorro.external.postgresql.platforms.Platforms

API_WHITELIST = (
'code',
'name',
)

def get(self):
# XXX (peterbe, Mar 2016): Oh I wish we had stats on how many people
# are using /api/Platforms/. If we knew we could be brave about
# removing this legacy hack.

# When we first exposed this model it would just return a plain
# list. It was hardcoded. To avoid deprecating things for people
# we continue this trandition by only returning the hits directly
Expand Down
13 changes: 6 additions & 7 deletions webapp-django/crashstats/crashstats/tests/test_models.py
Expand Up @@ -1333,13 +1333,11 @@ def mocked_get(url, params, **options):
channel='nightly')
eq_(r['total'], 2)

@mock.patch('requests.get')
def test_platforms(self, rget):
def test_platforms(self):
api = models.Platforms()

def mocked_get(url, **options):
assert '/platforms/' in url
return Response({
def mocked_get(**options):
return {
"hits": [
{
"code": "win",
Expand All @@ -1351,9 +1349,10 @@ def mocked_get(url, **options):
}
],
"total": 2
})
}

models.Platforms.implementation().get.side_effect = mocked_get

rget.side_effect = mocked_get
r = api.get()
eq_(len(r), 2)
assert 'Windows' in settings.DISPLAY_OS_NAMES
Expand Down
41 changes: 23 additions & 18 deletions webapp-django/crashstats/crashstats/tests/test_views.py
Expand Up @@ -318,30 +318,35 @@ def setUp(self, rget):
'The tests requires that you use LocMemCache when running'
)

def mocked_platforms_get(**options):
return {
"hits": [
{
'code': 'win',
'name': 'Windows',
},
{
'code': 'mac',
'name': 'Mac OS X',
},
{
'code': 'lin',
'name': 'Linux',
}
],
"total": 6
}

models.Platforms.implementation().get.side_effect = (
mocked_platforms_get
)

# we do this here so that the current/versions thing
# is cached since that's going to be called later
# in every view more or less
def mocked_get(url, params, **options):
now = datetime.datetime.utcnow()
yesterday = now - datetime.timedelta(days=1)
if '/platforms/' in url:
return Response({
"hits": [
{
'code': 'win',
'name': 'Windows',
},
{
'code': 'mac',
'name': 'Mac OS X',
},
{
'code': 'lin',
'name': 'Linux',
}
],
"total": 6
})
if 'products/' in url:
return Response("""
{"products": [
Expand Down

0 comments on commit 07d8a41

Please sign in to comment.