diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-03-17 18:37:53 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-03-30 10:11:32 +0300 |
commit | 3e98768fc55aedadc7362a58f50134db9eb4fc63 (patch) | |
tree | e5704c4f71e3e860de7c233558d6f9c9b71dc66c /ick2/client_tests.py | |
parent | 87001d6a0c5d9d8b48e716ec733e5ba6c0c4afd4 (diff) | |
download | ick2-3e98768fc55aedadc7362a58f50134db9eb4fc63.tar.gz |
Add: ControllerClient class for using controller API
Diffstat (limited to 'ick2/client_tests.py')
-rw-r--r-- | ick2/client_tests.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/ick2/client_tests.py b/ick2/client_tests.py index 1a0bcc5..856f4c3 100644 --- a/ick2/client_tests.py +++ b/ick2/client_tests.py @@ -98,6 +98,73 @@ class HttpAPITests(unittest.TestCase): self.assertEqual(obj, None) +class ControllerClientTests(unittest.TestCase): + + def setUp(self): + self.session = FakeHttpSession() + self.session.token = 'SECRET-TOKEN' + + self.client = ick2.HttpAPI() + self.client.set_session(self.session) + self.client.set_token(self.session.token) + + self.controller = ick2.ControllerClient() + self.controller.set_http_api(self.client) + self.controller.set_controller_url('https://controller') + self.controller.set_token('SECRET-TOKEN') + self.controller.set_client_name('asterix') + + def test_register_succeeds_on_error(self): + self.session.response = FakeResponse(400) + self.assertEqual(self.controller.register(), None) + + def test_register_succeeds(self): + self.session.response = FakeResponse(200) + self.assertEqual(self.controller.register(), None) + + def test_get_work_raises_exception_on_error(self): + self.session.response = FakeResponse(400) + with self.assertRaises(ick2.HttpError): + self.controller.get_work() + + def test_get_work_succeeds(self): + work = { + 'build_id': 'rome/1' + } + self.session.response = FakeResponse( + 200, body=json.dumps(work), content_type=json_type) + self.assertEqual(self.controller.get_work(), work) + + def test_report_work_raises_exception_on_error(self): + work = { + 'stdout': 'hello, world', + } + self.session.response = FakeResponse(400) + with self.assertRaises(ick2.HttpError): + self.controller.report_work(work) + + def test_report_work_succeeds(self): + work = { + 'stdout': 'hello, world', + } + self.session.response = FakeResponse(200) + self.assertEqual(self.controller.report_work(work), None) + + def test_get_blob_service_url_raises_exception_on_error(self): + self.session.response = FakeResponse(400) + with self.assertRaises(ick2.HttpError): + self.controller.get_blob_service_url() + + def test_get_blob_service_url_succeeds(self): + url = 'https://blobs' + version = { + 'blob_service': url, + } + self.session.response = FakeResponse( + 200, body=json.dumps(version), content_type=json_type) + self.assertEqual(self.controller.get_blob_service_url(), url) + + class FakeHttpSession: def __init__(self): |