def test_to_much_unnamed_parameters_raises_error(): with pytest.raises(Exception): Requester('foo', 'bar', False, 'foobar', 'http://dummy', 5, 'test')
def test_get_request_dict_wrong_headers(): req = Requester('foo', 'bar') with pytest.raises(AssertionError) as na: req.get_request_dict(params={}, data=None, headers='wrong') assert "headers must be a dict, got 'wrong'" in str(na.value)
def test_get_request_dict_nocookie(): req = Requester('foo', 'bar') req_return = req.get_request_dict(params={}, data=None, headers=None) assert isinstance(req_return, dict) assert not req_return.get('headers')
def test_password_without_username_raises_error(): with pytest.raises(AssertionError): Requester(password='******')
def test_username_without_password_raises_error(): with pytest.raises(Exception): Requester(username='******') Requester('foo')
import jenkinsapi from jenkinsapi.jenkins import Requester from jenkinsapi.jenkins import Jenkins from pprint import pprint import base64, os, ConfigParser cp = ConfigParser.ConfigParser() cp.read(os.path.expanduser('~/.jenkins')) cfg = dict(cp.items('api')) if not cfg.has_key('password'): cfg['password'] = base64.decodestring(cfg['xpassword']) # API docs say this should work, too. It does not. # cfg['password']=cfg['token'] j = Jenkins(cfg['baseurl'], username=cfg['username'], password=cfg['password'], requester=Requester(cfg['username'], cfg['password'], baseurl=cfg['baseurl'], ssl_verify=False)) print(cfg['baseurl']) for nodename in ('new-mac-builder', 'Solid Gear Mac'): print(" node %s is" % nodename), node = j.get_node(nodename) if node.is_idle(): print(" idle"), if node.is_online(): print(" online"), if node.is_temporarily_offline(): print(" offline"), print(".")