Commit cbdfd23a authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Update tests

parent 58235481
......@@ -80,6 +80,7 @@ class ImageAPITest(BaseAPITest):
@assert_backend_closed
def test_list_images_detail(self, mimage):
self.maxDiff = None
images = [{'id': 1,
'name': u'image-1 \u2601',
'status': 'available',
......@@ -87,6 +88,7 @@ class ImageAPITest(BaseAPITest):
'updated_at': '2012-12-26 11:52:54',
'owner': 'user1',
'deleted_at': '',
'is_snapshot': False,
'properties': {u'foo\u2610': u'bar\u2611'}},
{'id': 2,
'name': 'image-2',
......@@ -95,6 +97,7 @@ class ImageAPITest(BaseAPITest):
'updated_at': '2012-12-26 11:52:54',
'owner': 'user1',
'deleted_at': '2012-12-27 11:52:54',
'is_snapshot': False,
'properties': ''},
{'id': 3,
'name': 'image-3',
......@@ -103,6 +106,7 @@ class ImageAPITest(BaseAPITest):
'deleted_at': '',
'updated_at': '2012-12-26 11:52:54',
'owner': 'user1',
'is_snapshot': False,
'properties': ''}]
result_images = [
{'id': 1,
......@@ -113,6 +117,7 @@ class ImageAPITest(BaseAPITest):
'updated': '2012-12-26T11:52:54+00:00',
'user_id': 'user1',
'tenant_id': 'user1',
'is_snapshot': False,
'metadata': {u'foo\u2610': u'bar\u2611'}},
{'id': 2,
'name': 'image-2',
......@@ -122,6 +127,7 @@ class ImageAPITest(BaseAPITest):
'tenant_id': 'user1',
'created': '2012-11-26T11:52:54+00:00',
'updated': '2012-12-26T11:52:54+00:00',
'is_snapshot': False,
'metadata': {}},
{'id': 3,
'name': 'image-3',
......@@ -131,6 +137,7 @@ class ImageAPITest(BaseAPITest):
'tenant_id': 'user1',
'created': '2012-11-26T11:52:54+00:00',
'updated': '2012-12-26T11:52:54+00:00',
'is_snapshot': False,
'metadata': {}}]
mimage().__enter__().list_images.return_value = images
response = self.get(join_urls(IMAGES_URL, "detail"), 'user')
......@@ -156,6 +163,7 @@ class ImageAPITest(BaseAPITest):
'deleted_at': '',
'updated_at': old_time.isoformat(),
'owner': 'user1',
'is_snapshot': False,
'properties': ''},
{'id': 2,
'name': 'image-2',
......@@ -165,6 +173,7 @@ class ImageAPITest(BaseAPITest):
'created_at': new_time.isoformat(),
'updated_at': new_time.isoformat(),
'deleted_at': new_time.isoformat(),
'is_snapshot': False,
'properties': ''}]
mimage().__enter__().list_images.return_value = images
response =\
......@@ -176,6 +185,7 @@ class ImageAPITest(BaseAPITest):
@assert_backend_closed
def test_get_image_details(self, mimage):
self.maxDiff = None
image = {'id': 42,
'name': 'image-1',
'status': 'available',
......@@ -183,6 +193,7 @@ class ImageAPITest(BaseAPITest):
'updated_at': '2012-12-26 11:52:54',
'deleted_at': '',
'owner': 'user1',
'is_snapshot': False,
'properties': {'foo': 'bar'}}
result_image = \
{'id': 42,
......@@ -193,6 +204,7 @@ class ImageAPITest(BaseAPITest):
'updated': '2012-12-26T11:52:54+00:00',
'user_id': 'user1',
'tenant_id': 'user1',
'is_snapshot': False,
'metadata': {'foo': 'bar'}}
mimage().__enter__().get_image.return_value = image
response = self.get(join_urls(IMAGES_URL, "42"), 'user')
......
......@@ -34,14 +34,24 @@ from django.test import TransactionTestCase
from synnefo.logic import servers
from synnefo import quotas
from synnefo.db import models_factory as mfactory, models
from mock import patch
from mock import patch, Mock
from snf_django.lib.api import faults
from snf_django.utils.testing import mocked_quotaholder, override_settings
from django.conf import settings
from copy import deepcopy
fixed_image = Mock()
fixed_image.return_value = {'location': 'pithos://foo',
'checksum': 'test_checksum',
"id": 1,
"name": "test_image",
"size": 1024,
"is_snapshot": False,
'disk_format': 'diskdump'}
@patch('synnefo.api.util.get_image', fixed_image)
@patch("synnefo.logic.rapi_pool.GanetiRapiClient")
class ServerCreationTest(TransactionTestCase):
def test_create(self, mrapi):
......@@ -51,9 +61,7 @@ class ServerCreationTest(TransactionTestCase):
"name": "test_vm",
"password": "1234",
"flavor": flavor,
"image": {"id": "foo", "backend_id": "foo", "format": "diskdump",
"checksum": "test_checksum",
"metadata": "{}"},
"image_id": "safs",
"networks": [],
"metadata": {"foo": "bar"},
"personality": [],
......@@ -103,11 +111,13 @@ class ServerCreationTest(TransactionTestCase):
with override_settings(settings, **osettings):
vm = servers.create(**req)
name, args, kwargs = mrapi().CreateInstance.mock_calls[-1]
self.assertEqual(kwargs["disks"][0], {"provider": "archipelago",
"origin": "test_checksum",
"foo": "mpaz",
"lala": "lolo",
"size": 1024})
self.assertEqual(kwargs["disks"][0],
{"provider": "archipelago",
"origin": "pithos:test_checksum",
"name": vm.volumes.all()[0].backend_volume_uuid,
"foo": "mpaz",
"lala": "lolo",
"size": 1024})
@patch("synnefo.logic.rapi_pool.GanetiRapiClient")
......
......@@ -52,7 +52,7 @@ class VolumesTest(BaseAPITest):
name, args, kwargs = mrapi().ModifyInstance.mock_calls[0]
self.assertEqual(kwargs["instance"], self.vm.backend_vm_id)
disk_info = kwargs["disks"][0][2]
self.assertEqual(disk_info["size"], self.size)
self.assertEqual(disk_info["size"], self.size << 10)
self.assertEqual(disk_info["name"], vol.backend_volume_uuid)
self.assertEqual(disk_info["volume_name"], vol.backend_volume_uuid)
self.assertFalse("origin" in disk_info)
......@@ -86,7 +86,7 @@ class VolumesTest(BaseAPITest):
name, args, kwargs = mrapi().ModifyInstance.mock_calls[0]
self.assertEqual(kwargs["instance"], self.vm.backend_vm_id)
disk_info = kwargs["disks"][0][2]
self.assertEqual(disk_info["size"], self.size)
self.assertEqual(disk_info["size"], self.size << 10)
self.assertEqual(disk_info["name"], vol.backend_volume_uuid)
self.assertEqual(disk_info["volume_name"], vol.backend_volume_uuid)
self.assertEqual(disk_info["origin"], svol.backend_volume_uuid)
......@@ -125,14 +125,14 @@ class VolumesTest(BaseAPITest):
name, args, kwargs = mrapi().ModifyInstance.mock_calls[0]
self.assertEqual(kwargs["instance"], self.vm.backend_vm_id)
disk_info = kwargs["disks"][0][2]
self.assertEqual(disk_info["size"], self.size)
self.assertEqual(disk_info["size"], self.size << 10)
self.assertEqual(disk_info["name"], vol.backend_volume_uuid)
self.assertEqual(disk_info["volume_name"], vol.backend_volume_uuid)
self.assertEqual(disk_info["origin"], "snf-snapshot-43")
def test_delete(self, mrapi):
# We can not deleted detached volumes
vol = mf.VolumeFactory(machine=None)
vol = mf.VolumeFactory(machine=None, status="AVAILABLE")
self.assertRaises(faults.BadRequest,
volumes.delete,
vol)
......@@ -141,6 +141,8 @@ class VolumesTest(BaseAPITest):
# Also we cannot delete root volume
vol.index = 0
vol.machine = vm
vol.status = "IN_USE"
vol.save()
self.assertRaises(faults.BadRequest,
volumes.delete,
vol)
......
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