Actions
Bug #44317
closedmgr/dashboard: backend Grafana unit test error
Status:
Resolved
Priority:
Normal
Assignee:
Category:
Testing & QA
Target version:
% Done:
0%
Source:
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Description
Some of the Grafana Unit Test in the backend are not using mocks properly and don't prevent requests being made to a configured HTTP address. In fact, it is required for the tests to pass, that no service is running on this address (`http://localhost:3000`). If a service is available at that port (usually a Grafana instance), the tests will fail:
tests/test_grafana.py ....F __________________________________________________________ GrafanaTest.test_validation ___________________________________________________________ self = <dashboard.tests.test_grafana.GrafanaTest testMethod=test_validation> def test_validation(self): self.server_settings() self._get('/api/grafana/validation/foo') > self.assertStatus(500) tests/test_grafana.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .tox/py3/lib/python3.6/site-packages/cheroot/test/webtest.py:325: in assertStatus self._handlewebError(msg) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <dashboard.tests.test_grafana.GrafanaTest testMethod=test_validation>, msg = 'Status 200 OK does not match 500' def _handlewebError(self, msg): print('') print(' ERROR: %s' % msg) if not self.interactive: > raise self.failureException(msg) E AssertionError: Status 200 OK does not match 500 .tox/py3/lib/python3.6/site-packages/cheroot/test/webtest.py:257: AssertionError -------------------------------------------------------------- Captured stdout call -------------------------------------------------------------- ERROR: Status 200 OK does not match 500 -------------------------------------------------------------- Captured stderr call -------------------------------------------------------------- DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:3000 DEBUG:urllib3.connectionpool:http://localhost:3000 "GET /api/dashboards/uid/foo HTTP/1.1" 501 496 INFO:cherrypy.access.140271818942672:127.0.0.1 - - [27/Feb/2020:09:14:55] "GET /api/grafana/validation/foo HTTP/1.1" 200 3 "" "" --------------------------------------------------------------- Captured log call ----------------------------------------------------------------
It should be ensured that no requests whatsoever are made from the backend that target external URLs.
How to reproduce¶
- Run `python3 -c 'from http import server; s = server.HTTPServer(("", 3000), server.BaseHTTPRequestHandler); s.serve_forever()'` on the host where the unit test will run.
- Run the unit test.
- Observe stray requests being made, which are relied upon to not respond and hence result in failing tests.
user@work ~ » python3 -c 'from http import server; s = server.HTTPServer(("", 3000), server.BaseHTTPRequestHandler); s.serve_forever()' 130 ↵ 127.0.0.1 - - [27/Feb/2020 09:14:55] code 501, message Unsupported method ('POST') 127.0.0.1 - - [27/Feb/2020 09:14:55] "POST /api/dashboards/db HTTP/1.1" 501 - 127.0.0.1 - - [27/Feb/2020 09:14:55] code 501, message Unsupported method ('POST') 127.0.0.1 - - [27/Feb/2020 09:14:55] "POST /api/dashboards/db HTTP/1.1" 501 - 127.0.0.1 - - [27/Feb/2020 09:14:55] code 501, message Unsupported method ('GET') 127.0.0.1 - - [27/Feb/2020 09:14:55] "GET /api/dashboards/uid/foo HTTP/1.1" 501 -
Actions