diff --git a/socorro/external/postgresql/crashes.py b/socorro/external/postgresql/crashes.py deleted file mode 100644 index 286d5749e9..0000000000 --- a/socorro/external/postgresql/crashes.py +++ /dev/null @@ -1,74 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -import datetime -import logging - -from socorro.lib import ( - MissingArgumentError, - BadArgumentError, - datetimeutil, - external_common, -) -from socorro.external.postgresql.base import PostgreSQLBase - - -logger = logging.getLogger("webapi") - - -class AduBySignature(PostgreSQLBase): - - def get(self, **kwargs): - """Return a list of ADUs and crash counts by signature and ADU date - """ - now = datetimeutil.utc_now().date() - lastweek = now - datetime.timedelta(weeks=1) - - filters = [ - ("start_date", lastweek, "date"), - ("end_date", now, "date"), - ("signature", None, "str"), - ("channel", None, "str"), - ("product_name", None, "str"), - ] - - params = external_common.parse_arguments(filters, kwargs) - - for param in ("start_date", "end_date", "signature", "channel"): - if not params[param]: - raise MissingArgumentError(param) - - if params.end_date - params.start_date > datetime.timedelta(days=365): - raise BadArgumentError('Duration too long. Max 365 days.') - - sql_query = """ - SELECT - product_name, - signature, - adu_date::TEXT, - build_date::TEXT, - buildid::TEXT, - crash_count, - adu_count, - os_name, - channel - FROM crash_adu_by_build_signature - WHERE adu_date BETWEEN %(start_date)s AND %(end_date)s - AND product_name = %(product_name)s - AND channel = %(channel)s - AND signature = %(signature)s - ORDER BY buildid - """ - - error_message = ( - "Failed to retrieve crash ADU by build signature from PostgreSQL" - ) - results = self.query(sql_query, params, error_message=error_message) - - crashes = results.zipped() - - return { - "hits": crashes, - "total": len(crashes) - } diff --git a/socorro/unittest/external/postgresql/test_crashes.py b/socorro/unittest/external/postgresql/test_crashes.py deleted file mode 100644 index 2101af3c0c..0000000000 --- a/socorro/unittest/external/postgresql/test_crashes.py +++ /dev/null @@ -1,120 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -import datetime -from nose.tools import eq_, assert_raises - -from socorro.lib import ( - BadArgumentError, - datetimeutil, -) -from socorro.external.postgresql.crashes import AduBySignature - -from unittestbase import PostgreSQLTestCase - - -class IntegrationTestCrashes(PostgreSQLTestCase): - """Test socorro.external.postgresql.crashes.Crashes class. """ - - @classmethod - def setUpClass(cls): - """Set up this test class by populating the reports table with fake - data. """ - super(IntegrationTestCrashes, cls).setUpClass() - - cursor = cls.connection.cursor() - - cls.now = datetimeutil.utc_now() - yesterday = cls.now - datetime.timedelta(days=1) - - cursor.execute(""" - INSERT INTO crash_adu_by_build_signature - (signature_id, signature, adu_date, build_date, buildid, - crash_count, adu_count, os_name, channel, product_name) - VALUES - (1, 'canIhaveYourSignature()', '{yesterday}', '2014-03-01', - '201403010101', 3, 1023, 'Mac OS X', 'release', 'WaterWolf'), - (1, 'canIhaveYourSignature()', '{yesterday}', '2014-04-01', - '201404010101', 4, 1024, 'Windows NT', 'release', 'WaterWolf'), - (1, 'canIhaveYourSignature()', '2014-01-01', '2014-04-01', - '201404010101', 4, 1024, 'Windows NT', 'release', 'WaterWolf'), - (2, 'youMayNotHaveMySignature()', '{yesterday}', '2014-04-01', - '201404010101', 4, 1024, 'Windows NT', 'release', 'WaterWolf'), - (2, 'youMayNotHaveMySignature()', '{yesterday}', '2014-04-01', - '201404010101', 4, 1024, 'Windows NT', 'release', 'WaterWolf') - """.format(yesterday=yesterday)) - - cls.connection.commit() - cursor.close() - - @classmethod - def tearDownClass(cls): - """Clean up the database, delete tables and functions. """ - cursor = cls.connection.cursor() - cursor.execute(""" - TRUNCATE reports, home_page_graph_build, home_page_graph, - crashes_by_user, crashes_by_user_build, crash_types, - process_types, os_names, signatures, - product_versions, product_release_channels, - release_channels, products, - reports_clean, crash_adu_by_build_signature - CASCADE - """) - cls.connection.commit() - cursor.close() - super(IntegrationTestCrashes, cls).tearDownClass() - - def test_get_adu_by_signature(self): - adu_by_signature = AduBySignature(config=self.config) - - signature = "canIhaveYourSignature()" - channel = "release" - yesterday_date = (self.now - datetime.timedelta(days=1)).date() - yesterday = datetimeutil.date_to_string(yesterday_date) - - res_expected = { - "hits": [ - { - "product_name": "WaterWolf", - "signature": signature, - "adu_date": yesterday, - "build_date": "2014-03-01", - "buildid": '201403010101', - "crash_count": 3, - "adu_count": 1023, - "os_name": "Mac OS X", - "channel": channel, - }, - { - "product_name": "WaterWolf", - "signature": signature, - "adu_date": yesterday, - "build_date": "2014-04-01", - "buildid": '201404010101', - "crash_count": 4, - "adu_count": 1024, - "os_name": "Windows NT", - "channel": channel, - }, - ], - "total": 2, - } - - res = adu_by_signature.get( - product_name="WaterWolf", - start_date=yesterday, - end_date=yesterday, - signature=signature, - channel=channel, - ) - eq_(res, res_expected) - - assert_raises( - BadArgumentError, - adu_by_signature.get, - start_date=(yesterday_date - datetime.timedelta(days=366)), - end_date=yesterday, - signature=signature, - channel=channel - ) diff --git a/webapp-django/crashstats/crashstats/models.py b/webapp-django/crashstats/crashstats/models.py index 5043bd8f84..2645cb6528 100644 --- a/webapp-django/crashstats/crashstats/models.py +++ b/webapp-django/crashstats/crashstats/models.py @@ -19,7 +19,6 @@ ) import socorro.external.postgresql.platforms import socorro.external.postgresql.bugs -import socorro.external.postgresql.crashes import socorro.external.postgresql.products import socorro.external.postgresql.graphics_devices import socorro.external.postgresql.crontabber_state @@ -1078,32 +1077,6 @@ def get_pairs(self, adapter_hexes, vendor_hexes): return names -class AduBySignature(SocorroMiddleware): - - implementation = socorro.external.postgresql.crashes.AduBySignature - - deprecation_warning = ( - 'This endpoint is deprecated and will soon cease to exist.\n' - 'Please see https://bugzilla.mozilla.org/show_bug.cgi?id=1380761' - ) - - required_params = ( - 'product_name', - 'signature', - 'channel', - ) - - possible_params = ( - ('start_date', datetime.date), - ('end_date', datetime.date), - ) - - API_WHITELIST = ( - 'hits', - 'total', - ) - - class ADI(SocorroMiddleware): implementation = socorro.external.postgresql.adi.ADI diff --git a/webapp-django/crashstats/crashstats/tests/test_models.py b/webapp-django/crashstats/crashstats/tests/test_models.py index bbb0335a1b..220fbc7fcd 100644 --- a/webapp-django/crashstats/crashstats/tests/test_models.py +++ b/webapp-django/crashstats/crashstats/tests/test_models.py @@ -395,55 +395,6 @@ def mocked_post(**params): }) eq_(r, True) - @mock.patch('requests.get') - def test_adu_by_signature(self, rget): - model = models.AduBySignature - api = model() - - def mocked_get(**options): - ok_('product_name' in options) - eq_(options['product_name'], 'WaterWolf') - - ok_('signature' in options) - eq_(options['signature'], 'FakeSignature1') - - ok_('channel' in options) - eq_(options['channel'], 'nightly') - - return { - 'hits': [ - { - 'build_date': '2014-04-01', - 'os_name': 'Windows', - 'buildid': '20140401000000', - 'adu_count': 1, - 'crash_count': 1, - 'adu_date': '2014-04-01', - 'signature': 'FakeSignature1', - 'channel': 'nightly'}, - { - 'build_date': '2014-04-01', - 'os_name': 'Windows', - 'buildid': '20140401000001', - 'adu_count': 2, - 'crash_count': 2, - 'adu_date': '2014-04-01', - 'signature': 'FakeSignature2', - 'channel': 'nightly' - }, - ], - 'total': 2, - } - - models.AduBySignature.implementation().get.side_effect = mocked_get - - r = api.get( - product_name='WaterWolf', - signature='FakeSignature1', - channel='nightly', - ) - eq_(r['total'], 2) - def test_platforms(self): api = models.Platforms()