Modify the expected HTTP status code for unauthorized InfluxDB query

The status code differs with InfluxDB version 0.11 vs 1.1.

Change-Id: I24a6b8980bf513d6b85112f77899a087e85a5cca
This commit is contained in:
Swann Croiset 2017-01-13 09:52:09 +01:00
parent 27639b433a
commit e0bfdb76dd
2 changed files with 11 additions and 5 deletions

View File

@ -38,8 +38,8 @@ def check_http_get_response(url, expected_code=200, msg=None, **kwargs):
:param url: the requested URL :param url: the requested URL
:type url: str :type url: str
:param expected_code: the expected HTTP response code. Defaults to 200 :param expected_code: the expected HTTP response code(s). Defaults to 200
:type expected_code: int :type expected_code: list(int) or int
:param msg: the assertion message. Defaults to None :param msg: the assertion message. Defaults to None
:type msg: str :type msg: str
:returns: HTTP response object :returns: HTTP response object
@ -50,8 +50,12 @@ def check_http_get_response(url, expected_code=200, msg=None, **kwargs):
cert = helpers.get_fixture("https/rootCA.pem") cert = helpers.get_fixture("https/rootCA.pem")
msg = msg or "%s responded with {0}, expected {1}" % url msg = msg or "%s responded with {0}, expected {1}" % url
r = s.get(url, verify=cert, **kwargs) r = s.get(url, verify=cert, **kwargs)
asserts.assert_equal( if isinstance(expected_code, int):
r.status_code, expected_code, msg.format(r.status_code, expected_code)) expected_code = [expected_code]
asserts.assert_true(
r.status_code in expected_code,
msg.format(r.status_code, expected_code))
return r return r

View File

@ -107,7 +107,9 @@ class InfluxdbPluginApi(base_test.PluginApi):
self.do_influxdb_query("show measurements") self.do_influxdb_query("show measurements")
logger.info("Check that the InfluxDB user doesn't have admin rights") logger.info("Check that the InfluxDB user doesn't have admin rights")
self.do_influxdb_query("show stats", expected_code=401)
# 401 is for InfluxDB 0.11 and 403 for InfluxDB 1.1
self.do_influxdb_query("show stats", expected_code=[401, 403])
logger.info("Check that the InfluxDB root user has admin rights") logger.info("Check that the InfluxDB root user has admin rights")
self.do_influxdb_query("show stats", self.do_influxdb_query("show stats",