commit 2d04422f4302baf75898fa4ffd618c9901ffec78
Author: Christos Stavrakakis <cstavr@grnet.gr>
Date:   Mon May 20 16:34:31 2013 +0300

    cyclades: Update tests
    
    Update tests to use OpenStack Compute API v2.
    
    Refs #3768

diff --git a/snf-cyclades-app/synnefo/api/test/flavors.py b/snf-cyclades-app/synnefo/api/test/flavors.py
index b786512..7b7b444 100644
--- a/snf-cyclades-app/synnefo/api/test/flavors.py
+++ b/snf-cyclades-app/synnefo/api/test/flavors.py
@@ -50,7 +50,7 @@ class FlavorAPITest(BaseAPITest):
         response = self.get('/api/v1.1/flavors')
         self.assertSuccess(response)
 
-        api_flavors = json.loads(response.content)['flavors']['values']
+        api_flavors = json.loads(response.content)['flavors']
         db_flavors = Flavor.objects.filter(deleted=False)
         self.assertEqual(len(api_flavors), len(db_flavors))
         for api_flavor in api_flavors:
@@ -64,7 +64,7 @@ class FlavorAPITest(BaseAPITest):
         self.assertSuccess(response)
 
         db_flavors = Flavor.objects.filter(deleted=False)
-        api_flavors = json.loads(response.content)['flavors']['values']
+        api_flavors = json.loads(response.content)['flavors']
 
         self.assertEqual(len(db_flavors), len(api_flavors))
 
@@ -108,7 +108,7 @@ class FlavorAPITest(BaseAPITest):
         """Test that deleted flavors do not appear to flavors list"""
         response = self.get('/api/v1.1/flavors')
         self.assertSuccess(response)
-        api_flavors = json.loads(response.content)['flavors']['values']
+        api_flavors = json.loads(response.content)['flavors']
         self.assertEqual(len(api_flavors), 2)
 
     def test_deleted_flavors_details(self):
@@ -116,7 +116,7 @@ class FlavorAPITest(BaseAPITest):
         FlavorFactory(deleted=True)
         response = self.get('/api/v1.1/flavors/detail')
         self.assertSuccess(response)
-        api_flavors = json.loads(response.content)['flavors']['values']
+        api_flavors = json.loads(response.content)['flavors']
         self.assertEqual(len(api_flavors), 2)
 
     def test_wrong_flavor(self):
diff --git a/snf-cyclades-app/synnefo/api/test/images.py b/snf-cyclades-app/synnefo/api/test/images.py
index f1057b6..3f1aa80 100644
--- a/snf-cyclades-app/synnefo/api/test/images.py
+++ b/snf-cyclades-app/synnefo/api/test/images.py
@@ -69,7 +69,7 @@ class ImageAPITest(BaseAPITest):
         mimage().list_images.return_value = images
         response = self.get('/api/v1.1/images/', 'user')
         self.assertSuccess(response)
-        api_images = json.loads(response.content)['images']['values']
+        api_images = json.loads(response.content)['images']
         self.assertEqual(images, api_images)
 
     @assert_backend_closed
@@ -102,7 +102,7 @@ class ImageAPITest(BaseAPITest):
                    'progress': 100,
                    'created': '2012-11-26T11:52:54+00:00',
                    'updated': '2012-12-26T11:52:54+00:00',
-                   'metadata': {'values': {'foo':'bar'}}},
+                   'metadata': {'foo':'bar'}},
                   {'id': 2,
                    'name': 'image-2',
                    'status': 'DELETED',
@@ -118,7 +118,7 @@ class ImageAPITest(BaseAPITest):
         mimage().list_images.return_value = images
         response = self.get('/api/v1.1/images/detail', 'user')
         self.assertSuccess(response)
-        api_images = json.loads(response.content)['images']['values']
+        api_images = json.loads(response.content)['images']
         self.assertEqual(len(result_images), len(api_images))
         self.assertEqual(result_images, api_images)
 
@@ -150,7 +150,7 @@ class ImageAPITest(BaseAPITest):
         response =\
             self.get('/api/v1.1/images/detail?changes-since=%sUTC' % new_time)
         self.assertSuccess(response)
-        api_images = json.loads(response.content)['images']['values']
+        api_images = json.loads(response.content)['images']
         self.assertEqual(1, len(api_images))
 
     @assert_backend_closed
@@ -169,7 +169,7 @@ class ImageAPITest(BaseAPITest):
                    'progress': 100,
                    'created': '2012-11-26T11:52:54+00:00',
                    'updated': '2012-12-26T11:52:54+00:00',
-                   'metadata': {'values': {'foo': 'bar'}}}
+                   'metadata': {'foo': 'bar'}}
         mimage.return_value.get_image.return_value = image
         response = self.get('/api/v1.1/images/42', 'user')
         self.assertSuccess(response)
