def test_failed_report_data_construction(self): """ Test failed creation of the resulting list """ config = get_common_params(None) config['REPORT_SIZE'] = 'aaa' log_result = {} log_result['statistics'] = {} log_result['requests_number'] = 4 log_result['times'] = { '/api/v1/aaa': [0.01, 0.002], '/api/v2/ccc': [0.005, 115.21] } log_result['requests_data'] = [ { 'url': '/api/v1/aaa' }, { 'url': '/api/v2/ccc' }, ] log_result['common_request_time'] = sum( [sum(v) for k, v in log_result['times'].iteritems()]) results = make_report_data(log_result) data = report_data_array(config, results) self.assertEqual(len(data), 0) config['REPORT_SIZE'] = 100
def test_success_report_data_construction(self): """ Test correct forming of the final scope of logs """ config = get_common_params(None) log_result = {} log_result['statistics'] = {} log_result['requests_number'] = 4 log_result['times'] = { '/api/v1/aaa': [0.01, 0.002], '/api/v2/ccc': [0.005, 115.21] } log_result['requests_data'] = [ { 'url': '/api/v1/aaa' }, { 'url': '/api/v2/ccc' }, ] log_result['common_request_time'] = sum( [sum(v) for k, v in log_result['times'].iteritems()]) results = make_report_data(log_result) data = report_data_array(config, results) self.assertEqual(len(data), 2)
def test_report_url_count(self): """ Test correct value of calculated information for every url """ log_result = {} log_result['statistics'] = {} log_result['requests_number'] = 4 log_result['times'] = { '/api/v1/aaa': [0.01, 0.002], '/api/v2/ccc': [0.005, 115.21] } log_result['requests_data'] = [ { 'url': '/api/v1/aaa' }, { 'url': '/api/v2/ccc' }, ] log_result['common_request_time'] = sum( [sum(v) for k, v in log_result['times'].iteritems()]) results = make_report_data(log_result) self.assertTrue(results['/api/v1/aaa']['count'], 1) self.assertTrue(results['/api/v2/ccc']['count'], 1)
def test_making_report_data(self): """ Test making report data base on request data """ log_result = {} log_result['statistics'] = {} log_result['requests_number'] = 4 log_result['times'] = { '/api/v1/aaa': [0.01, 0.002], '/api/v2/ccc': [0.005, 115.21] } log_result['requests_data'] = [ { 'url': '/api/v1/aaa' }, { 'url': '/api/v2/ccc' }, ] log_result['common_request_time'] = sum( [sum(v) for k, v in log_result['times'].iteritems()]) results = make_report_data(log_result) self.assertIsNotNone(results)
def test_report_result_by_url_containing(self): """ Test report by containing all the necessary urls """ log_result = {} log_result['statistics'] = {} log_result['requests_number'] = 4 log_result['times'] = { '/api/v1/aaa': [0.01, 0.002], '/api/v2/ccc': [0.005, 115.21] } log_result['requests_data'] = [ { 'url': '/api/v1/aaa' }, { 'url': '/api/v2/ccc' }, ] log_result['common_request_time'] = sum( [sum(v) for k, v in log_result['times'].iteritems()]) results = make_report_data(log_result) self.assertTrue('/api/v1/aaa' in results) self.assertTrue('/api/v2/ccc' in results)