def test_get_exploitibility_by_product(self): crashes = Crashes(config=self.config) res_expected = { "hits": [ { "signature": "canIhaveYourSignature()", "null_count": 0, "none_count": 1, "low_count": 2, "medium_count": 3, "high_count": 4 }, { "signature": "ofCourseYouCan()", "null_count": 5, "none_count": 7, "low_count": 2, "medium_count": 2, "high_count": 0 }, ], "total": 2, } res = crashes.get_exploitability(product='Firefox') eq_(res, res_expected)
def test_get_exploitibility_by_report_date(self): crashes = Crashes(config=self.config) yesterday_date = (self.now - datetime.timedelta(days=1)).date() yesterday = datetimeutil.date_to_string(yesterday_date) res_expected = { "hits": [ { "signature": "canIhaveYourSignature()", "null_count": 2, "none_count": 2, "low_count": 2, "medium_count": 2, "high_count": 2 }, { "signature": "ofCourseYouCan()", "null_count": 4, "none_count": 3, "low_count": 2, "medium_count": 1, "high_count": 0 } ], "total": 2, } res = crashes.get_exploitability( start_date=yesterday, end_date=yesterday ) eq_(res, res_expected)
def test_get_count_by_day(self): crashes = Crashes(config=self.config) now = datetime.datetime.utcnow() yesterday = now - datetime.timedelta(1) tomorrow = now + datetime.timedelta(1) now = now.strftime("%Y-%m-%d") yesterday = yesterday.strftime("%Y-%m-%d") tomorrow = tomorrow.strftime("%Y-%m-%d") params = {'signature': 'js', 'start_date': now} expected = {'hits': {now: 3}, 'total': 1} res = crashes.get_count_by_day(**params) eq_(res, expected) params = {'signature': 'nothing', 'start_date': now} expected = {'hits': {now: 0}, 'total': 1} res = crashes.get_count_by_day(**params) eq_(res, expected) params = { 'signature': 'js', 'start_date': yesterday, 'end_date': tomorrow } expected = {'hits': {yesterday: 2, now: 3}, 'total': 2} res = crashes.get_count_by_day(**params) eq_(res, expected)
def test_get_exploitibility(self): crashes = Crashes(config=self.config) res_expected = { "hits": [ { "signature": "canIhaveYourSignature()", "null_count": 2, "none_count": 3, "low_count": 4, "medium_count": 5, "high_count": 6 }, { "signature": "ofCourseYouCan()", "null_count": 5, "none_count": 7, "low_count": 2, "medium_count": 2, "high_count": 0 } ], "total": 2, } res = crashes.get_exploitability() self.assertEqual(res, res_expected)
def test_get_exploitibility_by_product(self): crashes = Crashes(config=self.config) res_expected = { "hits": [ { "signature": "canIhaveYourSignature()", "null_count": 0, "none_count": 1, "low_count": 2, "medium_count": 3, "high_count": 4 }, { "signature": "ofCourseYouCan()", "null_count": 5, "none_count": 7, "low_count": 2, "medium_count": 2, "high_count": 0 }, ], "total": 2, } res = crashes.get_exploitability(product='Firefox') self.assertEqual(res, res_expected)
def test_get_exploitibility(self): crashes = Crashes(config=self.config) res_expected = { "hits": [{ "signature": "canIhaveYourSignature()", "null_count": 2, "none_count": 3, "low_count": 4, "medium_count": 5, "high_count": 6 }, { "signature": "ofCourseYouCan()", "null_count": 5, "none_count": 7, "low_count": 2, "medium_count": 2, "high_count": 0 }], "total": 2, } res = crashes.get_exploitability() eq_(res, res_expected)
def test_get_exploitibility_by_report_date(self): crashes = Crashes(config=self.config) yesterday_date = (self.now - datetime.timedelta(days=1)).date() yesterday = datetimeutil.date_to_string(yesterday_date) res_expected = { "hits": [{ "signature": "canIhaveYourSignature()", "null_count": 2, "none_count": 2, "low_count": 2, "medium_count": 2, "high_count": 2 }, { "signature": "ofCourseYouCan()", "null_count": 4, "none_count": 3, "low_count": 2, "medium_count": 1, "high_count": 0 }], "total": 2, } res = crashes.get_exploitability(start_date=yesterday, end_date=yesterday) eq_(res, res_expected)
def test_get_signature_history(self): api = Crashes(config=self.config) now = self.now lastweek = now - datetime.timedelta(days=7) params = { "product": "Firefox", "version": "8.0", "signature": "signature1", "start_date": lastweek, "end_date": now, } res = api.get_signature_history(**params) self.assertEqual(len(res["hits"]), 2) self.assertEqual(len(res["hits"]), res["total"]) date = datetimeutil.date_to_string(now.date()) self.assertEqual(res["hits"][0]["date"], date) self.assertEqual(res["hits"][1]["date"], date) self.assertEqual(res["hits"][0]["count"], 5) self.assertEqual(res["hits"][1]["count"], 14) self.assertEqual(round(res["hits"][0]["percent_of_total"], 2), round(5.0 / 19.0 * 100, 2)) self.assertEqual(round(res["hits"][1]["percent_of_total"], 2), round(14.0 / 19.0 * 100, 2)) # Test no results params = { "product": "Firefox", "version": "9.0", "signature": "signature1", "start_date": lastweek, "end_date": now, } res = api.get_signature_history(**params) res_expected = {"hits": [], "total": 0} self.assertEqual(res, res_expected) # Test default date parameters params = {"product": "Fennec", "version": "11.0.1", "signature": "signature3"} res = api.get_signature_history(**params) res_expected = {"hits": [{"date": now.date().isoformat(), "count": 14, "percent_of_total": 100}], "total": 1} self.assertEqual(res, res_expected) # Test missing parameters self.assertRaises(MissingOrBadArgumentError, api.get_signature_history) self.assertRaises(MissingOrBadArgumentError, api.get_signature_history, **{"product": "Firefox"}) self.assertRaises( MissingOrBadArgumentError, api.get_signature_history, **{"product": "Firefox", "version": "8.0"} ) self.assertRaises( MissingOrBadArgumentError, api.get_signature_history, **{"signature": "signature1", "version": "8.0"} )
def test_get_adu_by_signature(self): crashes = Crashes(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 = crashes.get_adu_by_signature( product_name="WaterWolf", start_date=yesterday, end_date=yesterday, signature=signature, channel=channel, ) eq_(res, res_expected) assert_raises(BadArgumentError, crashes.get_adu_by_signature, start_date=(yesterday_date - datetime.timedelta(days=366)), end_date=yesterday, signature=signature, channel=channel)
def test_get_adu_by_signature(self): crashes = Crashes(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 = crashes.get_adu_by_signature( product_name="WaterWolf", start_date=yesterday, end_date=yesterday, signature=signature, channel=channel, ) eq_(res, res_expected) assert_raises( BadArgumentError, crashes.get_adu_by_signature, start_date=(yesterday_date - datetime.timedelta(days=366)), end_date=yesterday, signature=signature, channel=channel )
def test_get_count_by_day(self): crashes = Crashes(config=self.config) now = datetime.datetime.utcnow() yesterday = now - datetime.timedelta(1) tomorrow = now + datetime.timedelta(1) now = now.strftime("%Y-%m-%d") yesterday = yesterday.strftime("%Y-%m-%d") tomorrow = tomorrow.strftime("%Y-%m-%d") params = { 'signature': 'js', 'start_date': now } expected = { 'hits': {now: 3}, 'total': 1 } res = crashes.get_count_by_day(**params) eq_(res, expected) params = { 'signature': 'nothing', 'start_date': now } expected = { 'hits': {now: 0}, 'total': 1 } res = crashes.get_count_by_day(**params) eq_(res, expected) params = { 'signature': 'js', 'start_date': yesterday, 'end_date': tomorrow } expected = { 'hits': { yesterday: 2, now: 3 }, 'total': 2 } res = crashes.get_count_by_day(**params) eq_(res, expected)
def get_instance(self, config=None): """Return an instance of Crashes with the config parameter as a context or the default one if config is None. """ args = { "config": config or self.get_dummy_context() } return Crashes(**args)
def test_get_exploitibility_by_product_and_version(self): crashes = Crashes(config=self.config) res_expected = { "hits": [{ "signature": "ofCourseYouCan()", "null_count": 1, "none_count": 4, "low_count": 0, "medium_count": 1, "high_count": 0 }], "total": 1, } res = crashes.get_exploitability(product='Firefox', version='14.0b') eq_(res, res_expected)
def test_get_comments(self): crashes = Crashes(config=self.config) today = datetimeutil.date_to_string(datetimeutil.utc_now()) # Test 1: results params = { "signature": "js", } res_expected = { "hits": [ { "email": None, "date_processed": today, "uuid": "def", "user_comments": "hello" }, { "email": None, "date_processed": today, "uuid": "hij", "user_comments": "hah" } ], "total": 2 } res = crashes.get_comments(**params) self.assertEqual(res, res_expected) # Test 2: no results params = { "signature": "blah", } res_expected = { "hits": [], "total": 0 } res = crashes.get_comments(**params) self.assertEqual(res, res_expected) # Test 3: missing parameter self.assertRaises(MissingOrBadArgumentError, crashes.get_comments)
def test_get_comments(self): crashes = Crashes(config=self.config) today = datetimeutil.date_to_string(self.now) # Test 1: results params = { "signature": "js", } res_expected = { "hits": [ { "email": None, "date_processed": today, "uuid": "def", "user_comments": "hello" }, { "email": None, "date_processed": today, "uuid": "hij", "user_comments": "hah" } ], "total": 2 } res = crashes.get_comments(**params) self.assertEqual(res, res_expected) # Test 2: no results params = { "signature": "blah", } res_expected = { "hits": [], "total": 0 } res = crashes.get_comments(**params) self.assertEqual(res, res_expected) # Test 3: missing parameter self.assertRaises(MissingArgumentError, crashes.get_comments)
def test_get_exploitibility_by_product_and_version(self): crashes = Crashes(config=self.config) res_expected = { "hits": [ { "signature": "ofCourseYouCan()", "null_count": 1, "none_count": 4, "low_count": 0, "medium_count": 1, "high_count": 0 } ], "total": 1, } res = crashes.get_exploitability(product='Firefox', version='14.0b') eq_(res, res_expected)
def test_get_signatures_with_too_big_date_range(self): # This can all be some fake crap because we're testing that # the implementation class throws out the request before # it gets to doing any queries. config = { 'database_hostname': None, 'database_name': None, 'database_username': None, 'database_password': None, } crashes = Crashes(config=config) params = {} params['duration'] = 31 * 24 # 31 days assert_raises(BadArgumentError, crashes.get_signatures, **params)
def test_get_paireduuid(self): crashes = Crashes(config=self.config) now = datetimeutil.utc_now() yesterday = now - datetime.timedelta(days=1) uuid = "%%s-%s" % now.strftime("%y%m%d") yesterday_uuid = "%%s-%s" % yesterday.strftime("%y%m%d") #...................................................................... # Test 1: a uuid and a hangid params = {"uuid": uuid % "a1", "hangid": "ab1"} res = crashes.get_paireduuid(**params) res_expected = {"hits": [{"uuid": uuid % "a2"}], "total": 1} self.assertEqual(res, res_expected) #...................................................................... # Test 2: a uuid only params = {"uuid": uuid % "a1"} res = crashes.get_paireduuid(**params) res_expected = { "hits": [{ "uuid": uuid % "a2" }, { "uuid": uuid % "a3" }], "total": 2 } self.assertEqual(res, res_expected) #...................................................................... # Test 3: a query with no result params = {"uuid": uuid % "b1"} res = crashes.get_paireduuid(**params) res_expected = {"hits": [], "total": 0} self.assertEqual(res, res_expected) #...................................................................... # Test 4: one result that was yesterday params = {"uuid": uuid % "c1"} res = crashes.get_paireduuid(**params) res_expected = {"hits": [{"uuid": yesterday_uuid % "c2"}], "total": 1} self.assertEqual(res, res_expected) #...................................................................... # Test 5: missing argument params = {"hangid": "c1"} self.assertRaises(MissingOrBadArgumentError, crashes.get_paireduuid, **params)
def test_get_frequency(self): self.config.platforms = ( { "id": "windows", "name": "Windows NT" }, { "id": "linux", "name": "Linux" } ) crashes = Crashes(config=self.config) #...................................................................... # Test 1 params = { "signature": "js" } res_expected = { "hits": [ { "build_date": "2012033117", "count": 1, "frequency": 1.0, "total": 1, "count_windows": 1, "frequency_windows": 1.0, "count_linux": 0, "frequency_linux": 0 }, { "build_date": "2012033116", "count": 2, "frequency": 1.0, "total": 2, "count_windows": 1, "frequency_windows": 1.0, "count_linux": 1, "frequency_linux": 1.0 } ], "total": 2 } res = crashes.get_frequency(**params) self.assertEqual(res, res_expected) #...................................................................... # Test 2 params = { "signature": "blah" } res_expected = { "hits": [ { "build_date": "2012033117", "count": 1, "frequency": 1.0, "total": 1, "count_windows": 0, "frequency_windows": 0.0, "count_linux": 0, "frequency_linux": 0.0 } ], "total": 1 } res = crashes.get_frequency(**params) self.assertEqual(res, res_expected)
def test_get_daily(self): crashes = Crashes(config=self.config) now = self.now.date() today = now.isoformat() yesterday = (now - datetime.timedelta(days=1)).isoformat() # Test 1: one product, one version (simple version) params = {"product": "Firefox", "versions": ["11.0"]} res_expected = { "hits": { "Firefox:11.0": { today: { "product": "Firefox", "version": "11.0", "date": today, "report_count": 5, "adu": 20, "crash_hadu": 0.12 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 2: one product, several versions, range by build date, # simple version params = { "product": "Firefox", "versions": ["11.0", "12.0"], "date_range_type": "build" } res_expected = { "hits": { "Firefox:11.0": { today: { "product": "Firefox", "version": "11.0", "date": today, "report_count": 5, "adu": 200, "crash_hadu": 25.0 }, yesterday: { "product": "Firefox", "version": "11.0", "date": yesterday, "report_count": 3, "adu": 274, "crash_hadu": 10.949 } }, "Firefox:12.0": { today: { "product": "Firefox", "version": "12.0", "date": today, "report_count": 3, "adu": 109, "crash_hadu": 27.523 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 3: one product, one version, extended fields, complex version params = { "product": "Firefox", "versions": ["11.0"], "separated_by": "os" } res_expected = { "hits": { "Firefox:11.0:win": { today: { "product": "Firefox", "version": "11.0", "date": today, "os": "Windows", "report_count": 50, "adu": 3000, "crash_hadu": 1.667, "throttle": 0.1 } }, "Firefox:11.0:lin": { today: { "product": "Firefox", "version": "11.0", "date": today, "os": "Linux", "report_count": 10, "adu": 1000, "crash_hadu": 1.0, "throttle": 0.1 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 4: report type filter, complex version params = { "product": "Firefox", "versions": ["13.0"], "report_type": "hang" } res_expected = { "hits": { "Firefox:13.0": { today: { "product": "Firefox", "version": "13.0", "date": today, "report_count": 90, "adu": 12000, "crash_hadu": 0.75, "throttle": 0.1 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 5: extended fields, by build date and with report type, # complex version params = { "product": "Firefox", "versions": ["11.0", "12.0"], "report_type": "crash", "date_range_type": "build" } res_expected = { "hits": { "Firefox:11.0": { today: { "product": "Firefox", "version": "11.0", "date": today, "report_count": 10, "adu": 2000, "crash_hadu": 0.5, "throttle": 0.1 }, yesterday: { "product": "Firefox", "version": "11.0", "date": yesterday, "report_count": 70, "adu": 7000, "crash_hadu": 1.0, "throttle": 0.1 } }, "Firefox:12.0": { yesterday: { "product": "Firefox", "version": "12.0", "date": yesterday, "report_count": 10, "adu": 1000, "crash_hadu": 1.0, "throttle": 0.1 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 6: missing parameters assert_raises(MissingArgumentError, crashes.get_daily) assert_raises(MissingArgumentError, crashes.get_daily, **{"product": "Firefox"})
def test_get_comments(self): crashes = Crashes(config=self.config) today = datetimeutil.date_to_string(self.now) # Test 1: results params = { "signature": "js", } res_expected = { "hits": [{ "email": None, "date_processed": today, "uuid": "def", "user_comments": "hello" }, { "email": None, "date_processed": today, "uuid": "hij", "user_comments": "hah" }], "total": 2 } res = crashes.get_comments(**params) eq_(res, res_expected) # Test 2: no results params = { "signature": "blah", } res_expected = {"hits": [], "total": 0} res = crashes.get_comments(**params) eq_(res, res_expected) # Test 3: missing parameter assert_raises(MissingArgumentError, crashes.get_comments) # Test a valid rapid beta versions params = { "signature": "cool_sig", "products": "Firefox", "versions": "Firefox:14.0b", } res_expected = { 'hits': [{ 'email': None, 'date_processed': today, 'uuid': 'nop', 'user_comments': 'hi!' }], 'total': 1 } res = crashes.get_comments(**params) eq_(res, res_expected) # Test an invalid rapid beta versions params = { "signature": "cool_sig", "versions": "WaterWolf:2.0b", } res = crashes.get_comments(**params) ok_(res) eq_(len(res['hits']), 2) eq_(res['total'], 2) # use pagination params['result_number'] = 1 params['result_offset'] = 0 res = crashes.get_comments(**params) eq_(len(res['hits']), 1) eq_(res['total'], 2)
def test_get_exploitibility_with_pagination(self): crashes = Crashes(config=self.config) yesterday_date = (self.now - datetime.timedelta(days=1)).date() day_before_yesterday = (self.now - datetime.timedelta(days=2)).date() j = 100 # some number so it's not used by other tests or fixtures rand = lambda: random.randint(0, 10) exploit_values = [] signature_values = [] for day in day_before_yesterday, yesterday_date, self.now: for i in range(10): exploit_values.append( "(%s, 3, 'Signature%s%s', '%s', %s, %s, %s, %s, %s)" % (j + 1, j, i, day, rand(), rand(), rand(), rand(), rand())) signature_values.append( "(%s, 'Signature%s%s', %s, '%s')" % (j + 1, j, i, day.strftime('%Y%m%d%H'), day)) j += 1 cursor = self.connection.cursor() insert = """ INSERT INTO signatures (signature_id, signature, first_build, first_report) VALUES """ insert += ',\n'.join(signature_values) cursor.execute(insert) insert = """ INSERT INTO exploitability_reports (signature_id, product_version_id, signature, report_date, null_count, none_count, low_count, medium_count, high_count) VALUES """ insert += ',\n'.join(exploit_values) cursor.execute(insert) self.connection.commit() res = crashes.get_exploitability() eq_(len(res['hits']), res['total']) ok_(res['total'] >= 3 * 10) res = crashes.get_exploitability(start_date=yesterday_date, end_date=self.now) eq_(len(res['hits']), res['total']) ok_(res['total'] >= 2 * 10) ok_(res['total'] < 3 * 10) # passing a `page` without `batch` will yield an error assert_raises(MissingArgumentError, crashes.get_exploitability, page=2) # `page` starts on one so anything smaller is bad assert_raises(BadArgumentError, crashes.get_exploitability, page=0, batch=15) # Note, `page=1` is on number line starting on 1 res = crashes.get_exploitability(page=1, batch=15) self.assertNotEqual(len(res['hits']), res['total']) eq_(len(res['hits']), 15) ok_(res['total'] >= 3 * 10) # since it's ordered by "medium + high"... med_or_highs = [ x['medium_count'] + x['high_count'] for x in res['hits'] ] eq_(med_or_highs[0], max(med_or_highs)) eq_(med_or_highs[-1], min(med_or_highs))
def test_get_exploitibility_with_pagination(self): crashes = Crashes(config=self.config) yesterday_date = (self.now - datetime.timedelta(days=1)).date() day_before_yesterday = (self.now - datetime.timedelta(days=2)).date() j = 100 # some number so it's not used by other tests or fixtures rand = lambda: random.randint(0, 10) exploit_values = [] signature_values = [] for day in day_before_yesterday, yesterday_date, self.now: for i in range(10): exploit_values.append( "(%s, 3, 'Signature%s%s', '%s', %s, %s, %s, %s, %s)" % ( j + 1, j, i, day, rand(), rand(), rand(), rand(), rand() ) ) signature_values.append( "(%s, 'Signature%s%s', %s, '%s')" % ( j + 1, j, i, day.strftime('%Y%m%d%H'), day ) ) j += 1 cursor = self.connection.cursor() insert = """ INSERT INTO signatures (signature_id, signature, first_build, first_report) VALUES """ insert += ',\n'.join(signature_values) cursor.execute(insert) insert = """ INSERT INTO exploitability_reports (signature_id, product_version_id, signature, report_date, null_count, none_count, low_count, medium_count, high_count) VALUES """ insert += ',\n'.join(exploit_values) cursor.execute(insert) self.connection.commit() res = crashes.get_exploitability() eq_(len(res['hits']), res['total']) ok_(res['total'] >= 3 * 10) res = crashes.get_exploitability( start_date=yesterday_date, end_date=self.now ) eq_(len(res['hits']), res['total']) ok_(res['total'] >= 2 * 10) ok_(res['total'] < 3 * 10) # passing a `page` without `batch` will yield an error assert_raises( MissingArgumentError, crashes.get_exploitability, page=2 ) # `page` starts on one so anything smaller is bad assert_raises( BadArgumentError, crashes.get_exploitability, page=0, batch=15 ) # Note, `page=1` is on number line starting on 1 res = crashes.get_exploitability( page=1, batch=15 ) self.assertNotEqual(len(res['hits']), res['total']) eq_(len(res['hits']), 15) ok_(res['total'] >= 3 * 10) # since it's ordered by "medium + high"... med_or_highs = [ x['medium_count'] + x['high_count'] for x in res['hits'] ] eq_( med_or_highs[0], max(med_or_highs) ) eq_( med_or_highs[-1], min(med_or_highs) )
def test_get_frequency(self): self.config.webapi = util.DotDict() self.config.webapi.platforms = ({ "id": "windows", "name": "Windows NT" }, { "id": "linux", "name": "Linux" }) crashes = Crashes(config=self.config) #...................................................................... # Test 1 params = {"signature": "js"} res_expected = { "hits": [{ "build_date": "2012033117", "count": 1, "frequency": 1.0, "total": 1, "count_windows": 1, "frequency_windows": 1.0, "count_linux": 0, "frequency_linux": 0 }, { "build_date": "2012033116", "count": 2, "frequency": 1.0, "total": 2, "count_windows": 1, "frequency_windows": 1.0, "count_linux": 1, "frequency_linux": 1.0 }], "total": 2 } res = crashes.get_frequency(**params) eq_(res, res_expected) #...................................................................... # Test 2 params = {"signature": "blah"} res_expected = { "hits": [{ "build_date": "2012033117", "count": 1, "frequency": 1.0, "total": 1, "count_windows": 0, "frequency_windows": 0.0, "count_linux": 0, "frequency_linux": 0.0 }], "total": 1 } res = crashes.get_frequency(**params) eq_(res, res_expected) #...................................................................... # Verify that it is not possible to break the query. params = {"signature": "sig'"} res = crashes.get_frequency(**params) eq_(res["total"], 0)
def test_get_signatures(self): tcbs = Crashes(config=self.config) now = datetimeutil.utc_now() today = datetime.datetime(now.year, now.month, now.day) lastweek = today - datetime.timedelta(days=7) tomorrow_str = (today + datetime.timedelta(days=1)).strftime('%Y-%m-%d') today_str = today.strftime('%Y-%m-%d') sixdaysago_str = (lastweek + datetime.timedelta(days=1)).strftime('%Y-%m-%d') lastweek_str = lastweek.strftime('%Y-%m-%d') lastweek_str_full = lastweek.strftime('%Y-%m-%d %H:%M:%S') # Test 1: all TCBS for Firefox params = { "product": "Firefox", "version": "8.0" } res = tcbs.get_signatures(**params) res_expected = { 'totalPercentage': 1.0, 'end_date': tomorrow_str, 'start_date': sixdaysago_str, 'crashes': [ { 'count': 19L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 0, 'currentRank': 0, 'startup_percent': None, 'versions': 'plugin1, plugin2', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 0.86363636363636398, 'changeInRank': 0, 'win_count': 12L, 'changeInPercentOfTotal': -0.13636363636363602, 'linux_count': 6L, 'hang_count': 5L, 'signature': 'signature1', 'versions_count': 2, 'previousPercentOfTotal': 1.0, 'plugin_count': 0 }, { 'count': 3L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 'null', 'currentRank': 1, 'startup_percent': None, 'versions': 'plugin1, plugin2, plugin3, plugin4, plugin5, plugin6', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 0.13636363636363599, 'changeInRank': 'new', 'win_count': 1L, 'changeInPercentOfTotal': 'new', 'linux_count': 1L, 'hang_count': 0L, 'signature': 'signature2', 'versions_count': 6, 'previousPercentOfTotal': 'null', 'plugin_count': 0 } ], 'totalNumberOfCrashes': 22L } self.assertEqual(res, res_expected) # Test 2: Limit to one crash type params = { "product": "Firefox", "version": "8.0", "crash_type": "hang" } res = tcbs.get_signatures(**params) res_expected = { 'totalPercentage': 1.0, 'end_date': tomorrow_str, 'start_date': sixdaysago_str, 'crashes': [ { 'count': 5L, 'mac_count': 0L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 'null', 'currentRank': 0, 'startup_percent': None, 'versions': 'plugin1, plugin2', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 1.0, 'changeInRank': 'new', 'win_count': 0L, 'changeInPercentOfTotal': 'new', 'linux_count': 5L, 'hang_count': 5L, 'signature': 'signature1', 'versions_count': 2, 'previousPercentOfTotal': 'null', 'plugin_count': 0 } ], 'totalNumberOfCrashes': 5L } self.assertEqual(res, res_expected) # Test 3: Limit to one OS params = { "product": "Firefox", "version": "8.0", "os": "Windows" } res = tcbs.get_signatures(**params) res_expected = { 'totalPercentage': 0.76470588235294168, 'end_date': tomorrow_str, 'start_date': sixdaysago_str, 'crashes': [ { 'count': 14L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 0, 'currentRank': 0, 'startup_percent': None, 'versions': 'plugin1, plugin2', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 0.70588235294117696, 'changeInRank': 0, 'win_count': 12L, 'changeInPercentOfTotal': 0.0058823529411770048, 'linux_count': 1L, 'hang_count': 0L, 'signature': 'signature1', 'versions_count': 2, 'previousPercentOfTotal': 0.69999999999999996, 'plugin_count': 0 }, { 'count': 3L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 'null', 'currentRank': 1, 'startup_percent': None, 'versions': 'plugin1, plugin2, plugin3, plugin4, plugin5, plugin6', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 0.058823529411764698, 'changeInRank': 'new', 'win_count': 1L, 'changeInPercentOfTotal': 'new', 'linux_count': 1L, 'hang_count': 0L, 'signature': 'signature2', 'versions_count': 6, 'previousPercentOfTotal': 'null', 'plugin_count': 0 } ], 'totalNumberOfCrashes': 17L } self.assertEqual(res, res_expected) # Test 4: No results params = { "product": "Unknown", "version": "8.0", } res = tcbs.get_signatures(**params) self.assertTrue('totalNumberOfCrashes' in res) self.assertEqual(res['totalNumberOfCrashes'], 0) self.assertEqual(res['crashes'], []) # Test 5: Results ranged by build date params = { "product": "Fennec", "version": "11.0.1", "date_range_type": "build" } res = tcbs.get_signatures(**params) res_expected = { 'totalPercentage': 1.0, 'end_date': tomorrow_str, 'start_date': sixdaysago_str, 'crashes': [ { 'count': 14L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 'null', 'currentRank': 0, 'startup_percent': None, 'versions': 'plugin1, plugin2', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 1.0, 'changeInRank': 'new', 'win_count': 12L, 'changeInPercentOfTotal': 'new', 'linux_count': 1L, 'hang_count': 0L, 'signature': 'signature3', 'versions_count': 2, 'previousPercentOfTotal': 'null', 'plugin_count': 14 } ], 'totalNumberOfCrashes': 14L } self.assertEqual(res, res_expected)
def test_get_frequency(self): self.config.webapi = util.DotDict() self.config.webapi.platforms = ( { "id": "windows", "name": "Windows NT" }, { "id": "linux", "name": "Linux" } ) crashes = Crashes(config=self.config) # ..................................................................... # Test 1 params = { "signature": "js" } res_expected = { "hits": [ { "build_date": "2012033117", "count": 1, "frequency": 1.0, "total": 1, "count_windows": 1, "frequency_windows": 1.0, "count_linux": 0, "frequency_linux": 0 }, { "build_date": "2012033116", "count": 2, "frequency": 1.0, "total": 2, "count_windows": 1, "frequency_windows": 1.0, "count_linux": 1, "frequency_linux": 1.0 } ], "total": 2 } res = crashes.get_frequency(**params) eq_(res, res_expected) # ..................................................................... # Test 2 params = { "signature": "blah" } res_expected = { "hits": [ { "build_date": "2012033117", "count": 1, "frequency": 1.0, "total": 1, "count_windows": 0, "frequency_windows": 0.0, "count_linux": 0, "frequency_linux": 0.0 } ], "total": 1 } res = crashes.get_frequency(**params) eq_(res, res_expected) # ..................................................................... # Verify that it is not possible to break the query. params = { "signature": "sig'" } res = crashes.get_frequency(**params) eq_(res["total"], 0)
def test_get_daily(self): crashes = Crashes(config=self.config) now = self.now.date() today = now.isoformat() yesterday = (now - datetime.timedelta(days=1)).isoformat() # Test 1: one product, one version (simple version) params = { "product": "Firefox", "versions": ["11.0"] } res_expected = { "hits": { "Firefox:11.0": { today: { "product": "Firefox", "version": "11.0", "date": today, "report_count": 5, "adu": 20, "crash_hadu": 0.12 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 2: one product, several versions, range by build date, # simple version params = { "product": "Firefox", "versions": ["11.0", "12.0"], "date_range_type": "build" } res_expected = { "hits": { "Firefox:11.0": { today: { "product": "Firefox", "version": "11.0", "date": today, "report_count": 5, "adu": 200, "crash_hadu": 25.0 }, yesterday: { "product": "Firefox", "version": "11.0", "date": yesterday, "report_count": 3, "adu": 274, "crash_hadu": 10.949 } }, "Firefox:12.0": { today: { "product": "Firefox", "version": "12.0", "date": today, "report_count": 3, "adu": 109, "crash_hadu": 27.523 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 3: report type filter, complex version params = { "product": "Firefox", "versions": ["13.0"], "report_type": "hang" } res_expected = { "hits": { "Firefox:13.0": { today: { "product": "Firefox", "version": "13.0", "date": today, "report_count": 90, "adu": 12000, "crash_hadu": 0.75, "throttle": 0.1 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 4: extended fields, by build date and with report type, # complex version params = { "product": "Firefox", "versions": ["11.0", "12.0"], "report_type": "crash", "date_range_type": "build" } res_expected = { "hits": { "Firefox:11.0": { today: { "product": "Firefox", "version": "11.0", "date": today, "report_count": 10, "adu": 2000, "crash_hadu": 0.5, "throttle": 0.1 }, yesterday: { "product": "Firefox", "version": "11.0", "date": yesterday, "report_count": 70, "adu": 7000, "crash_hadu": 1.0, "throttle": 0.1 } }, "Firefox:12.0": { yesterday: { "product": "Firefox", "version": "12.0", "date": yesterday, "report_count": 10, "adu": 1000, "crash_hadu": 1.0, "throttle": 0.1 } } } } res = crashes.get_daily(**params) eq_(res, res_expected) # Test 5: missing parameters assert_raises(MissingArgumentError, crashes.get_daily) assert_raises(MissingArgumentError, crashes.get_daily, **{"product": "Firefox"})
def test_get_comments(self): crashes = Crashes(config=self.config) today = datetimeutil.date_to_string(self.now) # Test 1: results params = { "signature": "js", } res_expected = { "hits": [ { "email": None, "date_processed": today, "uuid": "def", "user_comments": "hello" }, { "email": None, "date_processed": today, "uuid": "hij", "user_comments": "hah" } ], "total": 2 } res = crashes.get_comments(**params) eq_(res, res_expected) # Test 2: no results params = { "signature": "blah", } res_expected = { "hits": [], "total": 0 } res = crashes.get_comments(**params) eq_(res, res_expected) # Test 3: missing parameter assert_raises(MissingArgumentError, crashes.get_comments) # Test a valid rapid beta versions params = { "signature": "cool_sig", "products": "Firefox", "versions": "Firefox:14.0b", } res_expected = { 'hits': [ { 'email': None, 'date_processed': today, 'uuid': 'nop', 'user_comments': 'hi!' } ], 'total': 1 } res = crashes.get_comments(**params) eq_(res, res_expected) # Test an invalid rapid beta versions params = { "signature": "cool_sig", "versions": "WaterWolf:2.0b", } res_expected = { 'hits': [ { 'email': None, 'date_processed': today, 'uuid': 'qrs', 'user_comments': 'meow' } ], 'total': 1 } res = crashes.get_comments(**params) eq_(res, res_expected) # use pagination params = { "signature": "cool_sig", "result_number": 1, "result_offset": 0, } params['result_number'] = 1 params['result_offset'] = 0 res = crashes.get_comments(**params) eq_(len(res['hits']), 1) eq_(res['total'], 2)
def test_get_comments(self): crashes = Crashes(config=self.config) today = datetimeutil.date_to_string(self.now) # Test 1: results params = { "signature": "js", } res_expected = { "hits": [ { "email": None, "date_processed": today, "uuid": "def", "user_comments": "hello" }, { "email": None, "date_processed": today, "uuid": "hij", "user_comments": "hah" } ], "total": 2 } res = crashes.get_comments(**params) self.assertEqual(res, res_expected) # Test 2: no results params = { "signature": "blah", } res_expected = { "hits": [], "total": 0 } res = crashes.get_comments(**params) self.assertEqual(res, res_expected) # Test 3: missing parameter self.assertRaises(MissingArgumentError, crashes.get_comments) # Test a valid rapid beta versions params = { "signature": "cool_sig", "products": "Firefox", "versions": "Firefox:14.0b", } res_expected = { 'hits': [ { 'email': None, 'date_processed': today, 'uuid': 'nop', 'user_comments': 'hi!' } ], 'total': 1 } res = crashes.get_comments(**params) self.assertEqual(res, res_expected) # Test an invalid rapid beta versions params = { "signature": "cool_sig", "versions": "WaterWolf:2.0b", } res = crashes.get_comments(**params) self.assertTrue(res)
def test_get_signatures(self): tcbs = Crashes(config=self.config) now = self.now today = datetime.datetime(now.year, now.month, now.day) lastweek = today - datetime.timedelta(days=7) tomorrow_str = (today + datetime.timedelta(days=1)).strftime('%Y-%m-%d') sixdaysago_str = (lastweek + datetime.timedelta(days=1)).strftime('%Y-%m-%d') lastweek_str = lastweek.strftime('%Y-%m-%d') lastweek_str_full = lastweek.strftime('%Y-%m-%d %H:%M:%S') # Test 1: all TCBS for Firefox params = { "product": "Firefox", "version": "8.0" } res = tcbs.get_signatures(**params) res_expected = { 'totalPercentage': 1.0, 'end_date': tomorrow_str, 'start_date': sixdaysago_str, 'crashes': [ { 'count': 19L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 0, 'currentRank': 0, 'startup_percent': None, 'versions': 'plugin1, plugin2', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 0.86363636363636398, 'changeInRank': 0, 'win_count': 12L, 'changeInPercentOfTotal': -0.13636363636363602, 'linux_count': 6L, 'hang_count': 5L, 'signature': 'signature1', 'versions_count': 2, 'previousPercentOfTotal': 1.0, 'plugin_count': 0, 'is_gc_count': 11L }, { 'count': 3L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 'null', 'currentRank': 1, 'startup_percent': None, 'versions': 'plugin1, plugin2, plugin3, plugin4, plugin5, plugin6', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 0.13636363636363599, 'changeInRank': 'new', 'win_count': 1L, 'changeInPercentOfTotal': 'new', 'linux_count': 1L, 'hang_count': 0L, 'signature': 'signature2', 'versions_count': 6, 'previousPercentOfTotal': 'null', 'plugin_count': 0, 'is_gc_count': 1L } ], 'totalNumberOfCrashes': 22L } eq_(res, res_expected) # Test 2: Limit to one crash type params = { "product": "Firefox", "version": "8.0", "crash_type": "hang" } res = tcbs.get_signatures(**params) res_expected = { 'totalPercentage': 1.0, 'end_date': tomorrow_str, 'start_date': sixdaysago_str, 'crashes': [ { 'count': 5L, 'mac_count': 0L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 'null', 'currentRank': 0, 'startup_percent': None, 'versions': 'plugin1, plugin2', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 1.0, 'changeInRank': 'new', 'win_count': 0L, 'changeInPercentOfTotal': 'new', 'linux_count': 5L, 'hang_count': 5L, 'signature': 'signature1', 'versions_count': 2, 'previousPercentOfTotal': 'null', 'plugin_count': 0, 'is_gc_count': 10L } ], 'totalNumberOfCrashes': 5L } eq_(res, res_expected) # Test 3: Limit to one OS params = { "product": "Firefox", "version": "8.0", "os": "Windows" } res = tcbs.get_signatures(**params) res_expected = { 'totalPercentage': 0.76470588235294168, 'end_date': tomorrow_str, 'start_date': sixdaysago_str, 'crashes': [ { 'count': 14L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 0, 'currentRank': 0, 'startup_percent': None, 'versions': 'plugin1, plugin2', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 0.70588235294117696, 'changeInRank': 0, 'win_count': 12L, 'changeInPercentOfTotal': 0.0058823529411770048, 'linux_count': 1L, 'hang_count': 0L, 'signature': 'signature1', 'versions_count': 2, 'previousPercentOfTotal': 0.69999999999999996, 'plugin_count': 0, 'is_gc_count': 1L }, { 'count': 3L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 'null', 'currentRank': 1, 'startup_percent': None, 'versions': 'plugin1, plugin2, plugin3, plugin4, plugin5, plugin6', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 0.058823529411764698, 'changeInRank': 'new', 'win_count': 1L, 'changeInPercentOfTotal': 'new', 'linux_count': 1L, 'hang_count': 0L, 'signature': 'signature2', 'versions_count': 6, 'previousPercentOfTotal': 'null', 'plugin_count': 0, 'is_gc_count': 1L } ], 'totalNumberOfCrashes': 17L } eq_(res, res_expected) # Test 4: No results params = { "product": "Unknown", "version": "8.0", } res = tcbs.get_signatures(**params) ok_('totalNumberOfCrashes' in res) eq_(res['totalNumberOfCrashes'], 0) eq_(res['crashes'], []) # Test 5: Results ranged by build date params = { "product": "Fennec", "version": "11.0.1", "date_range_type": "build" } res = tcbs.get_signatures(**params) res_expected = { 'totalPercentage': 1.0, 'end_date': tomorrow_str, 'start_date': sixdaysago_str, 'crashes': [ { 'count': 14L, 'mac_count': 1L, 'content_count': 0, 'first_report': lastweek_str, 'previousRank': 'null', 'currentRank': 0, 'startup_percent': None, 'versions': 'plugin1, plugin2', 'first_report_exact': lastweek_str_full, 'percentOfTotal': 1.0, 'changeInRank': 'new', 'win_count': 12L, 'changeInPercentOfTotal': 'new', 'linux_count': 1L, 'hang_count': 0L, 'signature': 'signature3', 'versions_count': 2, 'previousPercentOfTotal': 'null', 'plugin_count': 14, 'is_gc_count': 10L } ], 'totalNumberOfCrashes': 14L } eq_(res, res_expected) # And now some error handling checks # Test 6: Limit to one OS but an unrecognized one params = { "product": "Firefox", "version": "8.0", "os": "NEVER_HEARD_OF" } assert_raises(BadArgumentError, tcbs.get_signatures, **params) # Test 7: A nasty crash_type value params = { "product": "Firefox", "version": "8.0", "crash_type": "';delete from user" } res = tcbs.get_signatures(**params) eq_(res['crashes'], []) eq_(res['totalNumberOfCrashes'], 0)
def test_get_signature_history(self): api = Crashes(config=self.config) now = self.now lastweek = now - datetime.timedelta(days=7) params = { 'product': 'Firefox', 'version': '8.0', 'signature': 'signature1', 'start_date': lastweek, 'end_date': now, } res = api.get_signature_history(**params) eq_(len(res['hits']), 2) eq_(len(res['hits']), res['total']) date = datetimeutil.date_to_string(now.date()) eq_(res['hits'][0]['date'], date) eq_(res['hits'][1]['date'], date) eq_(res['hits'][0]['count'], 5) eq_(res['hits'][1]['count'], 14) eq_( round(res['hits'][0]['percent_of_total'], 2), round(5.0 / 19.0 * 100, 2) ) eq_( round(res['hits'][1]['percent_of_total'], 2), round(14.0 / 19.0 * 100, 2) ) # Test no results params = { 'product': 'Firefox', 'version': '9.0', 'signature': 'signature1', 'start_date': lastweek, 'end_date': now, } res = api.get_signature_history(**params) res_expected = { 'hits': [], 'total': 0 } eq_(res, res_expected) # Test default date parameters params = { 'product': 'Fennec', 'version': '11.0.1', 'signature': 'signature3', } res = api.get_signature_history(**params) res_expected = { 'hits': [ { 'date': now.date().isoformat(), 'count': 14, 'percent_of_total': 100 } ], 'total': 1 } eq_(res, res_expected) # Test missing parameters assert_raises( MissingArgumentError, api.get_signature_history ) assert_raises( MissingArgumentError, api.get_signature_history, **{'product': 'Firefox'} ) assert_raises( MissingArgumentError, api.get_signature_history, **{'product': 'Firefox', 'version': '8.0'} ) assert_raises( MissingArgumentError, api.get_signature_history, **{'signature': 'signature1', 'version': '8.0'} )
def test_get_signatures(self): tcbs = Crashes(config=self.config) now = self.now today = datetime.datetime(now.year, now.month, now.day) lastweek = today - datetime.timedelta(days=7) tomorrow_str = (today + datetime.timedelta(days=1)).strftime("%Y-%m-%d") sixdaysago_str = (lastweek + datetime.timedelta(days=1)).strftime("%Y-%m-%d") lastweek_str = lastweek.strftime("%Y-%m-%d") lastweek_str_full = lastweek.strftime("%Y-%m-%d %H:%M:%S") # Test 1: all TCBS for Firefox params = {"product": "Firefox", "version": "8.0"} res = tcbs.get_signatures(**params) res_expected = { "totalPercentage": 1.0, "end_date": tomorrow_str, "start_date": sixdaysago_str, "crashes": [ { "count": 19L, "mac_count": 1L, "content_count": 0, "first_report": lastweek_str, "previousRank": 0, "currentRank": 0, "startup_percent": None, "versions": "plugin1, plugin2", "first_report_exact": lastweek_str_full, "percentOfTotal": 0.86363636363636398, "changeInRank": 0, "win_count": 12L, "changeInPercentOfTotal": -0.13636363636363602, "linux_count": 6L, "hang_count": 5L, "signature": "signature1", "versions_count": 2, "previousPercentOfTotal": 1.0, "plugin_count": 0, "is_gc_count": 11L, }, { "count": 3L, "mac_count": 1L, "content_count": 0, "first_report": lastweek_str, "previousRank": "null", "currentRank": 1, "startup_percent": None, "versions": "plugin1, plugin2, plugin3, plugin4, plugin5, plugin6", "first_report_exact": lastweek_str_full, "percentOfTotal": 0.13636363636363599, "changeInRank": "new", "win_count": 1L, "changeInPercentOfTotal": "new", "linux_count": 1L, "hang_count": 0L, "signature": "signature2", "versions_count": 6, "previousPercentOfTotal": "null", "plugin_count": 0, "is_gc_count": 1L, }, ], "totalNumberOfCrashes": 22L, } self.assertEqual(res, res_expected) # Test 2: Limit to one crash type params = {"product": "Firefox", "version": "8.0", "crash_type": "hang"} res = tcbs.get_signatures(**params) res_expected = { "totalPercentage": 1.0, "end_date": tomorrow_str, "start_date": sixdaysago_str, "crashes": [ { "count": 5L, "mac_count": 0L, "content_count": 0, "first_report": lastweek_str, "previousRank": "null", "currentRank": 0, "startup_percent": None, "versions": "plugin1, plugin2", "first_report_exact": lastweek_str_full, "percentOfTotal": 1.0, "changeInRank": "new", "win_count": 0L, "changeInPercentOfTotal": "new", "linux_count": 5L, "hang_count": 5L, "signature": "signature1", "versions_count": 2, "previousPercentOfTotal": "null", "plugin_count": 0, "is_gc_count": 10L, } ], "totalNumberOfCrashes": 5L, } self.assertEqual(res, res_expected) # Test 3: Limit to one OS params = {"product": "Firefox", "version": "8.0", "os": "Windows"} res = tcbs.get_signatures(**params) res_expected = { "totalPercentage": 0.76470588235294168, "end_date": tomorrow_str, "start_date": sixdaysago_str, "crashes": [ { "count": 14L, "mac_count": 1L, "content_count": 0, "first_report": lastweek_str, "previousRank": 0, "currentRank": 0, "startup_percent": None, "versions": "plugin1, plugin2", "first_report_exact": lastweek_str_full, "percentOfTotal": 0.70588235294117696, "changeInRank": 0, "win_count": 12L, "changeInPercentOfTotal": 0.0058823529411770048, "linux_count": 1L, "hang_count": 0L, "signature": "signature1", "versions_count": 2, "previousPercentOfTotal": 0.69999999999999996, "plugin_count": 0, "is_gc_count": 1L, }, { "count": 3L, "mac_count": 1L, "content_count": 0, "first_report": lastweek_str, "previousRank": "null", "currentRank": 1, "startup_percent": None, "versions": "plugin1, plugin2, plugin3, plugin4, plugin5, plugin6", "first_report_exact": lastweek_str_full, "percentOfTotal": 0.058823529411764698, "changeInRank": "new", "win_count": 1L, "changeInPercentOfTotal": "new", "linux_count": 1L, "hang_count": 0L, "signature": "signature2", "versions_count": 6, "previousPercentOfTotal": "null", "plugin_count": 0, "is_gc_count": 1L, }, ], "totalNumberOfCrashes": 17L, } self.assertEqual(res, res_expected) # Test 4: No results params = {"product": "Unknown", "version": "8.0"} res = tcbs.get_signatures(**params) self.assertTrue("totalNumberOfCrashes" in res) self.assertEqual(res["totalNumberOfCrashes"], 0) self.assertEqual(res["crashes"], []) # Test 5: Results ranged by build date params = {"product": "Fennec", "version": "11.0.1", "date_range_type": "build"} res = tcbs.get_signatures(**params) res_expected = { "totalPercentage": 1.0, "end_date": tomorrow_str, "start_date": sixdaysago_str, "crashes": [ { "count": 14L, "mac_count": 1L, "content_count": 0, "first_report": lastweek_str, "previousRank": "null", "currentRank": 0, "startup_percent": None, "versions": "plugin1, plugin2", "first_report_exact": lastweek_str_full, "percentOfTotal": 1.0, "changeInRank": "new", "win_count": 12L, "changeInPercentOfTotal": "new", "linux_count": 1L, "hang_count": 0L, "signature": "signature3", "versions_count": 2, "previousPercentOfTotal": "null", "plugin_count": 14, "is_gc_count": 10L, } ], "totalNumberOfCrashes": 14L, } self.assertEqual(res, res_expected)
def test_get_paireduuid(self): crashes = Crashes(config=self.config) yesterday = self.now - datetime.timedelta(days=1) uuid = "%%s-%s" % self.now.strftime("%y%m%d") yesterday_uuid = "%%s-%s" % yesterday.strftime("%y%m%d") #...................................................................... # Test 1: a uuid and a hangid params = { "uuid": uuid % "a1", "hangid": "ab1" } res = crashes.get_paireduuid(**params) res_expected = { "hits": [ { "uuid": uuid % "a2" } ], "total": 1 } self.assertEqual(res, res_expected) #...................................................................... # Test 2: a uuid only params = { "uuid": uuid % "a1" } res = crashes.get_paireduuid(**params) res_expected = { "hits": [ { "uuid": uuid % "a2" }, { "uuid": uuid % "a3" } ], "total": 2 } self.assertEqual(res, res_expected) #...................................................................... # Test 3: a query with no result params = { "uuid": uuid % "b1" } res = crashes.get_paireduuid(**params) res_expected = { "hits": [], "total": 0 } self.assertEqual(res, res_expected) #...................................................................... # Test 4: one result that was yesterday params = { "uuid": uuid % "c1" } res = crashes.get_paireduuid(**params) res_expected = { "hits": [ { "uuid": yesterday_uuid % "c2" } ], "total": 1 } self.assertEqual(res, res_expected) #...................................................................... # Test 5: missing argument params = { "hangid": "c1" } self.assertRaises(MissingArgumentError, crashes.get_paireduuid, **params)