Ejemplo n.º 1
0
 def test_get_recent_failed_runs_rss_no_failure_valid_meta(self, count_mock,
                                                           db_mock):
     api.rss_opts['data_dir'] = tempfile.gettempdir()
     api.rss_opts['frontend_url'] = 'http://status.openstack.org'
     build_uuid = str(uuid.uuid4())
     meta_mock = mock.patch(
         'subunit2sql.db.api.get_run_metadata',
         return_value=[
             models.RunMetadata(key='build_name', value='job'),
             models.RunMetadata(key='build_uuid', value=build_uuid)])
     meta_mock.start()
     self.addCleanup(meta_mock.stop)
     res = self.app.get('/runs/key/b_key/b_value/recent/rss')
     self.assertEqual(200, res.status_code)
     db_mock.assert_called_once_with('b_key', 'b_value',
                                     start_date=None, session=api.Session())
     count_mock.assert_called_once_with('b_key', 'b_value',
                                        session=api.Session())
     db_mock.reset_mock()
     count_mock.reset_mock()
     out = feedparser.parse(res.data.decode('utf-8'))
     title = 'Failures for %s: %s' % ('b_key', 'b_value')
     self.assertEqual(title, out['feed']['title'])
     self.assertEqual('en', out['feed']['language'])
     self.assertEqual(0, len(out.entries))
Ejemplo n.º 2
0
 def test_get_recent_test_failures_with_missing_meta(self, meta_mock,
                                                     db_mock, recent_mock):
     setup_mock = mock.patch('openstack_health.api.setup')
     setup_mock.start()
     self.addCleanup(setup_mock.stop)
     api.region = mock.MagicMock()
     api.region.cache_on_arguments = mock.MagicMock()
     api.region.cache_on_arguments.return_value = lambda x: x
     api.classifier = mock.MagicMock()
     api.classifier.classify = mock.MagicMock()
     api.classifier.classify.return_value = ['12345']
     res = self.app.get('/tests/recent/fail')
     self.assertEqual(200, res.status_code)
     self.assertEqual(0, api.classifier.classify.call_count)
     db_mock.assert_called_once_with('fail', ['a_convincing_id'],
                                     session=api.Session(),
                                     include_run_id=True)
     response_data = json.loads(res.data.decode('utf-8'))
     expected_resp = {
         'bugs': {},
         'test_runs': [{
             'test_id': u'fake_test',
             'link': u'fake_url',
             'start_time': timestamp_a.isoformat(),
             'stop_time': timestamp_b.isoformat(),
         }]}
     self.assertEqual(expected_resp, response_data)
Ejemplo n.º 3
0
 def test_get_test_runs_for_test(self, api_mock):
     setup_mock = mock.patch('openstack_health.api.setup')
     setup_mock.start()
     self.addCleanup(setup_mock.stop)
     api.classifier = None
     api.region = mock.MagicMock()
     api.region.cache_on_arguments = mock.MagicMock()
     api.region.cache_on_arguments.return_value = lambda x: x
     res = self.app.get('/test_runs/fake.test.id')
     self.assertEqual(200, res.status_code)
     exp_result = {'data': {
         timestamp_a.isoformat(): {
             'run_id': 1234,
             'status': 'success',
         }}, 'numeric': {
         timestamp_a.isoformat(): {
             'avg_run_time': numpy.NaN,
             'run_time': 1.0,
             'std_dev_run_time': numpy.NaN
         }}, 'failed_runs': []
     }
     response_data = json.loads(res.data.decode('utf-8'))
     numpy.testing.assert_equal(exp_result, response_data)
     api_mock.assert_called_once_with('fake.test.id', start_date=None,
                                      stop_date=None,
                                      session=api.Session())
