forked from ramonvanalteren/jenkinsapi-old
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interim commit - I'm part way through refactoring all the networking …
…stuff. Posts are not yet working.
- Loading branch information
1 parent
b36d9df
commit 6a5505a
Showing
10 changed files
with
155 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from jenkinsapi.jenkins import Jenkins | ||
J = Jenkins('http://localhost:8080') | ||
|
||
EMPTY_JOB_CONFIG = '''\ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<project> | ||
<actions/> | ||
<description></description> | ||
<keepDependencies>false</keepDependencies> | ||
<properties/> | ||
<scm class="hudson.scm.NullSCM"/> | ||
<canRoam>true</canRoam> | ||
<disabled>false</disabled> | ||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> | ||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> | ||
<triggers class="vector"/> | ||
<concurrentBuild>false</concurrentBuild> | ||
<builders/> | ||
<publishers/> | ||
<buildWrappers/> | ||
</project> | ||
''' | ||
|
||
new_job = J.create_job(jobname='foo_job', config=EMPTY_JOB_CONFIG) | ||
|
||
j= J['foo_job'] | ||
print j |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import StringIO | ||
import requests | ||
|
||
class Requester(object): | ||
|
||
""" | ||
A class which carries out HTTP requests. You can replace this class with one of your own implementation if you require | ||
some other way to access Jenkins. | ||
This default class can handle simple authentication only. | ||
""" | ||
|
||
def __init__(self, username=None, password=None): | ||
if username: | ||
assert password, 'Cannot set a username without a password!' | ||
|
||
self.username = None | ||
self.password = None | ||
|
||
def hit_url(self, url, params=None, data=None, headers=None): | ||
requestKwargs = {} | ||
if self.username: | ||
requestKwargs['auth'] = (self.username, self.password) | ||
|
||
if params: | ||
assert isinstance(params, dict), 'Params must be a dict, got %s' % repr(params) | ||
requestKwargs['params'] = params | ||
|
||
if headers: | ||
assert isinstance(headers, dict), 'headers must be a dict, got %s' % repr(headers) | ||
requestKwargs['headers'] = headers | ||
|
||
if data: | ||
requestKwargs['data'] = data | ||
response = requests.post(url, **requestKwargs) | ||
else: | ||
response = requests.get(url, **requestKwargs) | ||
|
||
import ipdb; ipdb.set_trace() | ||
|
||
return response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,4 @@ def setUpPackage(): | |
|
||
|
||
def tearDownPackage(): | ||
launcher.stop() | ||
launcher.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import mock | ||
import unittest | ||
import datetime | ||
|
||
from jenkinsapi.jenkins import Jenkins | ||
|
||
class TestJenkins(unittest.TestCase): | ||
|
||
DATA = {} | ||
|
||
@mock.patch.object(Jenkins, '_poll') | ||
def setUp(self, _poll): | ||
_poll.return_value = self.DATA | ||
self.J = Jenkins('http://localhost:8080', username='foouser', password='foopassword') | ||
|
||
def testClone(self): | ||
JJ = self.J._clone() | ||
self.assertNotEquals(id(JJ), id(self.J)) | ||
self.assertEquals(JJ, self.J) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.