Skip to content

Commit

Permalink
Merge pull request #1853 from rhelmer/bug915317-gccrashes-model
Browse files Browse the repository at this point in the history
bug 915317 - gccrashes model
  • Loading branch information
rhelmer committed Feb 4, 2014
2 parents d4f1c69 + d6adfb2 commit 97608fb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
21 changes: 21 additions & 0 deletions webapp-django/crashstats/crashstats/models.py
Expand Up @@ -1414,3 +1414,24 @@ class LagLog(SocorroMiddleware):

# never anything sensitive
API_WHITELIST = None


class GCCrashes(SocorroMiddleware):

cache_seconds = 60

URL_PREFIX = '/gccrashes/'
required_params = (
('product', unicode),
('version', unicode),
)

possible_params = (
('from_date', datetime.date),
('to_date', datetime.date),
)

API_WHITELIST = (
'hits',
'total',
)
21 changes: 14 additions & 7 deletions webapp-django/crashstats/crashstats/tests/test_views.py
Expand Up @@ -691,14 +691,24 @@ def mocked_get(**options):

@mock.patch('requests.get')
def test_gccrashes_json(self, rget):
url = reverse('crashstats.gccrashes_json')
url = reverse(
'crashstats.gccrashes_json',
kwargs={'product': 'WaterWolf',
'versions': '20.0',
'start_date': '2014-01-27',
'end_date': '2014-02-04'}
)

def mocked_get(url, **options):
ok_('/product/WaterWolf/' in url)
if 'gccrashes/' in url:
return Response("""
{
"gccrashes": "",
"hits": [
[
"20140203000001",
366
]
],
"total": 1
}
""")
Expand All @@ -707,10 +717,7 @@ def mocked_get(url, **options):

rget.side_effect = mocked_get

response = self.client.get(url, {
'product': 'WaterWolf',
'version': '20.0'
})
response = self.client.get(url)

ok_(response.status_code, 200)
ok_('application/json' in response['content-type'])
Expand Down
5 changes: 4 additions & 1 deletion webapp-django/crashstats/crashstats/urls.py
Expand Up @@ -7,6 +7,8 @@
products = r'/products/(?P<product>\w+)'
versions = r'/versions/(?P<versions>[;\w\.()]+)'
crash_type = r'/crash_type/(?P<crash_type>\w+)'
start_date = r'/start_date/(?P<start_date>[0-9]{4}-[0-9]{2}-[0-9]{2})'
end_date = r'/end_date/(?P<end_date>[0-9]{4}-[0-9]{2}-[0-9]{2})'
date_range_type = r'/date_range_type/(?P<date_range_type>\w+)'
# putting a * on the following regex so we allow URLs to be things like
# `.../os_name/` without any default value which the view function will
Expand Down Expand Up @@ -194,7 +196,8 @@
url(r'^gccrashes' + products + versions + '$',
views.gccrashes,
name='crashstats.gccrashes'),
url(r'^gccrashes/json_data$',
url(r'^gccrashes/json_data' + products + versions + start_date +
end_date + '$',
views.gccrashes_json,
name='crashstats.gccrashes_json'),
url(r'^login/$',
Expand Down
16 changes: 10 additions & 6 deletions webapp-django/crashstats/crashstats/views.py
Expand Up @@ -2098,13 +2098,17 @@ def gccrashes(request, product, versions=None, default_context=None):

@utils.json_view
@pass_default_context
def gccrashes_json(request, default_context=None):
json_response = {
'gccrashes': '',
'total': 1
}
def gccrashes_json(request, product, versions, start_date, end_date,
default_context=None):
api = models.GCCrashes()
result = api.get(
product=product,
version=versions,
from_date=start_date,
to=end_date,
)

return json_response
return result


@pass_default_context
Expand Down

0 comments on commit 97608fb

Please sign in to comment.