def test_no_notes_for_public_reporting(self): mock = BZMock() mock.mock_post.update({ 'https://a.blazemeter.com/api/v4/sessions/1/terminate-external': {}, 'https://data.blazemeter.com/submit.php?session_id=1&signature=None&test_id=1&user_id=1&pq=0&target=labels_bulk&update=1': {}, }) obj = BlazeMeterUploader() obj.parameters['project'] = 'Proj name' obj.settings['token'] = '' # public reporting obj.settings['browser-open'] = 'none' obj.engine = EngineEmul() mock.apply(obj._user) obj.prepare() obj._session = Session(obj._user, {'id': 1, 'testId': 1, 'userId': 1}) obj._master = Master(obj._user, {'id': 1}) obj.engine.stopping_reason = ValueError('wrong value') obj.aggregated_second(random_datapoint(10)) obj.kpi_buffer[-1][DataPoint.CUMULATIVE][''][KPISet.ERRORS] = [ {'msg': 'Forbidden', 'cnt': 10, 'type': KPISet.ERRTYPE_ASSERT, 'urls': [], KPISet.RESP_CODES: '111', 'tag': ""}, {'msg': 'Allowed', 'cnt': 20, 'type': KPISet.ERRTYPE_ERROR, 'urls': [], KPISet.RESP_CODES: '222'}] obj.send_monitoring = False obj.post_process() # TODO: looks like this whole block of checks is useless # check for note appending in _postproc_phase3() reqs = [{'url': '', 'data': ''} for _ in range(4)] # add template for minimal size reqs = (reqs + mock.requests)[-4:] self.assertNotIn('api/v4/sessions/1', reqs[0]['url']) self.assertNotIn('api/v4/sessions/1', reqs[1]['url']) self.assertNotIn('api/v4/masters/1', reqs[2]['url']) self.assertNotIn('api/v4/masters/1', reqs[3]['url']) if reqs[1]['data']: self.assertNotIn('ValueError: wrong value', reqs[1]['data']) if reqs[3]['data']: self.assertNotIn('ValueError: wrong value', reqs[3]['data'])
def test_get_errors(self): mock = BZMock() mock.mock_get.update({ 'https://a.blazemeter.com/api/v4/data/labels?master_id=1': { "api_version": 4, "error": None, "result": [{ "sessions": ["r-t-5746a8e38569a"], "id": "ALL", "name": "ALL" }, { "sessions": ["r-t-5746a8e38569a"], "id": "e843ff89a5737891a10251cbb0db08e5", "name": "http://blazedemo.com/" }] }, 'https://a.blazemeter.com/api/v4/data/kpis?interval=1&from=0&master_ids%5B%5D=1&kpis%5B%5D=t&kpis%5B%5D=lt&kpis%5B%5D=by&kpis%5B%5D=n&kpis%5B%5D=ec&kpis%5B%5D=ts&kpis%5B%5D=na&labels%5B%5D=ALL&labels%5B%5D=e843ff89a5737891a10251cbb0db08e5': { "api_version": 4, "error": None, "result": [{ "labelId": "ALL", "labelName": "ALL", "label": "ALL", "kpis": [{ "n": 1, "na": 1, "ec": 0, "p90": 0, "t_avg": 817, "lt_avg": 82, "by_avg": 0, "n_avg": 1, "ec_avg": 0, "ts": 1464248743 }, { "n": 1, "na": 1, "ec": 0, "p90": 0, "t_avg": 817, "lt_avg": 82, "by_avg": 0, "n_avg": 1, "ec_avg": 0, "ts": 1464248744 }] }] }, 'https://a.blazemeter.com/api/v4/masters/1/reports/aggregatereport/data': { "api_version": 4, "error": None, "result": [{ "labelName": "ALL", "99line": 1050, "90line": 836, "95line": 912 }, { "labelName": "http://blazedemo.com", "99line": 1050, "90line": 836, "95line": 912 }] }, 'https://a.blazemeter.com/api/v4/data/kpis?interval=1&from=1464248744&master_ids%5B%5D=1&kpis%5B%5D=t&kpis%5B%5D=lt&kpis%5B%5D=by&kpis%5B%5D=n&kpis%5B%5D=ec&kpis%5B%5D=ts&kpis%5B%5D=na&labels%5B%5D=ALL&labels%5B%5D=e843ff89a5737891a10251cbb0db08e5': { "api_version": 4, "error": None, "result": [{ "labelId": "ALL", "labelName": "ALL", "label": "ALL", "kpis": [{ "n": 1, "na": 1, "ec": 0, "p90": 0, "t_avg": 817, "lt_avg": 82, "by_avg": 0, "n_avg": 1, "ec_avg": 0, "ts": 1464248744 }, { "n": 1, "na": 1, "ec": 0, "p90": 0, "t_avg": 817, "lt_avg": 82, "by_avg": 0, "n_avg": 1, "ec_avg": 0, "ts": 1464248745 }] }] }, 'https://a.blazemeter.com/api/v4/data/kpis?interval=1&from=1464248745&master_ids%5B%5D=1&kpis%5B%5D=t&kpis%5B%5D=lt&kpis%5B%5D=by&kpis%5B%5D=n&kpis%5B%5D=ec&kpis%5B%5D=ts&kpis%5B%5D=na&labels%5B%5D=ALL&labels%5B%5D=e843ff89a5737891a10251cbb0db08e5': { "api_version": 4, "error": None, "result": [{ "labelId": "ALL", "labelName": "ALL", "label": "ALL", "kpis": [{ "n": 1, "na": 1, "ec": 0, "p90": 0, "t_avg": 817, "lt_avg": 82, "by_avg": 0, "n_avg": 1, "ec_avg": 0, "ts": 1464248745 }] }] } }) obj = ResultsFromBZA() obj.master = Master(data={"id": 1}) mock.apply(obj.master) # set cumulative errors from BM mock.mock_get.update( self.get_errors_mock( {'ALL': { "Not found": { "count": 10, "rc": "404" } }})) # frame [0, 1464248744) res1 = list(obj.datapoints(False)) self.assertEqual(1, len(res1)) cumul = res1[0][DataPoint.CUMULATIVE] cur = res1[0][DataPoint.CURRENT] self.assertEqual(1, len(cumul.keys())) self.assertEqual(1, len(cur.keys())) errors_1 = {'Not found': {'count': 10, 'rc': u'404'}} self.assertEqual(self.convert_kpi_errors(cumul[""]["errors"]), errors_1) # all error data is written self.assertEqual(self.convert_kpi_errors(cur[""]["errors"]), errors_1) # to 'current' and 'cumulative' # frame [1464248744, 1464248745) res2 = list(obj.datapoints(False)) self.assertEqual(1, len(res2)) cumul = res2[0][DataPoint.CUMULATIVE] cur = res2[0][DataPoint.CURRENT] self.assertEqual(1, len(cumul.keys())) self.assertEqual(1, len(cur.keys())) self.assertEqual(self.convert_kpi_errors(cumul[""]["errors"]), errors_1) # the same errors, self.assertEqual(cur[""]["errors"], []) # new errors not found mock.mock_get.update( self.get_errors_mock( { "ALL": { "Not found": { "count": 11, "rc": "404" }, # one more error "Found": { "count": 2, "rc": "200" } }, # new error message (error ID) "label1": { "Strange behaviour": { "count": 666, "rc": "666" } } }, { # new error label "ALL": { "assertion_example": { "count": 33 } } })) res3 = list( obj.datapoints(True)) # let's add the last timestamp [1464248745] self.assertEqual(1, len(res3)) cumul = res3[0][DataPoint.CUMULATIVE] cur = res3[0][DataPoint.CURRENT] errors_all_full = { 'Not found': { 'count': 11, 'rc': '404' }, 'Found': { 'count': 2, 'rc': '200' }, 'assertion_example': { 'count': 33, 'rc': 'All Assertions' } } errors_all_update = { 'Not found': { 'count': 1, 'rc': '404' }, 'Found': { 'count': 2, 'rc': '200' }, 'assertion_example': { 'count': 33, 'rc': 'All Assertions' } } errors_label1 = {'Strange behaviour': {'count': 666, 'rc': '666'}} self.assertEqual(errors_label1, self.convert_kpi_errors(cumul["label1"]["errors"])) self.assertEqual(errors_all_full, self.convert_kpi_errors(cumul[""]["errors"])) self.assertEqual(errors_label1, self.convert_kpi_errors(cur["label1"]["errors"])) self.assertEqual(errors_all_update, self.convert_kpi_errors(cur[""]["errors"]))
def test_no_kpis_on_cloud_crash(self): mock = BZMock() mock.mock_get.update({ 'https://a.blazemeter.com/api/v4/data/labels?master_id=0': { "api_version": 2, "error": None, "result": [{ "sessions": ["r-t-5746a8e38569a"], "id": "ALL", "name": "ALL" }, { "sessions": ["r-t-5746a8e38569a"], "id": "e843ff89a5737891a10251cbb0db08e5", "name": "http://blazedemo.com/" }] }, 'https://a.blazemeter.com/api/v4/data/kpis?interval=1&from=0&master_ids%5B%5D=0&kpis%5B%5D=t&kpis%5B%5D=lt&kpis%5B%5D=by&kpis%5B%5D=n&kpis%5B%5D=ec&kpis%5B%5D=ts&kpis%5B%5D=na&labels%5B%5D=ALL&labels%5B%5D=e843ff89a5737891a10251cbb0db08e5': { "api_version": 2, "error": None, "result": [{ "labelId": "ALL", "labelName": "ALL", }] }, 'https://a.blazemeter.com/api/v4/masters/0/reports/aggregatereport/data': { "api_version": 2, "error": None, "result": [{ "labelId": "ALL", "labelName": "ALL", "samples": 152, "avgResponseTime": 786, "90line": 836, "95line": 912, "99line": 1050, "minResponseTime": 531, "maxResponseTime": 1148, "avgLatency": 81, "geoMeanResponseTime": None, "stDev": 108, "duration": 119, "avgBytes": 0, "avgThroughput": 1.2773109243697, "medianResponseTime": 0, "errorsCount": 0, "errorsRate": 0, "hasLabelPassedThresholds": None }, { "labelId": "e843ff89a5737891a10251cbb0db08e5", "labelName": "http://blazedemo.com/", "samples": 152, "avgResponseTime": 786, "90line": 836, "95line": 912, "99line": 1050, "minResponseTime": 531, "maxResponseTime": 1148, "avgLatency": 81, "geoMeanResponseTime": None, "stDev": 108, "duration": 119, "avgBytes": 0, "avgThroughput": 1.2773109243697, "medianResponseTime": 0, "errorsCount": 0, "errorsRate": 0, "hasLabelPassedThresholds": None }] } }) obj = ResultsFromBZA(Master(data={'id': 0})) mock.apply(obj.master) res = list(obj.datapoints(True)) self.assertEqual(res, [])
def test_datapoint(self): mock = BZMock() mock.mock_get.update({ 'https://a.blazemeter.com/api/v4/data/labels?master_id=1': { "api_version": 2, "error": None, "result": [{ "sessions": ["r-t-5746a8e38569a"], "id": "ALL", "name": "ALL" }, { "sessions": ["r-t-5746a8e38569a"], "id": "e843ff89a5737891a10251cbb0db08e5", "name": "http://blazedemo.com/" }] }, 'https://a.blazemeter.com/api/v4/data/kpis?interval=1&from=0&master_ids%5B%5D=1&kpis%5B%5D=t&kpis%5B%5D=lt&kpis%5B%5D=by&kpis%5B%5D=n&kpis%5B%5D=ec&kpis%5B%5D=ts&kpis%5B%5D=na&labels%5B%5D=ALL&labels%5B%5D=e843ff89a5737891a10251cbb0db08e5': { "api_version": 2, "error": None, "result": [{ "labelId": "ALL", "labelName": "ALL", "label": "ALL", "kpis": [{ "n": 1, "na": 1, "ec": 0, "p90": 0, "t_avg": 817, "lt_avg": 82, "by_avg": 0, "n_avg": 1, "ec_avg": 0, "ts": 1464248743 }] }] }, 'https://a.blazemeter.com/api/v4/masters/1/reports/aggregatereport/data': { "api_version": 2, "error": None, "result": [{ "labelId": "ALL", "labelName": "ALL", "samples": 152, "avgResponseTime": 786, "90line": 836, "95line": 912, "99line": 1050, "minResponseTime": 531, "maxResponseTime": 1148, "avgLatency": 81, "geoMeanResponseTime": None, "stDev": 108, "duration": 119, "avgBytes": 0, "avgThroughput": 1.2773109243697, "medianResponseTime": 0, "errorsCount": 0, "errorsRate": 0, "hasLabelPassedThresholds": None }, { "labelId": "e843ff89a5737891a10251cbb0db08e5", "labelName": "http://blazedemo.com/", "samples": 152, "avgResponseTime": 786, "90line": 836, "95line": 912, "99line": 1050, "minResponseTime": 531, "maxResponseTime": 1148, "avgLatency": 81, "geoMeanResponseTime": None, "stDev": 108, "duration": 119, "avgBytes": 0, "avgThroughput": 1.2773109243697, "medianResponseTime": 0, "errorsCount": 0, "errorsRate": 0, "hasLabelPassedThresholds": None }] } }) mock.mock_get.update(self.get_errors_mock({"ALL": {}})) obj = ResultsFromBZA() obj.master = Master(data={"id": 1}) mock.apply(obj.master) res = list(obj.datapoints(True)) cumulative_ = res[0][DataPoint.CUMULATIVE] total = cumulative_[''] percentiles_ = total[KPISet.PERCENTILES] self.assertEquals(1.05, percentiles_['99.0'])