summaryrefslogtreecommitdiff
path: root/ick2/client_tests.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-03-30 10:03:56 +0300
committerLars Wirzenius <liw@liw.fi>2018-03-30 10:32:54 +0300
commit974631edc803b66e4487431c596664371bf0400a (patch)
tree18d003e2e607a1619b1204f6d4529f5240649518 /ick2/client_tests.py
parent3e98768fc55aedadc7362a58f50134db9eb4fc63 (diff)
downloadick2-974631edc803b66e4487431c596664371bf0400a.tar.gz
Add: BlobClient class to use artifact store API
Diffstat (limited to 'ick2/client_tests.py')
-rw-r--r--ick2/client_tests.py67
1 files changed, 64 insertions, 3 deletions
diff --git a/ick2/client_tests.py b/ick2/client_tests.py
index 856f4c3..57486bd 100644
--- a/ick2/client_tests.py
+++ b/ick2/client_tests.py
@@ -61,12 +61,12 @@ class HttpAPITests(unittest.TestCase):
def test_get_blob_raises_exception_on_error(self):
self.session.response = FakeResponse(404)
with self.assertRaises(ick2.HttpError):
- self.client.get_blob('http://blobs/blob/foo')
+ self.client.get_blob('http://blobs/foo')
def test_get_blob_returns_response(self):
blob = b'hello, world\n'
self.session.response = FakeResponse(200, body=blob)
- obj = self.client.get_blob('http://blobs/blob/foo')
+ obj = self.client.get_blob('http://blobs/foo')
self.assertEqual(obj, blob)
def test_post_raises_exception_on_error(self):
@@ -89,7 +89,7 @@ class HttpAPITests(unittest.TestCase):
blob = b'fooblob'
self.session.response = FakeResponse(400)
with self.assertRaises(ick2.HttpError):
- self.client.put('http://blobs/blob/foo', body=blob)
+ self.client.put('http://blobs/foo', body=blob)
def test_put_succeeds(self):
blob = b'fooblob'
@@ -165,6 +165,67 @@ class ControllerClientTests(unittest.TestCase):
self.assertEqual(self.controller.get_blob_service_url(), url)
+class BlobServiceClientTests(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 get_blob_client(self):
+ url = 'https://blobs'
+ version = {
+ 'blob_service': url,
+ }
+ self.session.response = FakeResponse(
+ 200, body=json.dumps(version), content_type=json_type)
+
+ return self.controller.get_blob_client()
+
+ def test_get_blob_client_raises_exception_on_error(self):
+ self.session.response = FakeResponse(400)
+ with self.assertRaises(ick2.HttpError):
+ self.controller.get_blob_client()
+
+ def test_get_blob_client_succeeds(self):
+ blobs = self.get_blob_client()
+ self.assertTrue(isinstance(blobs, ick2.BlobClient))
+
+ def test_download_raises_exception_on_error(self):
+ blobs = self.get_blob_client()
+ self.session.response = FakeResponse(400)
+ with self.assertRaises(ick2.HttpError):
+ blobs.download('foo')
+
+ def test_download_succeeds(self):
+ blobs = self.get_blob_client()
+ blob = b'hello, world'
+ self.session.response = FakeResponse(200, body=blob)
+ self.assertEqual(blobs.download('foo'), blob)
+
+ def test_upload_raises_exception_on_error(self):
+ blobs = self.get_blob_client()
+ blob = b'hello, world'
+ self.session.response = FakeResponse(400)
+ with self.assertRaises(ick2.HttpError):
+ blobs.upload('foo', blob)
+
+ def test_upload_succeeds(self):
+ blobs = self.get_blob_client()
+ blob = b'hello, world'
+ self.session.response = FakeResponse(200)
+ self.assertEqual(blobs.upload('foo', blob), None)
+
+
class FakeHttpSession:
def __init__(self):