--- /dev/null
+'''
+System tests for `jenkinsapi.jenkins` module.
+'''
+import time
+import logging
+import unittest
+from jenkinsapi.queue import Queue
+from jenkinsapi_tests.systests.base import BaseSystemTest
+from jenkinsapi_tests.test_utils.random_strings import random_string
+
+log = logging.getLogger(__name__)
+
+JOB_XML = """
+<?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>
+ <hudson.tasks.Shell>
+ <command>ping -c 100 localhost</command>
+ </hudson.tasks.Shell>
+ </builders>
+ <publishers/>
+ <buildWrappers/>
+</project>""".strip()
+
+
+class TestQueue(BaseSystemTest):
+
+ def test_get_queue(self):
+ q = self.jenkins.get_queue()
+ self.assertIsInstance(q, Queue)
+
+ def test_invoke_job_parameterized(self):
+ job_names = [random_string() for i in range(5)]
+ jobs = []
+
+ for job_name in job_names:
+ j = self.jenkins.create_job(job_name, JOB_XML)
+ jobs.append(j)
+ j.invoke()
+
+ queue = self.jenkins.get_queue()
+ reprString = repr(queue)
+ self.assertIn(queue.baseurl, reprString)
+
+
+if __name__ == '__main__':
+ logging.basicConfig()
+ unittest.main()
import mock
import unittest
-import datetime
-import urllib2
-from jenkinsapi.jenkins import Jenkins, JenkinsBase, View, Job
+from jenkinsapi.jenkins import Jenkins, JenkinsBase, Job
from jenkinsapi.utils.requester import Requester
-from jenkinsapi.exceptions import UnknownJob, NotAuthorized, JenkinsAPIException
-
+from jenkinsapi.exceptions import JenkinsAPIException
class TestJenkins(unittest.TestCase):
self.assertEquals(
J.get_create_url(), 'http://localhost:8080/createItem')
- @mock.patch.object(Jenkins, '_poll')
- def test_get_base_server_url(self, _poll):
- _poll.return_value = {}
- J = Jenkins('http://localhost:8080/',
- username='foouser', password='foopassword')
- self.assertEquals(J.baseurl, 'http://localhost:8080')
- self.assertEquals(
- J.get_base_server_url(), 'http://localhost:8080')
-
-
if __name__ == '__main__':
unittest.main()
--- /dev/null
+import mock
+import unittest
+
+from collections import defaultdict
+from jenkinsapi.jenkins import Jenkins
+from jenkinsapi.queue import Queue, QueueItem
+from jenkinsapi.jenkinsbase import JenkinsBase
+from jenkinsapi.job import Job
+
+class FourOhFourError(Exception):
+ """
+ Missing fake data
+ """
+
+class TestQueue(unittest.TestCase):
+
+ @classmethod
+ def mockGetData(self, url):
+ try:
+ return TestQueue.URL_DATA[url]
+ except KeyError:
+ raise FourOhFourError(url)
+
+ URL_DATA = {}
+
+ URL_DATA['http://localhost:8080/api/python/'] = \
+ {'jobs':[
+ {'name':'utmebvpxrw',
+ 'url':'http://localhost/job/utmebvpxrw'}
+ ]
+ }
+
+ URL_DATA['http://localhost/job/utmebvpxrw/api/python/'] = \
+ {}
+
+
+ URL_DATA['http://localhost:8080/queue/api/python/'] = \
+ {'items': [{'actions': [{'causes': [{'shortDescription': 'Started by user anonymous',
+ 'userId': None,
+ 'userName': 'anonymous'}]}],
+ 'blocked': False,
+ 'buildable': True,
+ 'buildableStartMilliseconds': 1371419916747,
+ 'id': 42,
+ 'inQueueSince': 1371419909428,
+ 'params': '',
+ 'stuck': False,
+ 'task': {'color': 'grey',
+ 'name': 'klscuimkqo',
+ 'url': 'http://localhost:8080/job/klscuimkqo/'},
+ 'why': 'Waiting for next available executor'},
+ {'actions': [{'causes': [{'shortDescription': 'Started by user anonymous',
+ 'userId': None,
+ 'userName': 'anonymous'}]}],
+ 'blocked': False,
+ 'buildable': True,
+ 'buildableStartMilliseconds': 1371419911747,
+ 'id': 41,
+ 'inQueueSince': 1371419906327,
+ 'params': '',
+ 'stuck': False,
+ 'task': {'color': 'grey',
+ 'name': 'vluyhzzepl',
+ 'url': 'http://localhost:8080/job/vluyhzzepl/'},
+ 'why': 'Waiting for next available executor'},
+ {'actions': [{'causes': [{'shortDescription': 'Started by user anonymous',
+ 'userId': None,
+ 'userName': 'anonymous'}]}],
+ 'blocked': False,
+ 'buildable': True,
+ 'buildableStartMilliseconds': 1371419911747,
+ 'id': 40,
+ 'inQueueSince': 1371419903212,
+ 'params': '',
+ 'stuck': False,
+ 'task': {'color': 'grey',
+ 'name': 'utmebvpxrw',
+ 'url': 'http://localhost:8080/job/utmebvpxrw/'},
+ 'why': 'Waiting for next available executor'}]}
+
+
+ @mock.patch.object(JenkinsBase, 'get_data', mockGetData)
+ def setUp(self):
+ self.J = Jenkins('http://localhost:8080') # Jenkins
+ self.q = Queue('http://localhost:8080/queue', self.J)
+
+ def testRepr(self):
+ self.assertTrue(repr(self.q))
+
+ def test_length(self):
+ self.assertEquals(len(self.q), 3)
+
+ def test_list_items(self):
+ self.assertEquals(set(self.q.keys()), set([40,41,42]))
+
+ def test_getitem(self):
+ item40 = self.q[40]
+ self.assertIsInstance(item40, QueueItem)
+
+ @mock.patch.object(JenkinsBase, 'get_data', mockGetData)
+ def test_get_job_for_queue_item(self):
+ item40 = self.q[40]
+ j = item40.get_job()
+ self.assertIsInstance(j, Job)
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file