import time
-import urlparse
+import pytz
import urllib2
+import urlparse
import datetime
from jenkinsapi.artifact import Artifact
from jenkinsapi import config
self.poll()
return self._data["building"]
+ def block(self):
+ while self.is_running():
+ time.sleep(1)
+
def is_good( self ):
"""
Return a bool, true if the build was good.
Returns build timestamp in UTC
'''
# Java timestamps are given in miliseconds since the epoch start!
- return datetime.datetime(*time.gmtime(self._data['timestamp']/1000.0)[:6])
+ naive_timestamp = datetime.datetime(*time.gmtime(self._data['timestamp']/1000.0)[:6])
+ return pytz.utc.localize(naive_timestamp)
def stop(self):
"""
+import pytz
import mock
import unittest
import datetime
from jenkinsapi.build import Build
-class TestTimestamps(unittest.TestCase):
-
- DATA = { 'actions': [{'causes': [{'shortDescription': 'Started by user anonymous',
- 'userId': None,
- 'userName': 'anonymous'}]}],
- 'artifacts': [],
- 'building': False,
- 'builtOn': '',
- 'changeSet': {'items': [], 'kind': None},
- 'culprits': [],
- 'description': None,
- 'duration': 106,
- 'estimatedDuration': 106,
- 'executor': None,
- 'fullDisplayName': 'foo #1',
- 'id': '2013-05-31_23-15-40',
- 'keepLog': False,
- 'number': 1,
- 'result': 'SUCCESS',
- 'timestamp': 1370042140000,
- 'url': 'http://localhost:8080/job/foo/1/'}
-
- @mock.patch.object(Build, '_poll')
- def setUp(self, _poll):
- _poll.return_value = self.DATA
- self.j = mock.MagicMock() # Job
- self.j.name = 'FooJob'
-
- self.b = Build('http://', 97, self.j)
-
- 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')
+
+class test_build(unittest.TestCase):
+
+ DATA = {
+ 'actions': [{'causes': [{'shortDescription': 'Started by user anonymous',
+ 'userId': None,
+ 'userName': 'anonymous'}]}],
+ 'artifacts': [],
+ 'building': False,
+ 'builtOn': '',
+ 'changeSet': {'items': [], 'kind': None},
+ 'culprits': [],
+ 'description': None,
+ 'duration': 106,
+ 'estimatedDuration': 106,
+ 'executor': None,
+ 'fullDisplayName': 'foo #1',
+ 'id': '2013-05-31_23-15-40',
+ 'keepLog': False,
+ 'number': 1,
+ 'result': 'SUCCESS',
+ 'timestamp': 1370042140000,
+ 'url': 'http://localhost:8080/job/foo/1/'}
+
+ @mock.patch.object(Build, '_poll')
+ def setUp(self, _poll):
+ _poll.return_value = self.DATA
+ self.j = mock.MagicMock() # Job
+ self.j.name = 'FooJob'
+
+ self.b = Build('http://', 97, self.j)
+
+ def test_timestamp(self):
+ self.assertIsInstance(self.b.get_timestamp(), datetime.datetime)
+
+ expected = pytz.utc.localize(
+ datetime.datetime(2013, 5, 31, 23, 15, 40))
+
+ self.assertEqual(self.b.get_timestamp(), expected)
+
+ def testName(self):
+ with self.assertRaises(AttributeError):
+ _ = self.b.id()
+ self.assertEquals(self.b.name, 'foo #1')
DESCRIPTION = open(os.path.join(PROJECT_ROOT, "README.rst")).read()
except IOError, _:
DESCRIPTION = SHORT_DESCRIPTION
-
+
GLOBAL_ENTRY_POINTS = {
"console_scripts": ["jenkins_invoke=jenkinsapi.command_line.jenkins_invoke:main"]
}
packages=['jenkinsapi', 'jenkinsapi.utils', 'jenkinsapi.command_line', 'jenkinsapi_tests'],
zip_safe=True,
include_package_data=False,
- install_requires=['requests==1.2.3'],
+ install_requires=['requests==1.2.3', 'pytz'],
test_suite='jenkinsapi_tests',
tests_require=['mock', 'nose'],
extras_require={