@@ -207,20 +207,20 @@ class ImageMetadataAPITest(BaseAPITest):
                    'progress': 100,
                    'created': '2012-11-26T11:52:54+00:00',
                    'updated': '2012-12-26T11:52:54+00:00',
-                   'metadata': {'values': {'foo': 'bar'}}}
+                   'metadata': {'foo': 'bar'}}
 
     @assert_backend_closed
     def test_list_metadata(self, backend):
         backend.return_value.get_image.return_value = self.image
-        response = self.get('/api/v1.1/images/42/meta', 'user')
+        response = self.get('/api/v1.1/images/42/metadata', 'user')
         self.assertSuccess(response)
-        meta = json.loads(response.content)['metadata']['values']
+        meta = json.loads(response.content)['metadata']
         self.assertEqual(meta, self.image['properties'])
 
     @assert_backend_closed
     def test_get_metadata(self, backend):
         backend.return_value.get_image.return_value = self.image
-        response = self.get('/api/v1.1/images/42/meta/foo', 'user')
+        response = self.get('/api/v1.1/images/42/metadata/foo', 'user')
         self.assertSuccess(response)
         meta = json.loads(response.content)['meta']
         self.assertEqual(meta['foo'], 'bar')
@@ -228,12 +228,12 @@ class ImageMetadataAPITest(BaseAPITest):
     @assert_backend_closed
     def test_get_invalid_metadata(self, backend):
         backend.return_value.get_image.return_value = self.image
-        response = self.get('/api/v1.1/images/42/meta/not_found', 'user')
+        response = self.get('/api/v1.1/images/42/metadata/not_found', 'user')
         self.assertItemNotFound(response)
 
     def test_delete_metadata_item(self, backend):
         backend.return_value.get_image.return_value = self.image
-        response = self.delete('/api/v1.1/images/42/meta/foo', 'user')
+        response = self.delete('/api/v1.1/images/42/metadata/foo', 'user')
         self.assertEqual(response.status_code, 204)
         backend.return_value.update_metadata.assert_called_once_with('42', {'properties': {'foo2':
                                                     'bar2'}})
@@ -242,7 +242,7 @@ class ImageMetadataAPITest(BaseAPITest):
     def test_create_metadata_item(self, backend):
         backend.return_value.get_image.return_value = self.image
         request = {'meta': {'foo3': 'bar3'}}
