class test_build(unittest.TestCase): DATA = { 'actions': [{'causes': [{'shortDescription': 'Started by user anonymous', 'userId': None, 'userName': '******'}]}, None, {'causes': []}], 'artifacts': [], 'building': False, 'builtOn': '', 'changeSet': {'items': [], 'kind': None}, 'culprits': [], 'description': None, "duration": 5782, 'estimatedDuration': 106, 'executor': None, "fingerprint": [{"fileName": "BuildId.json", "hash": "e3850a45ab64aa34c1aa66e30c1a8977", "original": {"name": "ArtifactGenerateJob", "number": 469}, "timestamp": 1380270162488, "usage": [{"name": "SingleJob", "ranges": {"ranges": [{"end": 567, "start": 566}]}}, {"name": "MultipleJobs", "ranges": {"ranges": [{"end": 150, "start": 139}]}}] }], 'fullDisplayName': 'foo #1', 'id': '2013-05-31_23-15-40', 'keepLog': False, 'number': 1, 'result': 'SUCCESS', 'timestamp': 1370042140000, 'url': 'http://*****:*****@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') def test_duration(self): expected = datetime.timedelta(milliseconds=5782) self.assertEquals(self.b.get_duration(), expected) self.assertEquals(self.b.get_duration().seconds, 5) self.assertEquals(self.b.get_duration().microseconds, 782000) self.assertEquals(str(self.b.get_duration()), '0:00:05.782000') def test_get_causes(self): self.assertEquals(self.b.get_causes(), [{'shortDescription': 'Started by user anonymous', 'userId': None, 'userName': '******'}]) @mock.patch.object(Build, 'get_data') def test_build_depth(self, get_data_mock): build = Build('http://halob:8080/job/foo/98', 98, self.j, depth=0) get_data_mock.assert_called_with('http://halob:8080/job/foo/98/api/python?depth=0') def test_get_revision_no_scm(self): """ with no scm, get_revision should return None """ self.assertEqual(self.b.get_revision(), None)
class test_build(unittest.TestCase): DATA = { 'actions': [{ 'causes': [{ 'shortDescription': 'Started by user anonymous', 'userId': None, 'userName': '******' }] }], 'artifacts': [], 'building': False, 'builtOn': '', 'changeSet': { 'items': [], 'kind': None }, 'culprits': [], 'description': None, "duration": 5782, 'estimatedDuration': 106, 'executor': None, "fingerprint": [{ "fileName": "BuildId.json", "hash": "e3850a45ab64aa34c1aa66e30c1a8977", "original": { "name": "ArtifactGenerateJob", "number": 469 }, "timestamp": 1380270162488, "usage": [{ "name": "SingleJob", "ranges": { "ranges": [{ "end": 567, "start": 566 }] } }, { "name": "MultipleJobs", "ranges": { "ranges": [{ "end": 150, "start": 139 }] } }] }], 'fullDisplayName': 'foo #1', 'id': '2013-05-31_23-15-40', 'keepLog': False, 'number': 1, 'result': 'SUCCESS', 'timestamp': 1370042140000, 'url': 'http://*****:*****@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') def test_duration(self): expected = datetime.timedelta(milliseconds=5782) self.assertEquals(self.b.get_duration(), expected) self.assertEquals(self.b.get_duration().seconds, 5) self.assertEquals(self.b.get_duration().microseconds, 782000) self.assertEquals(str(self.b.get_duration()), '0:00:05.782000') @mock.patch.object(Build, 'get_data') def test_build_depth(self, get_data_mock): build = Build('http://halob:8080/job/foo/98', 98, self.j, depth=0) get_data_mock.assert_called_with( 'http://halob:8080/job/foo/98/api/python?depth=0')
class test_build(unittest.TestCase): DATA = { 'actions': [{'causes': [{'shortDescription': 'Started by user anonymous', 'userId': None, 'userName': '******'}]}], 'artifacts': [], 'building': False, 'builtOn': '', 'changeSet': {'items': [], 'kind': None}, 'culprits': [], 'description': None, "duration": 5782, 'estimatedDuration': 106, 'executor': None, "fingerprint": [{"fileName": "BuildId.json", "hash": "e3850a45ab64aa34c1aa66e30c1a8977", "original": {"name": "ArtifactGenerateJob", "number": 469}, "timestamp": 1380270162488, "usage": [{"name": "SingleJob", "ranges": {"ranges": [{"end": 567, "start": 566}]}}, {"name": "MultipleJobs", "ranges": {"ranges": [{"end": 150, "start": 139}]}}] }], 'fullDisplayName': 'foo #1', 'id': '2013-05-31_23-15-40', 'keepLog': False, 'number': 1, 'result': 'SUCCESS', 'timestamp': 1370042140000, 'url': 'http://*****:*****@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') def test_duration(self): expected = datetime.timedelta(milliseconds=5782) self.assertEquals(self.b.get_duration(), expected) self.assertEquals(self.b.get_duration().seconds, 5) self.assertEquals(self.b.get_duration().microseconds, 782000) self.assertEquals(str(self.b.get_duration()), '0:00:05.782000') @mock.patch.object(Build, '_poll') def test_poll_cache(self, _poll): # only gets called once in interval b = Build('http://', 97, self.j, poll_cache_timeout=1) for i in range(2): b.poll() self.assertEquals(_poll.call_count, 1) b.poll(True) # test force poll self.assertEquals(_poll.call_count, 2) # ensure it gets called again after cache timeout _poll.reset_mock() time.sleep(1.1) b.poll() self.assertTrue(_poll.called) # ensure it is disabled by default _poll.reset_mock() for i in range(2): self.b.poll() self.assertEquals(_poll.call_count, 2) self.assertIsNone(self.b.poll_cache_expires)
class TestBuildCase(unittest.TestCase): DATA = { 'actions': [{ 'causes': [{ 'shortDescription': 'Started by user anonymous', 'userId': None, 'userName': '******' }] }, None, { 'causes': [] }], 'artifacts': [], 'building': False, 'builtOn': 'localhost', 'changeSet': { 'items': [], 'kind': None }, 'culprits': [], 'description': 'Best build ever!', "duration": 5782, 'estimatedDuration': 106, 'executor': None, "fingerprint": [{ "fileName": "BuildId.json", "hash": "e3850a45ab64aa34c1aa66e30c1a8977", "original": { "name": "ArtifactGenerateJob", "number": 469 }, "timestamp": 1380270162488, "usage": [{ "name": "SingleJob", "ranges": { "ranges": [{ "end": 567, "start": 566 }] } }, { "name": "MultipleJobs", "ranges": { "ranges": [{ "end": 150, "start": 139 }] } }] }], 'fullDisplayName': 'foo #1', 'id': '2013-05-31_23-15-40', 'keepLog': False, 'number': 1, 'result': 'SUCCESS', 'timestamp': 1370042140000, 'url': 'http://*****:*****@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') def test_duration(self): expected = datetime.timedelta(milliseconds=5782) self.assertEquals(self.b.get_duration(), expected) self.assertEquals(self.b.get_duration().seconds, 5) self.assertEquals(self.b.get_duration().microseconds, 782000) self.assertEquals(str(self.b.get_duration()), '0:00:05.782000') def test_get_causes(self): self.assertEquals(self.b.get_causes(), [{ 'shortDescription': 'Started by user anonymous', 'userId': None, 'userName': '******' }]) def test_get_description(self): self.assertEquals(self.b.get_description(), 'Best build ever!') def test_get_slave(self): self.assertEquals(self.b.get_slave(), 'localhost') @mock.patch.object(Build, 'get_data') def test_build_depth(self, get_data_mock): Build('http://*****:*****@mock.patch.object(Build, '__init__') def test_get_matrix_runs(self, build_init_mock): build_init_mock.return_value = None for build in self.b.get_matrix_runs(): continue build_init_mock.assert_called_once_with( 'http//localhost:8080/job/foo/SHARD_NUM=1/1/', 1, self.j) def test_get_params(self): expected = { 'first_param': 'first_value', 'second_param': 'second_value', } self.b._data = { 'actions': [{ 'parameters': [ { 'name': 'first_param', 'value': 'first_value' }, { 'name': 'second_param', 'value': 'second_value' }, ] }] } params = self.b.get_params() self.assertDictEqual(params, expected) def test_get_params_different_order(self): """ Dictionary with `parameters` key is not always the first element in `actions` list, so we need to search through whole array. This test covers such a case """ expected = { 'first_param': 'first_value', 'second_param': 'second_value', } self.b._data = { 'actions': [{ 'not_parameters': 'some_data', }, { 'another_action': 'some_value', }, { 'parameters': [ { 'name': 'first_param', 'value': 'first_value' }, { 'name': 'second_param', 'value': 'second_value' }, ] }] } params = self.b.get_params() self.assertDictEqual(params, expected)
class test_build(unittest.TestCase): DATA = { "actions": [ {"causes": [{"shortDescription": "Started by user anonymous", "userId": None, "userName": "******"}]}, None, {"causes": []}, ], "artifacts": [], "building": False, "builtOn": "", "changeSet": {"items": [], "kind": None}, "culprits": [], "description": None, "duration": 5782, "estimatedDuration": 106, "executor": None, "fingerprint": [ { "fileName": "BuildId.json", "hash": "e3850a45ab64aa34c1aa66e30c1a8977", "original": {"name": "ArtifactGenerateJob", "number": 469}, "timestamp": 1380270162488, "usage": [ {"name": "SingleJob", "ranges": {"ranges": [{"end": 567, "start": 566}]}}, {"name": "MultipleJobs", "ranges": {"ranges": [{"end": 150, "start": 139}]}}, ], } ], "fullDisplayName": "foo #1", "id": "2013-05-31_23-15-40", "keepLog": False, "number": 1, "result": "SUCCESS", "timestamp": 1370042140000, "url": "http://*****:*****@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") def test_duration(self): expected = datetime.timedelta(milliseconds=5782) self.assertEquals(self.b.get_duration(), expected) self.assertEquals(self.b.get_duration().seconds, 5) self.assertEquals(self.b.get_duration().microseconds, 782000) self.assertEquals(str(self.b.get_duration()), "0:00:05.782000") def test_get_causes(self): self.assertEquals( self.b.get_causes(), [{"shortDescription": "Started by user anonymous", "userId": None, "userName": "******"}], ) @mock.patch.object(Build, "get_data") def test_build_depth(self, get_data_mock): Build("http://*****:*****@mock.patch.object(Build, "__init__") def test_get_matrix_runs(self, build_init_mock): build_init_mock.return_value = None for build in self.b.get_matrix_runs(): continue build_init_mock.assert_called_once_with("http//localhost:8080/job/foo/SHARD_NUM=1/1/", 1, self.j)
class test_build(unittest.TestCase): DATA = { "actions": [ {"causes": [{"shortDescription": "Started by user anonymous", "userId": None, "userName": "******"}]} ], "artifacts": [], "building": False, "builtOn": "", "changeSet": {"items": [], "kind": None}, "culprits": [], "description": None, "duration": 5782, "estimatedDuration": 106, "executor": None, "fingerprint": [ { "fileName": "BuildId.json", "hash": "e3850a45ab64aa34c1aa66e30c1a8977", "original": {"name": "ArtifactGenerateJob", "number": 469}, "timestamp": 1380270162488, "usage": [ {"name": "SingleJob", "ranges": {"ranges": [{"end": 567, "start": 566}]}}, {"name": "MultipleJobs", "ranges": {"ranges": [{"end": 150, "start": 139}]}}, ], } ], "fullDisplayName": "foo #1", "id": "2013-05-31_23-15-40", "keepLog": False, "number": 1, "result": "SUCCESS", "timestamp": 1370042140000, "url": "http://*****:*****@mock.patch.object(Build, "_poll") # pylint: disable=W0221 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") def test_duration(self): expected = datetime.timedelta(milliseconds=5782) self.assertEquals(self.b.get_duration(), expected) self.assertEquals(self.b.get_duration().seconds, 5) self.assertEquals(self.b.get_duration().microseconds, 782000) self.assertEquals(str(self.b.get_duration()), "0:00:05.782000")