From: Patrick Seidensal Date: Thu, 27 Feb 2020 08:19:42 +0000 (+0100) Subject: mgr/dashboard: fix stray requests/error in Grafana unit test X-Git-Tag: v15.1.1~181^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=de804a9126bc107addf3ddb21ec513cb169f1213;p=ceph-ci.git mgr/dashboard: fix stray requests/error in Grafana unit test Fixes: https://tracker.ceph.com/issues/44317 Signed-off-by: Patrick Seidensal --- diff --git a/src/pybind/mgr/dashboard/tests/test_grafana.py b/src/pybind/mgr/dashboard/tests/test_grafana.py index 02597dfe36c..0eb46bf0f00 100644 --- a/src/pybind/mgr/dashboard/tests/test_grafana.py +++ b/src/pybind/mgr/dashboard/tests/test_grafana.py @@ -6,6 +6,8 @@ try: except ImportError: from unittest.mock import patch +from requests import RequestException + from . import ControllerTestCase, KVStoreMockMixin from ..controllers.grafana import Grafana from ..grafana import GrafanaRestClient @@ -41,23 +43,32 @@ class GrafanaTest(ControllerTestCase, KVStoreMockMixin): self.assertStatus(200) self.assertJsonBody({'instance': 'http://localhost:3000'}) - def test_validation(self): + @patch('dashboard.controllers.grafana.GrafanaRestClient.url_validation') + def test_validation_endpoint_returns(self, url_validation): + """ + The point of this test is to see that `validation` is an active endpoint that returns a 200 + status code. + """ + url_validation.return_value = b'404' self.server_settings() self._get('/api/grafana/validation/foo') - self.assertStatus(500) + self.assertStatus(200) + self.assertBody(b'"404"') def test_dashboards_unavailable_no_url(self): - self.server_settings(url=None) + self.server_settings(url="") self._post('/api/grafana/dashboards') self.assertStatus(500) - def test_dashboards_unavailable_no_user(self): - self.server_settings(user=None) + @patch('dashboard.controllers.grafana.GrafanaRestClient.push_dashboard') + def test_dashboards_unavailable_no_user(self, pd): + pd.side_effect = RequestException + self.server_settings(user="") self._post('/api/grafana/dashboards') self.assertStatus(500) def test_dashboards_unavailable_no_password(self): - self.server_settings(password=None) + self.server_settings(password="") self._post('/api/grafana/dashboards') self.assertStatus(500)