Ejemplo n.º 4
0
    def test_get_runs_by_project_resolution_day(self, api_mock):
        query = 'datetime_resolution=day'
        res = self.app.get('/runs/key/project/openstack/trove?{0}'
                           .format(query))

        self.assertEqual(200, res.status_code)

        expected_response_data = {'timedelta': [
            {'datetime': timestamp_d1.date().isoformat(),
             'job_data': [{'pass': 1,
                           'fail': 1,
                           'job_name': 'value-1',
                           'mean_run_time': 5.0},
                          {'pass': 0,
                           'fail': 1,
                           'job_name': 'value-2',
                           'mean_run_time': 2.0},
                          ]},
            {'datetime': timestamp_d2.date().isoformat(),
             'job_data': [{'pass': 1,
                           'fail': 0,
                           'job_name': 'value-3',
                           'mean_run_time': 20.0},
                          ]}
        ]}
        response_data = json.loads(res.data.decode('utf-8'))

        self.assertEqual(expected_response_data, response_data)
        api_mock.assert_called_once_with('project',
                                         'openstack/trove',
                                         None,
                                         None,
                                         api.Session())
Ejemplo n.º 5
0
 def test_get_run_metadata_keys(self, api_mock):
     res = self.app.get('/runs/metadata/keys')
     self.assertEqual(200, res.status_code)
     api_mock.assert_called_once_with(api.Session())
     expected_response = [
         u'build_name',
         u'project',
         u'build_uuid'
     ]
     self.assertItemsEqual(expected_response,
                           json.loads(res.data.decode('utf-8')))
Ejemplo n.º 6
0
 def test_get_runs_by_date_explicit_sec_res(self, api_mock):
     res = self.app.get('/runs/group_by/project?datetime_resolution=sec')
     self.assertEqual(200, res.status_code)
     expected_response = {u'runs': {
         six.text_type(timestamp_a.isoformat()): [{
             u'pass': 2, u'fail': 3, u'skip': 1
         }]
     }}
     self.assertEqual(expected_response,
                      json.loads(res.data.decode('utf-8')))
     # Ensure db api called correctly
     api_mock.assert_called_once_with('project', None, None, api.Session())
Ejemplo n.º 7
0
 def test_get_recent_runs_detail(self, api_mock, api_meta_mock):
     api.Session = mock.MagicMock()
     res = self.app.get('/runs/key/a_key/a_value/recent/detail')
     self.assertEqual(200, res.status_code)
     api_mock.assert_called_once_with('a_key', 'a_value',
                                      10, api.Session())
     response_data = json.loads(res.data.decode('utf-8'))
     format_time = timestamp_a.strftime('%a, %d %b %Y %H:%M:%S GMT')
     expected_res = [{
         u'artifacts': u'http://fake_url',
         u'id': u'a_id',
         u'build_name': u'job',
         u'fails': 0,
         u'passes': 2,
         u'skips': 10,
         u'run_at': format_time,
         u'run_time': 174,
         u'uuid': u'uuid'
     }]
     self.assertEqual(expected_res, response_data)
Ejemplo n.º 8
0
 def test_get_recent_runs(self, api_mock, api_meta_mock):
     res = self.app.get('/runs/key/a_key/a_value/recent')
     self.assertEqual(200, res.status_code)
     api_mock.assert_called_once_with('a_key', 'a_value',
                                      10, api.Session())
     response_data = json.loads(res.data.decode('utf-8'))
     expected_res = [{
         u'id': u'a_uuid',
         u'build_name': u'job',
         u'start_date': timestamp_a.isoformat(),
         u'link': u'http://fake_url',
         u'status': 'success'
     }, {
         u'id': u'b_uuid',
         u'build_name': u'job',
         u'start_date': timestamp_b.isoformat(),
         u'link': u'http://less_fake_url',
         u'status': 'fail'
     }]
     self.assertEqual(expected_res, response_data)
Ejemplo n.º 9
0
 def test_get_test_runs_by_build_name(self, api_mock):
     api.region = mock.MagicMock()
     api.region.cache_on_arguments = mock.MagicMock()
     api.region.cache_on_arguments.return_value = lambda x: x
     res = self.app.get('/build_name/fake_tests/test_runs')
     self.assertEqual(200, res.status_code)
     api_mock.assert_called_once_with('build_name', 'fake_tests', None,
                                      None, api.Session())
     expected_response = {
         six.text_type(timestamp_a.isoformat()): {
             u'fake_test_a': {
                 u'pass': 1,
                 u'fail': 0,
                 u'skip': 0,
                 u'run_time': 1},
             u'fake_test_b': {
                 u'pass': 0,
                 u'fail': 1,
                 u'skip': 0,
                 u'run_time': 0},
         }
     }
     self.assertEqual({u'tests': expected_response},
                      json.loads(res.data.decode('utf-8')))