-        response = self.put('/api/v1.1/images/42/meta/foo3', 'user',
+        response = self.put('/api/v1.1/images/42/metadata/foo3', 'user',
                             json.dumps(request), 'json')
         self.assertEqual(response.status_code, 201)
         backend.return_value.update_metadata.assert_called_once_with('42',
@@ -253,15 +253,15 @@ class ImageMetadataAPITest(BaseAPITest):
     def test_create_metadata_malformed_1(self, backend):
         backend.return_value.get_image.return_value = self.image
         request = {'met': {'foo3': 'bar3'}}
-        response = self.put('/api/v1.1/images/42/meta/foo3', 'user',
+        response = self.put('/api/v1.1/images/42/metadata/foo3', 'user',
                             json.dumps(request), 'json')
         self.assertBadRequest(response)
 
     @assert_backend_closed
     def test_create_metadata_malformed_2(self, backend):
         backend.return_value.get_image.return_value = self.image
-        request = {'meta': [('foo3', 'bar3')]}
-        response = self.put('/api/v1.1/images/42/meta/foo3', 'user',
+        request = {'metadata': [('foo3', 'bar3')]}
+        response = self.put('/api/v1.1/images/42/metadata/foo3', 'user',
                             json.dumps(request), 'json')
         self.assertBadRequest(response)
 
@@ -269,7 +269,7 @@ class ImageMetadataAPITest(BaseAPITest):
     def test_create_metadata_malformed_3(self, backend):
         backend.return_value.get_image.return_value = self.image
         request = {'met': {'foo3': 'bar3', 'foo4': 'bar4'}}
-        response = self.put('/api/v1.1/images/42/meta/foo3', 'user',
+        response = self.put('/api/v1.1/images/42/metadata/foo3', 'user',
                                 json.dumps(request), 'json')
         self.assertBadRequest(response)
 
@@ -277,7 +277,7 @@ class ImageMetadataAPITest(BaseAPITest):
     def test_create_metadata_malformed_4(self, backend):
         backend.return_value.get_image.return_value = self.image
         request = {'met': {'foo3': 'bar3'}}
-        response = self.put('/api/v1.1/images/42/meta/foo4', 'user',
+        response = self.put('/api/v1.1/images/42/metadata/foo4', 'user',
                                 json.dumps(request), 'json')
         self.assertBadRequest(response)
 
@@ -285,7 +285,7 @@ class ImageMetadataAPITest(BaseAPITest):
     def test_update_metadata_item(self, backend):
         backend.return_value.get_image.return_value = self.image
         request = {'metadata': {'foo': 'bar_new', 'foo4': 'bar4'}}
-        response = self.post('/api/v1.1/images/42/meta', 'user',
+        response = self.post('/api/v1.1/images/42/metadata', 'user',
                              json.dumps(request), 'json')
         self.assertEqual(response.status_code, 201)
         backend.return_value.update_metadata.assert_called_once_with('42',
@@ -297,6 +297,6 @@ class ImageMetadataAPITest(BaseAPITest):
     def test_update_metadata_malformed(self, backend):
         backend.return_value.get_image.return_value = self.image
         request = {'meta': {'foo': 'bar_new', 'foo4': 'bar4'}}
-        response = self.post('/api/v1.1/images/42/meta', 'user',
+        response = self.post('/api/v1.1/images/42/metadata', 'user',
                             json.dumps(request), 'json')
         self.assertBadRequest(response)
diff --git a/snf-cyclades-app/synnefo/api/test/networks.py b/snf-cyclades-app/synnefo/api/test/networks.py
index 0c183e2..419d79b 100644
--- a/snf-cyclades-app/synnefo/api/test/networks.py
+++ b/snf-cyclades-app/synnefo/api/test/networks.py
@@ -68,7 +68,7 @@ class NetworkAPITest(BaseAPITest):
             self.assertEqual(db_net.public, api_net['public'])
             db_nics = ["nic-%d-%d" % (nic.machine.id, nic.index) for nic in
                        db_net.nics.filter(machine__userid=db_net.userid)]
-            self.assertEqual(db_nics, api_net['attachments']['values'])
+            self.assertEqual(db_nics, api_net['attachments'])
 
     def test_create_network_1(self, mrapi):
         request = {
@@ -189,7 +189,7 @@ class NetworkAPITest(BaseAPITest):
         self.assertSuccess(response)
 
         db_nets = Network.objects.filter(userid=self.user, deleted=False)
-        api_nets = json.loads(response.content)["networks"]["values"]
+        api_nets = json.loads(response.content)["networks"]
 
         self.assertEqual(len(db_nets), len(api_nets))
         for api_net in api_nets:
@@ -205,7 +205,7 @@ class NetworkAPITest(BaseAPITest):
         self.assertSuccess(response)
 
         db_nets = Network.objects.filter(userid=self.user, deleted=False)
-        api_nets = json.loads(response.content)["networks"]["values"]
+        api_nets = json.loads(response.content)["networks"]
 
         self.assertEqual(len(db_nets), len(api_nets))
         for api_net in api_nets:
@@ -222,7 +222,7 @@ class NetworkAPITest(BaseAPITest):
                             net.userid)
         self.assertSuccess(response)
         api_net = json.loads(response.content)["network"]
-        self.assertEqual(len(api_net["attachments"]["values"]), 0)
+        self.assertEqual(len(api_net["attachments"]), 0)
 
     def test_network_details_1(self, mrapi):
         """Test that expected details for a network are returned"""
diff --git a/snf-cyclades-app/synnefo/api/test/servers.py b/snf-cyclades-app/synnefo/api/test/servers.py
index e513a39..b635d89 100644
--- a/snf-cyclades-app/synnefo/api/test/servers.py
+++ b/snf-cyclades-app/synnefo/api/test/servers.py
@@ -55,14 +55,14 @@ class ServerAPITest(BaseAPITest):
         """Test if the expected list of servers is returned."""
         response = self.get('/api/v1.1/servers')
         self.assertSuccess(response)
-        servers = json.loads(response.content)['servers']['values']
+        servers = json.loads(response.content)['servers']
         self.assertEqual(servers, [])
 
     def test_server_list_2(self):
         """Test if the expected list of servers is returned."""
         response = self.get('/api/v1.1/servers', self.user1)
         self.assertSuccess(response)
-        servers = json.loads(response.content)['servers']['values']
+        servers = json.loads(response.content)['servers']
         db_server = self.vm1
         self.assertEqual(servers, [{'name': db_server.name,
                                     'id': db_server.id}])
@@ -74,7 +74,7 @@ class ServerAPITest(BaseAPITest):
                     self.vm4.id: self.vm4}
 
         response = self.get('/api/v1.1/servers/detail', user)
-        servers = json.loads(response.content)['servers']['values']
+        servers = json.loads(response.content)['servers']
         self.assertEqual(len(servers), len(user_vms))
         for api_vm in servers:
             db_vm = user_vms[api_vm['id']]
@@ -104,7 +104,7 @@ class ServerAPITest(BaseAPITest):
         self.assertEqual(server['image'], db_vm.imageid)
         self.assertEqual(server['name'], db_vm.name)
         self.assertEqual(server['status'], get_rsapi_state(db_vm))
-        api_nic = server['attachments']['values'][0]
+        api_nic = server['attachments'][0]
         self.assertEqual(api_nic['network_id'], str(net.id))
         self.assertEqual(api_nic['mac_address'], nic.mac)
         self.assertEqual(api_nic['firewallProfile'], nic.firewall_profile)
@@ -112,7 +112,7 @@ class ServerAPITest(BaseAPITest):
         self.assertEqual(api_nic['ipv6'], nic.ipv6)
         self.assertEqual(api_nic['id'], 'nic-%s-%s' % (db_vm.id, nic.index))
 
-        metadata = server['metadata']['values']
+        metadata = server['metadata']
         self.assertEqual(len(metadata), 1)
         self.assertEqual(metadata[db_vm_meta.meta_key], db_vm_meta.meta_value)
         self.assertSuccess(response)
@@ -132,7 +132,7 @@ class ServerAPITest(BaseAPITest):
 
         response = self.get('/api/v1.1/servers/%d' % db_vm.id, user)
         server = json.loads(response.content)['server']
-        nics = server["attachments"]["values"]
+        nics = server["attachments"]
         self.assertEqual(len(nics), 1)
         self.assertEqual(nics[0]["network_id"], str(nic2.network_id))
 
@@ -203,7 +203,7 @@ class ServerCreateAPITest(BaseAPITest):
         api_server = json.loads(response.content)['server']
         self.assertEqual(api_server['status'], "BUILD")
         self.assertEqual(api_server['progress'], 0)
-        self.assertEqual(api_server['metadata']['values'],
+        self.assertEqual(api_server['metadata'],
                         {"My Server Name":  "Apache1"})
         self.assertTrue('adminPass' in api_server)
 
@@ -253,9 +253,9 @@ class ServerMetadataAPITest(BaseAPITest):
         vm = self.vm
         create_meta = lambda: mfactory.VirtualMachineMetadataFactory(vm=vm)
         metadata = [create_meta(), create_meta(), create_meta()]
-        response = self.get('/api/v1.1/servers/%d/meta' % vm.id, vm.userid)
+        response = self.get('/api/v1.1/servers/%d/metadata' % vm.id, vm.userid)
         self.assertTrue(response.status_code in [200, 203])
-        api_metadata = json.loads(response.content)['metadata']['values']
+        api_metadata = json.loads(response.content)['metadata']
         self.assertEqual(len(api_metadata), len(metadata) + 1)
         for db_m in metadata:
             self.assertEqual(api_metadata[db_m.meta_key], db_m.meta_value)
@@ -264,12 +264,12 @@ class ServerMetadataAPITest(BaseAPITest):
                         {'foo': 'bar'},
                         metadata[0].meta_key: 'bar2'
                   }
-        response = self.post('/api/v1.1/servers/%d/meta' % vm.id, vm.userid,
-                             json.dumps(request), 'json')
+        response = self.post('/api/v1.1/servers/%d/metadata' % vm.id,
+                             vm.userid, json.dumps(request), 'json')
         metadata2 = VirtualMachineMetadata.objects.filter(vm=vm)
-        response = self.get('/api/v1.1/servers/%d/meta' % vm.id, vm.userid)
+        response = self.get('/api/v1.1/servers/%d/metadata' % vm.id, vm.userid)
         self.assertTrue(response.status_code in [200, 203])
-        api_metadata2 = json.loads(response.content)['metadata']['values']
+        api_metadata2 = json.loads(response.content)['metadata']
         self.assertTrue('foo' in api_metadata2.keys())
         self.assertTrue(api_metadata2[metadata[0].meta_key], 'bar2')
         self.assertEqual(len(api_metadata2), len(metadata2))
@@ -278,38 +278,39 @@ class ServerMetadataAPITest(BaseAPITest):
 
         # Create new meta
         request = {'meta': {'foo2': 'bar2'}}
-        response = self.put('/api/v1.1/servers/%d/meta/foo2' % vm.id,
+        response = self.put('/api/v1.1/servers/%d/metadata/foo2' % vm.id,
                             vm.userid, json.dumps(request), 'json')
 
         # Get the new meta
-        response = self.get('/api/v1.1/servers/%d/meta/foo2' % vm.id,
+        response = self.get('/api/v1.1/servers/%d/metadata/foo2' % vm.id,
                             vm.userid)
         meta = json.loads(response.content)['meta']
         self.assertEqual(meta['foo2'], 'bar2')
 
         # Delete the new meta
-        response = self.delete('/api/v1.1/servers/%d/meta/foo2' % vm.id,
+        response = self.delete('/api/v1.1/servers/%d/metadata/foo2' % vm.id,
                                vm.userid)
         self.assertEqual(response.status_code, 204)
 
         # Try to get the deleted meta: should raise 404
-        response = self.get('/api/v1.1/servers/%d/meta/foo2' % vm.id,
+        response = self.get('/api/v1.1/servers/%d/metadata/foo2' % vm.id,
                             vm.userid)
         self.assertEqual(response.status_code, 404)
 
     def test_invalid_metadata(self):
         vm = self.vm
-        response = self.post('/api/v1.1/servers/%d/meta' % vm.id, vm.userid)
+        response = self.post('/api/v1.1/servers/%d/metadata' % vm.id,
+                             vm.userid)
         self.assertBadRequest(response)
         self.assertEqual(len(vm.metadata.all()), 1)
 
     def test_invalid_metadata_server(self):
-        response = self.post('/api/v1.1/servers/42/meta', 'user')
+        response = self.post('/api/v1.1/servers/42/metadata', 'user')
         self.assertItemNotFound(response)
 
     def test_get_meta_invalid_key(self):
         vm = self.vm
-        response = self.get('/api/v1.1/servers/%d/meta/foo2' % vm.id,
+        response = self.get('/api/v1.1/servers/%d/metadata/foo2' % vm.id,
                             vm.userid)
         self.assertItemNotFound(response)
 
