Skip to content

Commit

Permalink
Fixes bug 1325069 - Removed CrashesPerAdu model from public API. (moz…
Browse files Browse the repository at this point in the history
  • Loading branch information
adngdb authored Jan 25, 2017
1 parent ec25bb8 commit 54ad313
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 359 deletions.
174 changes: 0 additions & 174 deletions webapp-django/crashstats/api/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import re

from django.contrib.auth.models import User, Permission
from django.core.urlresolvers import reverse
Expand Down Expand Up @@ -99,58 +98,6 @@ def test_base_classes_raise_not_found(self):
response = self.client.get(url)
eq_(response.status_code, 404)

@mock.patch('requests.get')
def test_CrashesPerAdu(self, rget):
def mocked_get(url, params, **options):
if 'crashes/daily' in url:
return Response({
"hits": {
"WaterWolf:19.0": {
"2012-10-08": {
"product": "WaterWolf",
"adu": 30000,
"crash_hadu": 71.099999999999994,
"version": "19.0",
"report_count": 2133,
"date": "2012-10-08"
},
"2012-10-02": {
"product": "WaterWolf",
"adu": 30000,
"crash_hadu": 77.299999999999997,
"version": "19.0",
"report_count": 2319,
"date": "2012-10-02"
},
},
},
})

raise NotImplementedError(url)

rget.side_effect = mocked_get

url = reverse('api:model_wrapper', args=('CrashesPerAdu',))
response = self.client.get(url, {
'product': 'WaterWolf',
'versions': ['10.0', '11.1'],
})
eq_(response.status_code, 200)
eq_(response['Content-Type'], 'application/json; charset=UTF-8')
dump = json.loads(response.content)
ok_(dump['hits'])

# miss one of the required fields
response = self.client.get(url, {
# note! no 'product'
'versions': ['10.0', '11.1'],
})
eq_(response.status_code, 400)
eq_(response['Content-Type'], 'application/json; charset=UTF-8')
dump = json.loads(response.content)
ok_(dump['errors']['product'])
ok_('versions' not in dump['errors'])

def test_CORS(self):
"""any use of model_wrapper should return a CORS header"""

Expand Down Expand Up @@ -193,127 +140,6 @@ def mocked_get(**options):
cache_seconds = ProductBuildTypes.cache_seconds
ok_('max-age={}'.format(cache_seconds) in response['Cache-Control'])

@mock.patch('requests.get')
def test_CrashesPerAdu_too_much(self, rget):
def mocked_get(url, params, **options):
if 'crashes/daily' in url:
return Response({
"hits": {
"WaterWolf:19.0": {
"2012-10-08": {
"product": "WaterWolf",
"adu": 30000,
"crash_hadu": 71.099999999999994,
"version": "19.0",
"report_count": 2133,
"date": "2012-10-08"
},
"2012-10-02": {
"product": "WaterWolf",
"adu": 30000,
"crash_hadu": 77.299999999999997,
"version": "19.0",
"report_count": 2319,
"date": "2012-10-02"
}
}
}
})

raise NotImplementedError(url)

rget.side_effect = mocked_get
url = reverse('api:model_wrapper', args=('CrashesPerAdu',))
response = self.client.get(url, {
'product': 'WaterWolf',
'versions': ['10.0', '11.1'],
})
eq_(response.status_code, 200)
eq_(response['Content-Type'], 'application/json; charset=UTF-8')
for i in range(5):
response = self.client.get(url, {
'product': 'WaterWolf',
'versions': ['10.0', '11.1'],
})
# should still be ok
eq_(response.status_code, 200)

rate_limit = settings.API_RATE_LIMIT
rate_limit_times = int(re.findall('\d+', rate_limit)[0])
# double to avoid https://bugzilla.mozilla.org/show_bug.cgi?id=1148470
for i in range(rate_limit_times * 2):
response = self.client.get(url, {
'product': 'WaterWolf',
'versions': ['10.0', '11.1'],
})
eq_(response.status_code, 429)
eq_(response.content, 'Too Many Requests')

@mock.patch('requests.get')
def test_CrashesPerAdu_different_date_parameters(self, rget):
def mocked_get(url, params, **options):
if 'crashes/daily' in url:
# note that the test below sends in a string as
# '2012-1-1' which is valid but lacks the leading
# zeros. Because the date is converted to a datetime.date
# object and serialized back we'll get it here in this
# full format.
ok_('from_date' in params)
eq_('2012-01-01', params['from_date'])
return Response({
"hits": {
"WaterWolf:19.0": {
"2012-10-08": {
"product": "WaterWolf",
"adu": 30000,
"crash_hadu": 71.099999999999994,
"version": "19.0",
"report_count": 2133,
"date": "2012-10-08"
},
"2012-10-02": {
"product": "WaterWolf",
"adu": 30000,
"crash_hadu": 77.299999999999997,
"version": "19.0",
"report_count": 2319,
"date": "2012-10-02"
},
},
},
})

raise NotImplementedError(url)

rget.side_effect = mocked_get

url = reverse('api:model_wrapper', args=('CrashesPerAdu',))
response = self.client.get(url, {
'product': 'WaterWolf',
'versions': ['10.0', '11.1'],
'from_date': '2012-01-xx', # invalid format
})
eq_(response.status_code, 400)
eq_(response['Content-Type'], 'application/json; charset=UTF-8')
dump = json.loads(response.content)
ok_(dump['errors']['from_date'])

response = self.client.get(url, {
'product': 'WaterWolf',
'versions': ['10.0', '11.1'],
'from_date': '2012-02-32', # invalid numbers
})
eq_(response.status_code, 400)
dump = json.loads(response.content)
ok_(dump['errors']['from_date'])

response = self.client.get(url, {
'product': 'WaterWolf',
'versions': ['10.0', '11.1'],
'from_date': '2012-1-1',
})
eq_(response.status_code, 200)

def test_ProductVersions(self):

def mocked_get(*args, **k):
Expand Down
37 changes: 0 additions & 37 deletions webapp-django/crashstats/crashstats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from django.template.defaultfilters import slugify

from crashstats import scrubber
from crashstats.api.cleaner import Cleaner


DEPRECATION_RAMPAGE_WARNING = (
Expand Down Expand Up @@ -732,42 +731,6 @@ def get_all(self):
return super(Platforms, self).get()


class CrashesPerAdu(SocorroMiddleware):
# Fetch records for active daily installs.

deprecation_warning = DEPRECATION_RAMPAGE_WARNING

URL_PREFIX = '/crashes/daily/'

required_params = (
'product',
('versions', list),
)

possible_params = (
('from_date', datetime.date),
('to_date', datetime.date),
'date_range_type',
'os',
'report_type',
)

API_WHITELIST = {
'hits': {
Cleaner.ANY: {
Cleaner.ANY: (
'adu',
'date',
'crash_hadu',
'product',
'report_count',
'version',
)
}
}
}


class ProcessedCrash(SocorroMiddleware):

implementation = socorro.external.boto.crash_data.SimplifiedCrashData
Expand Down
Loading

0 comments on commit 54ad313

Please sign in to comment.