本文整理汇总了Python中jenkinsapi.utils.requester.Requester类的典型用法代码示例。如果您正苦于以下问题:Python Requester类的具体用法?Python Requester怎么用?Python Requester使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Requester类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_new_job_fail
def test_create_new_job_fail(self, _base_poll, _poll, _job_poll):
_job_poll.return_value = {}
_poll.return_value = {
'jobs': [
{'name': 'job_one',
'url': 'http://localhost:8080/job_one',
'color': 'blue'},
{'name': 'job_one',
'url': 'http://localhost:8080/job_one',
'color': 'blue'},
]
}
_base_poll.return_value = _poll.return_value
mock_requester = Requester(username='foouser', password='foopassword')
mock_requester.post_xml_and_confirm_status = mock.MagicMock(
return_value='')
J = Jenkins('http://localhost:8080/',
username='foouser', password='foopassword',
requester=mock_requester)
with self.assertRaises(JenkinsAPIException) as ar:
J.create_job('job_new', None)
self.assertEquals(str(ar.exception), 'Cannot create job job_new')
示例2: test_reload
def test_reload(self, _poll):
mock_requester = Requester(username='foouser', password='foopassword')
mock_requester.get_url = mock.MagicMock(return_value='')
J = Jenkins('http://localhost:8080/',
username='foouser', password='foopassword',
requester=mock_requester)
J.poll()
示例3: test_get_jenkins_obj_from_url
def test_get_jenkins_obj_from_url(self, _base_poll, _poll, _job_poll):
_job_poll.return_value = {}
_poll.return_value = {
'jobs': [
{'name': 'job_one',
'url': 'http://localhost:8080/job_one',
'color': 'blue'},
{'name': 'job_one',
'url': 'http://localhost:8080/job_one',
'color': 'blue'},
]
}
_base_poll.return_value = _poll.return_value
mock_requester = Requester(username='foouser', password='foopassword')
mock_requester.post_xml_and_confirm_status = mock.MagicMock(
return_value='')
J = Jenkins('http://localhost:8080/',
username='foouser', password='foopassword',
requester=mock_requester)
new_jenkins = J.get_jenkins_obj_from_url('http://localhost:8080/')
self.assertEquals(new_jenkins, J)
new_jenkins = J.get_jenkins_obj_from_url('http://localhost:8080/foo')
self.assertNotEquals(new_jenkins, J)
示例4: test_get_request_dict_wrong_headers
def test_get_request_dict_wrong_headers(self):
req = Requester('foo', 'bar')
with self.assertRaises(AssertionError) as na:
req_return = req.get_request_dict(url='http://', params={},
data=None, headers='wrong')
self.assertTrue(
na.exception.message=="headers must be a dict, got 'wrong'")
示例5: test_get_request_dict_auth
def test_get_request_dict_auth(self):
req = Requester('foo', 'bar')
req_return = req.get_request_dict(url='http://', params={}, data=None,
headers=None)
self.assertTrue(isinstance(req_return, dict))
self.assertTrue(req_return.get('auth'))
self.assertTrue(req_return['auth']==('foo', 'bar'))
示例6: test_get_and_confirm_status
def test_get_and_confirm_status(self, _get):
response = requests.Response()
response.status_code = 200
_get.return_value = response
req = Requester('foo', 'bar')
ret = req.get_and_confirm_status(
url='http://dummy',
params={'param': 'value'})
self.assertTrue(isinstance(ret, requests.Response))
示例7: test_get_request_dict_data_not_passed
def test_get_request_dict_data_not_passed(self):
req = Requester('foo', 'bar')
req_return = req.get_request_dict(url='http://',
params={'param': 'value'},
data=None, headers={'header': 'value'})
self.assertTrue(isinstance(req_return, dict))
self.assertFalse(req_return.get('data'))
示例8: test_post_xml_and_confirm_status_empty_xml
def test_post_xml_and_confirm_status_empty_xml(self, _post):
_post.return_value = 'SUCCESS'
req = Requester('foo', 'bar')
with self.assertRaises(AssertionError) as ae:
req.post_xml_and_confirm_status(
url='http://dummy',
params={'param': 'value'},
data=None)
self.assertTrue(ae.exception.message=="Unexpected type of parameter 'data': <type 'NoneType'>. Expected (str, dict)")
示例9: test_get_request_dict_correct_headers
def test_get_request_dict_correct_headers(self):
req = Requester('foo', 'bar')
req_return = req.get_request_dict(url='http://',
params={'param': 'value'},
data=None, headers={'header': 'value'})
self.assertTrue(isinstance(req_return, dict))
self.assertTrue(req_return.get('headers'))
self.assertTrue(req_return['headers']=={'header': 'value'})
示例10: test_post_and_confirm_status_some_data
def test_post_and_confirm_status_some_data(self, _post):
response = requests.Response()
response.status_code = 200
_post.return_value = response
req = Requester('foo', 'bar')
ret = req.post_and_confirm_status(
url='http://dummy',
params={'param': 'value'},
data='some data')
self.assertTrue(isinstance(ret, requests.Response))
示例11: test_get_request_dict_data_passed
def test_get_request_dict_data_passed(self):
req = Requester('foo', 'bar')
req_return = req.get_request_dict(url='http://',
params={'param': 'value'},
data='some data', headers={'header': 'value'})
self.assertTrue(isinstance(req_return, dict))
print req_return.get('data')
self.assertTrue(req_return.get('data'))
self.assertTrue(req_return['data']=='some data')
示例12: test_get_version_nonexistent
def test_get_version_nonexistent(self, _base_poll, _poll):
class MockResponse(object):
def __init__(self):
self.headers = {}
base_url = 'http://localhost:8080'
mock_requester = Requester(username='foouser', password='foopassword')
mock_requester.get_and_confirm_status = mock.MagicMock(return_value=MockResponse())
J = Jenkins(base_url,
username='foouser', password='foopassword',
requester=mock_requester)
self.assertEquals('0.0', J.version)
示例13: test_get_and_confirm_status_bad_result
def test_get_and_confirm_status_bad_result(self, _get):
response = requests.Response()
response.status_code = 500
_get.return_value = response
req = Requester('foo', 'bar')
with self.assertRaises(JenkinsAPIException) as ae:
req.get_and_confirm_status(
url='http://dummy',
params={'param': 'value'})
print ae.exception.message
self.assertTrue(ae.exception.message=="Operation failed. url=None, headers=None, status=500, text=")
示例14: test_post_and_confirm_status_bad_result
def test_post_and_confirm_status_bad_result(self, _post):
response = requests.Response()
response.status_code = 500
_post.return_value = response
req = Requester('foo', 'bar')
with self.assertRaises(JenkinsAPIException) as ae:
req.post_and_confirm_status(
url='http://dummy',
params={'param': 'value'},
data='some data')
print ae.exception.message
self.assertTrue(ae.exception.message=="Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=")
示例15: test_create_new_job
def test_create_new_job(self, _poll, _job_poll):
_job_poll.return_value = {}
mock_requester = Requester(username='foouser', password='foopassword')
mock_requester.post_xml_and_confirm_status = mock.MagicMock(return_value='')
J = Jenkins('http://localhost:8080/',
username='foouser', password='foopassword',
requester=mock_requester)
job = J.create_job('job_new', None)
self.assertTrue(isinstance(job, Job))
self.assertTrue(job.baseurl == 'http://localhost:8080/job_new')
self.assertTrue(job.name == 'job_new')