python-jenkins/tests/base.py
Darragh Bailey 34cca0c4d9 Migration to using requests
Convert to the requests library to allow for more sophisticated response
handling to be added.

Want to allow for applications to override the response handling in
certain cases where the default is incorrect. Handling of urlopen
responses results in version specific handling to ensure correct
behaviour across multiple versions of python.

Changing to use the requests package, provides a higher level interface
and removes some of the version specific handling for exceptions.

Change-Id: I5369a0d35be4bf8b3b197a51e60aba21b5742cc7
Depends-On: Iabd70aa457ceb4dbc147d7cbaeec913148cb3b56
2018-02-12 11:16:54 +00:00

39 lines
921 B
Python

import sys
from testscenarios import TestWithScenarios
import jenkins
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
class JenkinsTestBase(TestWithScenarios, unittest.TestCase):
crumb_data = {
"crumb": "dab177f483b3dd93483ef6716d8e792d",
"crumbRequestField": ".crumb",
}
scenarios = [
('base_url1', dict(base_url='http://example.com')),
('base_url2', dict(base_url='http://example.com/jenkins'))
]
def setUp(self):
super(JenkinsTestBase, self).setUp()
# TODO(darragh) would be useful if this could be mocked
jenkins.requests_kerberos = None
self.j = jenkins.Jenkins(self.base_url, 'test', 'test')
def make_url(self, path):
return u'{0}/{1}'.format(self.base_url, path)
def _check_requests(self, requests):
for req in requests:
req[0][0].prepare()