Commit 90f572fd authored by Georgios D. Tsoukalas's avatar Georgios D. Tsoukalas

cyclades: fix URLs in cyclades/image tests

parent e7ccae2e
......@@ -37,6 +37,31 @@ from mock import patch
from functools import wraps
from copy import deepcopy
from snf_django.utils.testing import BaseAPITest
from synnefo.cyclades_settings import cyclades_services
from synnefo.lib.services import get_service_path
from synnefo.lib import join_urls
class PlanktonAPITest(BaseAPITest):
def setUp(self, *args, **kwargs):
super(PlanktonAPITest, self).setUp(*args, **kwargs)
self.compute_path = get_service_path(cyclades_services, 'image',
version='v1.0')
def myget(self, path, *args, **kwargs):
path = join_urls(self.compute_path, path)
return self.get(path, *args, **kwargs)
def myput(self, path, *args, **kwargs):
path = join_urls(self.compute_path, path)
return self.put(path, *args, **kwargs)
def mypost(self, path, *args, **kwargs):
path = join_urls(self.compute_path, path)
return self.post(path, *args, **kwargs)
def mydelete(self, path, *args, **kwargs):
path = join_urls(self.compute_path, path)
return self.delete(path, *args, **kwargs)
FILTERS = ('name', 'container_format', 'disk_format', 'status', 'size_min',
......@@ -128,12 +153,12 @@ def assert_backend_closed(func):
@patch("synnefo.plankton.backend.ImageBackend")
class PlanktonTest(BaseAPITest):
class PlanktonTest(PlanktonAPITest):
@assert_backend_closed
def test_list_images(self, backend):
backend.return_value.list_images.return_value =\
deepcopy(DummyImages).values()
response = self.get("/plankton/images/")
response = self.myget("images/")
self.assertSuccess(response)
images = json.loads(response.content)
for api_image in images:
......@@ -150,7 +175,7 @@ class PlanktonTest(BaseAPITest):
def test_list_images_detail(self, backend):
backend.return_value.list_images.return_value =\
deepcopy(DummyImages).values()
response = self.get("/plankton/images/detail")
response = self.myget("images/detail")
self.assertSuccess(response)
images = json.loads(response.content)
for api_image in images:
......@@ -167,7 +192,7 @@ class PlanktonTest(BaseAPITest):
def test_list_images_filters(self, backend):
backend.return_value.list_images.return_value =\
deepcopy(DummyImages).values()
response = self.get("/plankton/images/?size_max=1000")
response = self.myget("images/?size_max=1000")
self.assertSuccess(response)
backend.return_value\
.list_images.assert_called_once_with({'size_max': 1000},
......@@ -176,20 +201,20 @@ class PlanktonTest(BaseAPITest):
@assert_backend_closed
def test_list_images_filters_error_1(self, backend):
response = self.get("/plankton/images/?size_max=")
response = self.myget("images/?size_max=")
self.assertBadRequest(response)
@assert_backend_closed
def test_list_images_filters_error_2(self, backend):
response = self.get("/plankton/images/?size_min=foo")
response = self.myget("images/?size_min=foo")
self.assertBadRequest(response)
@assert_backend_closed
def test_update_image(self, backend):
db_image = DummyImages.values()[0]
response = self.put("/plankton/images/%s" % db_image['id'],
json.dumps({}),
'json', HTTP_X_IMAGE_META_OWNER='user2')
response = self.myput("images/%s" % db_image['id'],
json.dumps({}),
'json', HTTP_X_IMAGE_META_OWNER='user2')
self.assertSuccess(response)
backend.return_value.update_metadata.assert_called_once_with(db_image['id'],
{"owner": "user2"})
......@@ -197,8 +222,8 @@ class PlanktonTest(BaseAPITest):
@assert_backend_closed
def test_add_image_member(self, backend):
image_id = DummyImages.values()[0]['id']
response = self.put("/plankton/images/%s/members/user3" % image_id,
json.dumps({}), 'json')
response = self.myput("images/%s/members/user3" % image_id,
json.dumps({}), 'json')
self.assertSuccess(response)
backend.return_value.add_user.assert_called_once_with(image_id,
'user3')
......@@ -206,7 +231,7 @@ class PlanktonTest(BaseAPITest):
@assert_backend_closed
def test_remove_image_member(self, backend):
image_id = DummyImages.values()[0]['id']
response = self.delete("/plankton/images/%s/members/user3" % image_id)
response = self.mydelete("images/%s/members/user3" % image_id)
self.assertSuccess(response)
backend.return_value.remove_user.assert_called_once_with(image_id,
'user3')
......@@ -214,12 +239,12 @@ class PlanktonTest(BaseAPITest):
@assert_backend_closed
def test_add_image(self, backend):
location = "pithos://uuid/container/name/"
response = self.post("/plankton/images/",
json.dumps({}),
'json',
HTTP_X_IMAGE_META_NAME='dummy_name',
HTTP_X_IMAGE_META_OWNER='dummy_owner',
HTTP_X_IMAGE_META_LOCATION=location)
response = self.mypost("images/",
json.dumps({}),
'json',
HTTP_X_IMAGE_META_NAME='dummy_name',
HTTP_X_IMAGE_META_OWNER='dummy_owner',
HTTP_X_IMAGE_META_LOCATION=location)
self.assertSuccess(response)
backend.return_value.register.assert_called_once_with('dummy_name',
location,
......@@ -227,12 +252,12 @@ class PlanktonTest(BaseAPITest):
@assert_backend_closed
def test_get_image(self, backend):
response = self.get("/plankton/images/123")
response = self.myget("images/123")
self.assertEqual(response.status_code, 501)
@assert_backend_closed
def test_delete_image(self, backend):
response = self.delete("/plankton/images/123")
response = self.mydelete("images/123")
self.assertEqual(response.status_code, 204)
backend.return_value.unregister.assert_called_once_with('123')
backend.return_value._delete.assert_not_called()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment