def __str__(self):
return self._data['fullDisplayName']
- def id(self):
+ @property
+ def name(self):
+ return str(self)
+
+ def get_number(self):
return self._data["number"]
def get_status(self):
None : lambda element_tree: []
}
JenkinsBase.__init__( self, url )
-
- def id( self ):
- return self._data["name"]
-
+
def __str__(self):
return self._data["name"]
def get_jenkins_obj(self):
return self.jenkins
- def id(self):
- return self.name
-
def __str__(self):
- return self.id()
+ return self.name
def get_node_data(self):
return self._data
def __str__(self):
return "Test Result for %s" % str( self.build )
+ @property
+ def name(self):
+ return str(self)
+
def keys(self):
return [ a[0] for a in self.iteritems() ]
yield viewdict["name"], viewdict["url"]
def get_nested_view_dict(self):
- return dict( self._get_nested_views() )
-
- def id(self):
- """
- Calculate an ID for this object.
- """
- return "%s.%s" % ( self.className, self.name )
+ return dict( self._get_nested_views() )
\ No newline at end of file
'url': 'http://localhost:8080/job/foo/1/'}
@mock.patch.object(Build, '_poll')
- def test_timestamp(self, _poll):
+ def setUp(self, _poll):
_poll.return_value = self.DATA
+ self.j = mock.MagicMock() # Job
+ self.j.name = 'FooJob'
- j = mock.MagicMock()
- b = Build('http://', 0, j)
+ self.b = Build('http://', 97, self.j)
- self.assertIsInstance(b.get_timestamp(), datetime.datetime)
- self.assertEqual(b.get_timestamp(), datetime.datetime(2013, 5, 31, 23, 15, 40))
\ No newline at end of file
+ def test_timestamp(self):
+ self.assertIsInstance(self.b.get_timestamp(), datetime.datetime)
+ self.assertEqual(self.b.get_timestamp(), datetime.datetime(2013, 5, 31, 23, 15, 40))
+
+ def testName(self):
+ with self.assertRaises(AttributeError):
+ _ = self.b.id()
+ self.assertEquals(self.b.name, 'foo #1')
\ No newline at end of file
--- /dev/null
+class TestJenkinsBaseMixin(object):
+ """
+ Tests which apply to all or most Jenkins objects
+ """
+ pass
\ No newline at end of file
--- /dev/null
+import mock
+import unittest
+import datetime
+
+from jenkinsapi.job import Job
+
+
+class TestJob(unittest.TestCase):
+
+ DATA = {"actions": [],
+ "description": "test job",
+ "displayName": "foo",
+ "displayNameOrNull": None,
+ "name": "foo",
+ "url": "http://halob:8080/job/foo/",
+ "buildable": True,
+ "builds": [{"number": 3, "url": "http://halob:8080/job/foo/3/"},
+ {"number": 2, "url": "http://halob:8080/job/foo/2/"},
+ {"number": 1, "url": "http://halob:8080/job/foo/1/"}],
+ "color": "blue",
+ "firstBuild": {"number": 1, "url": "http://halob:8080/job/foo/1/"},
+ "healthReport": [{"description": "Build stability: No recent builds failed.",
+ "iconUrl": "health-80plus.png", "score": 100}],
+ "inQueue": False,
+ "keepDependencies": False,
+ "lastBuild": {"number": 3, "url": "http://halob:8080/job/foo/3/"},
+ "lastCompletedBuild": {"number": 3, "url": "http://halob:8080/job/foo/3/"},
+ "lastFailedBuild": None,
+ "lastStableBuild": {"number": 3, "url": "http://halob:8080/job/foo/3/"},
+ "lastSuccessfulBuild": {"number": 3, "url": "http://halob:8080/job/foo/3/"},
+ "lastUnstableBuild": None,
+ "lastUnsuccessfulBuild": None,
+ "nextBuildNumber": 4,
+ "property": [],
+ "queueItem": None,
+ "concurrentBuild": False,
+ "downstreamProjects": [],
+ "scm": {},
+ "upstreamProjects": []}
+
+ @mock.patch.object(Job, '_poll')
+ def setUp(self, _poll):
+ _poll.return_value = self.DATA
+
+ # def __init__( self, url, name, jenkins_obj ):
+
+ self.J = mock.MagicMock() # Jenkins object
+ self.j = Job('http://', 'foo', self.J)
+
+ def testRepr(self):
+ # Can we produce a repr string for this object
+ repr(self.j)
+
+ def testName(self):
+ with self.assertRaises(AttributeError):
+ self.j.id()
+ self.assertEquals(self.j.name, 'foo')
--- /dev/null
+import mock
+import unittest
+import datetime
+
+from jenkinsapi.node import Node
+
+class TestNode(unittest.TestCase):
+
+ DATA = {"actions": [],
+ "displayName": "bobnit",
+ "executors": [{}],
+ "icon": "computer.png",
+ "idle": True,
+ "jnlpAgent": False,
+ "launchSupported": True,
+ "loadStatistics": {},
+ "manualLaunchAllowed": True,
+ "monitorData": {"hudson.node_monitors.SwapSpaceMonitor": {"availablePhysicalMemory": 7681417216,
+ "availableSwapSpace": 12195983360,
+ "totalPhysicalMemory": 8374497280,
+ "totalSwapSpace": 12195983360},
+ "hudson.node_monitors.ArchitectureMonitor": "Linux (amd64)",
+ "hudson.node_monitors.ResponseTimeMonitor": {"average": 64},
+ "hudson.node_monitors.TemporarySpaceMonitor": {"path": "/tmp", "size": 250172776448},
+ "hudson.node_monitors.DiskSpaceMonitor": {"path": "/home/sal/jenkins", "size": 170472026112},
+ "hudson.node_monitors.ClockMonitor": {"diff": 6736}},
+ "numExecutors": 1,
+ "offline": False,
+ "offlineCause": None,
+ "oneOffExecutors": [],
+ "temporarilyOffline": False}
+
+ @mock.patch.object(Node, '_poll')
+ def setUp(self, _poll):
+ _poll.return_value = self.DATA
+
+ # def __init__(self, baseurl, nodename, jenkins_obj):
+
+ self.J = mock.MagicMock() # Jenkins object
+ self.n = Node('http://', 'bobnit', self.J)
+
+ def testRepr(self):
+ # Can we produce a repr string for this object
+ repr(self.n)
+
+ def testName(self):
+ with self.assertRaises(AttributeError):
+ _ = self.j.id()
+
+ self.assertEquals(self.n.name, 'bobnit')
+
--- /dev/null
+import mock
+import unittest
+import datetime
+
+from jenkinsapi.result_set import ResultSet
+from jenkinsapi.result import Result
+
+class TestResultSet(unittest.TestCase):
+
+ DATA = {'duration': 0.0,
+ 'failCount': 2,
+ 'passCount': 0,
+ 'skipCount': 0,
+ 'suites': [{'cases': [{'age': 1,
+ 'className': '<nose.suite.ContextSuite context=jenkinsapi_tests',
+ 'duration': 0.0,
+ 'errorDetails': 'Timeout error occured while waiting for Jenkins start.',
+ 'errorStackTrace': 'Traceback (most recent call last):\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 208, in run\n self.setUp()\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 291, in setUp\n self.setupContext(ancestor)\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 314, in setupContext\n try_run(context, names)\n File "/usr/lib/python2.7/dist-packages/nose/util.py", line 478, in try_run\n return func()\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 54, in setUpPackage\n launcher = JenkinsLauncher(update_war=True, launch=True)\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 20, in __init__\n self.launch()\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 41, in launch\n raise Timeout(\'Timeout error occured while waiting for Jenkins start.\')\nTimeout: Timeout error occured while waiting for Jenkins start.\n',
+ 'failedSince': 88,
+ 'name': 'systests>:setup',
+ 'skipped': False,
+ 'status': 'FAILED',
+ 'stderr': None,
+ 'stdout': None},
+ {'age': 1,
+ 'className': 'nose.failure.Failure',
+ 'duration': 0.0,
+ 'errorDetails': 'No module named mock',
+ 'errorStackTrace': 'Traceback (most recent call last):\n File "/usr/lib/python2.7/unittest/case.py", line 332, in run\n testMethod()\n File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName\n addr.filename, addr.module)\n File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath\n return self.importFromDir(dir_path, fqname)\n File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir\n mod = load_module(part_fqname, fh, filename, desc)\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/unittests/test_build.py", line 1, in <module>\n import mock\nImportError: No module named mock\n',
+ 'failedSince': 88,
+ 'name': 'runTest',
+ 'skipped': False,
+ 'status': 'FAILED',
+ 'stderr': None,
+ 'stdout': None}],
+ 'duration': 0.0,
+ 'id': None,
+ 'name': 'nosetests',
+ 'stderr': None,
+ 'stdout': None,
+ 'timestamp': None}]}
+
+ @mock.patch.object(ResultSet, '_poll')
+ def setUp(self, _poll):
+ _poll.return_value = self.DATA
+
+ # def __init__(self, url, build ):
+
+ self.b = mock.MagicMock() # Build object
+ self.b.__str__.return_value = 'FooBuild'
+ self.rs = ResultSet('http://', self.b)
+
+ def testRepr(self):
+ # Can we produce a repr string for this object
+ repr(self.rs)
+
+ def testName(self):
+ with self.assertRaises(AttributeError):
+ self.rs.id()
+
+ self.assertEquals(self.rs.name, 'Test Result for FooBuild')
+
+ def testBuildComponents(self):
+ self.assertTrue(self.rs.items())
+ for k, v in self.rs.items():
+ self.assertIsInstance(k, str)
+ self.assertIsInstance(v, Result)
+ self.assertIsInstance(v.id(), str)
--- /dev/null
+import mock
+import unittest
+import datetime
+
+from jenkinsapi.view import View
+
+
+class TestView(unittest.TestCase):
+
+ DATA = {'description': 'Important Shizz',
+ 'jobs': [{'color': 'blue',
+ 'name': 'foo',
+ 'url': 'http://halob:8080/job/foo/'},
+ {'color': 'red',
+ 'name': 'test_jenkinsapi',
+ 'url': 'http://halob:8080/job/test_jenkinsapi/'}],
+ 'name': 'FodFanFo',
+ 'property': [],
+ 'url': 'http://halob:8080/view/FodFanFo/'}
+
+ @mock.patch.object(View, '_poll')
+ def setUp(self, _poll):
+ _poll.return_value = self.DATA
+
+ # def __init__(self, url, name, jenkins_obj)
+ self.J = mock.MagicMock() # Jenkins object
+ self.v = View('http://localhost:800/view/FodFanFo', 'FodFanFo', self.J)
+
+ def testRepr(self):
+ # Can we produce a repr string for this object
+ repr(self.v)
+
+ def testName(self):
+ with self.assertRaises(AttributeError):
+ self.v.id()
+ self.assertEquals(self.v.name, 'FodFanFo')