python-jenkins/tests/test_rest_endpoints.py
JP Sullivan f1f97ab4bf Update URLS that require depth or tree filters
Some API endpoints require the use of a filter or they will respond
with HTTP error code 418 I'm a teapot.

This was seen on CloudBees Jenkins Enterprise 2.107.2.1-rolling.

Adding a depth filter will ensure the API calls will succeed.

Change-Id: Ib4d6a251bf3a024a76081b2fc83baa7839ad4015
2018-05-28 10:17:26 +01:00

40 lines
1.4 KiB
Python

import jenkins
from tests.base import JenkinsTestBase
# Vars in the jenkins module scope that do not need validating
VAR_WHITELIST = ['__doc__',
'__file__',
'__name__',
'__package__',
'CRUMB_URL',
'DEFAULT_HEADERS',
'EMPTY_CONFIG_XML',
'EMPTY_FOLDER_XML',
'EMPTY_PROMO_CONFIG_XML',
'EMPTY_VIEW_CONFIG_XML',
'INFO',
'LAUNCHER_SSH',
'LAUNCHER_COMMAND',
'LAUNCHER_JNLP',
'LAUNCHER_WINDOWS_SERVICE',
'NODE_TYPE',
'PROMO_RECONFIG_XML',
'RECONFIG_XML']
class JenkinsRestTest(JenkinsTestBase):
# If there is no filter (depth or tree) we will get an exception
# on some Jenkins instances
def test_url_has_filter(self):
for var in dir(jenkins):
if var in VAR_WHITELIST:
continue
# Misses unicode on 2.x
val = getattr(jenkins, var)
if isinstance(val, str):
# If we end the path in api/json and don't have depth or tree encoded, fail
self.assertEqual(val.endswith('api/json'), False,
"URLS that end in 'api/json' must be called with depth or tree:" +
"var: [{}] val: [{}]".format(var, val))