Commit 1fb70dd6 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add some unicode unittests

parent 7f4eca15
......@@ -87,9 +87,9 @@ class ImageAPITest(ComputeAPITest):
@assert_backend_closed
def test_list_images(self, mimage):
"""Test that expected list of images is returned"""
images = [{'id': 1, 'name': 'image-1'},
{'id': 2, 'name': 'image-2'},
{'id': 3, 'name': 'image-3'}]
images = [{'id': 1, 'name': u'image-1 \u2601'},
{'id': 2, 'name': u'image-2 \u2602'},
{'id': 3, 'name': u'image-3 \u2603'}]
mimage().list_images.return_value = images
response = self.myget('images', 'user')
self.assertSuccess(response)
......@@ -99,13 +99,13 @@ class ImageAPITest(ComputeAPITest):
@assert_backend_closed
def test_list_images_detail(self, mimage):
images = [{'id': 1,
'name': 'image-1',
'status':'available',
'name': u'image-1 \u2601',
'status': 'available',
'created_at': '2012-11-26 11:52:54',
'updated_at': '2012-12-26 11:52:54',
'owner': 'user1',
'deleted_at': '',
'properties': {'foo':'bar'}},
'properties': {u'foo\u2610': u'bar\u2611'}},
{'id': 2,
'name': 'image-2',
'status': 'deleted',
......@@ -124,14 +124,14 @@ class ImageAPITest(ComputeAPITest):
'properties': ''}]
result_images = [
{'id': 1,
'name': 'image-1',
'status':'ACTIVE',
'name': u'image-1 \u2601',
'status': 'ACTIVE',
'progress': 100,
'created': '2012-11-26T11:52:54+00:00',
'updated': '2012-12-26T11:52:54+00:00',
'user_id': 'user1',
'tenant_id': 'user1',
'metadata': {'foo':'bar'}},
'metadata': {u'foo\u2610': u'bar\u2611'}},
{'id': 2,
'name': 'image-2',
'status': 'DELETED',
......
......@@ -73,17 +73,16 @@ class NetworkTest(BaseAPITest):
request = {
"network": {
"type": "MAC_FILTERED",
"name": ["Test"]
"name": ["Test", u"I need\u2602"]
}
}
response = self.post(NETWORKS_URL, params=json.dumps(request))
code = response.status_code
self.assertBadRequest(response)
def test_create(self):
request = {
"network": {
"name": "sample_network",
"name": u"Funky Network\u2602",
"type": "MAC_FILTERED"
}
}
......@@ -95,7 +94,7 @@ class NetworkTest(BaseAPITest):
code = response.status_code
self.assertEqual(code, 201)
res = json.loads(response.content)
self.assertEqual(res["network"]["name"], "sample_network")
self.assertEqual(res["network"]["name"], u"Funky Network\u2602")
# TEST QUOTAS!!!
name, args, kwargs =\
......@@ -199,10 +198,11 @@ class NetworkTest(BaseAPITest):
def test_rename_network(self):
test_net = dbmf.NetworkFactory(name="foo")
url = join_urls(NETWORKS_URL, str(test_net.id))
request = {'network': {'name': "new_name"}}
request = {'network': {'name': u"Cloud \u2601"}}
response = self.put(url, test_net.userid, json.dumps(request), 'json')
self.assertEqual(response.status_code, 200)
self.assertEqual(Network.objects.get(id=test_net.id).name, "new_name")
self.assertEqual(Network.objects.get(id=test_net.id).name,
u"Cloud \u2601")
# test if server deleted
test_net.deleted = True
test_net.save()
......@@ -225,135 +225,3 @@ class NetworkTest(BaseAPITest):
url = join_urls(NETWORKS_URL, "42")
response = self.post(url)
self.assertMethodNotAllowed(response)
#class NetworkNICsAPITest(BaseAPITest):
# def test_get_network_building_nics(self, mrapi):
# net = dbmf.NetworkFactory()
# machine = dbmf.VirtualMachineFactory(userid=net.userid)
# dbmf.NetworkInterfaceFactory(network=net, machine=machine,
# state="BUILDING")
# response = self.myget('networks/%d' % net.id, net.userid)
# self.assertSuccess(response)
# api_net = json.loads(response.content)["network"]
# self.assertEqual(len(api_net["attachments"]), 0)
#
#
# def test_add_nic(self, mrapi):
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
# net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
# mrapi().ModifyInstance.return_value = 1
# request = {'add': {'serverRef': vm.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# self.assertEqual(response.status_code, 202)
#
# def test_add_nic_to_deleted_network(self, mrapi):
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
# operstate="ACTIVE")
# net = dbmf.NetworkFactory(state='ACTIVE', userid=user,
# deleted=True)
# request = {'add': {'serverRef': vm.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# self.assertBadRequest(response)
# self.assertFalse(mrapi.called)
#
# def test_add_nic_to_public_network(self, mrapi):
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
# net = dbmf.NetworkFactory(state='ACTIVE', userid=user, public=True)
# request = {'add': {'serverRef': vm.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# self.assertFault(response, 403, 'forbidden')
# self.assertFalse(mrapi.called)
#
# def test_add_nic_malformed_1(self, mrapi):
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
# net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
# request = {'add': {'serveRef': vm.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# self.assertBadRequest(response)
# self.assertFalse(mrapi.called)
#
# def test_add_nic_malformed_2(self, mrapi):
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
# net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
# request = {'add': {'serveRef': [vm.id, 22]}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# self.assertBadRequest(response)
# self.assertFalse(mrapi.called)
#
# def test_add_nic_not_active(self, mrapi):
# """Test connecting VM to non-active network"""
# user = 'dummy'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
# net = dbmf.NetworkFactory(state='PENDING', subnet='10.0.0.0/31',
# userid=user)
# request = {'add': {'serverRef': vm.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# # Test that returns BuildInProgress
# self.assertEqual(response.status_code, 409)
# self.assertFalse(mrapi.called)
#
# def test_add_nic_full_network(self, mrapi):
# """Test connecting VM to a full network"""
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
# operstate="STARTED")
# net = dbmf.NetworkFactory(state='ACTIVE', subnet='10.0.0.0/30',
# userid=user, dhcp=True)
# pool = net.get_pool()
# while not pool.empty():
# pool.get()
# pool.save()
# pool = net.get_pool()
# self.assertTrue(pool.empty())
# request = {'add': {'serverRef': vm.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# # Test that returns OverLimit
# self.assertEqual(response.status_code, 413)
# self.assertFalse(mrapi.called)
#
# def test_remove_nic(self, mrapi):
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
# operstate="ACTIVE")
# net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
# nic = dbmf.NetworkInterfaceFactory(machine=vm, network=net)
# mrapi().ModifyInstance.return_value = 1
# request = {'remove': {'attachment': "%s" % nic.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# self.assertEqual(response.status_code, 202)
# vm.task = None
# vm.task_job_id = None
# vm.save()
#
# def test_remove_nic_malformed(self, mrapi):
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
# net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
# nic = dbmf.NetworkInterfaceFactory(machine=vm, network=net)
# request = {'remove': {'att234achment': '%s' % nic.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# self.assertBadRequest(response)
#
# def test_remove_nic_malformed_2(self, mrapi):
# user = 'userr'
# vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
# net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
# request = {'remove': {'attachment': 'nic-%s' % vm.id}}
# response = self.mypost('networks/%d/action' % net.id,
# net.userid, json.dumps(request), 'json')
# self.assertBadRequest(response)
......@@ -84,38 +84,13 @@ class PortTest(BaseAPITest):
def test_update_port_name(self):
nic = dbmf.NetworkInterfaceFactory(device_owner='vm')
url = join_urls(PORTS_URL, str(nic.id))
request = {'port': {"name": "test-name"}}
request = {'port': {"name": u"test-name\u2601\u2602"}}
response = self.put(url, params=json.dumps(request),
user=nic.userid)
self.assertEqual(response.status_code, 200)
res = json.loads(response.content)
self.assertEqual(res['port']['name'], "test-name")
# def test_update_port_sg_unfound(self):
# sg1 = dbmf.SecurityGroupFactory()
# nic = dbmf.NetworkInterfaceFactory(device_owner='vm')
# nic.security_groups.add(sg1)
# nic.save()
# url = join_urls(PORTS_URL, str(nic.id))
# request = {'port': {"security_groups": ["123"]}}
# response = self.put(url, params=json.dumps(request),
# user=nic.userid)
# self.assertEqual(response.status_code, 404)
# def test_update_port_sg(self):
# sg1 = dbmf.SecurityGroupFactory()
# sg2 = dbmf.SecurityGroupFactory()
# sg3 = dbmf.SecurityGroupFactory()
# nic = dbmf.NetworkInterfaceFactory(device_owner='vm')
# nic.security_groups.add(sg1)
# nic.save()
# url = join_urls(PORTS_URL, str(nic.id))
# request = {'port': {"security_groups": [str(sg2.id), str(sg3.id)]}}
# response = self.put(url, params=json.dumps(request),
# user=nic.userid)
# res = json.loads(response.content)
# self.assertEqual(res['port']['security_groups'],
# [str(sg2.id), str(sg3.id)])
self.assertEqual(res['port']['name'],
u"test-name\u2601\u2602")
def test_create_port_invalid(self):
# No network
......@@ -133,7 +108,7 @@ class PortTest(BaseAPITest):
"port": {
"name": "port1",
"network_id": net.id,
"fixed_ips": ["lala"]
"fixed_ips": [u"lala\u2608"]
}
}
response = self.post(PORTS_URL, params=json.dumps(request))
......@@ -170,7 +145,7 @@ class PortTest(BaseAPITest):
vm = dbmf.VirtualMachineFactory(userid=net.userid)
request = {
"port": {
"name": "port1",
"name": u"Port in the \u2601",
"network_id": str(net.id),
"device_id": str(vm.id),
}
......@@ -184,7 +159,7 @@ class PortTest(BaseAPITest):
vm = dbmf.VirtualMachineFactory(userid=net.userid)
request = {
"port": {
"name": "port1",
"name": u"Port in the \u2601",
"network_id": str(net.id),
"device_id": str(vm.id),
"fixed_ips": [{"ip_address": "8.8.8.8"}]
......@@ -233,7 +208,7 @@ class PortTest(BaseAPITest):
userid=vm.userid)
request = {
"port": {
"name": "port1",
"name": "Port in the \u2601",
"network_id": str(fip.network_id),
"device_id": str(vm.id),
"fixed_ips": [{"ip_address": fip.address}]
......
# encoding: utf-8
# Copyright 2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
......@@ -76,7 +77,8 @@ class ServerAPITest(ComputeAPITest):
def setUp(self):
self.user1 = 'user1'
self.user2 = 'user2'
self.vm1 = mfactory.VirtualMachineFactory(userid=self.user1)
self.vm1 = mfactory.VirtualMachineFactory(userid=self.user1,
name=u"Hi \u2601")
self.vm2 = mfactory.VirtualMachineFactory(userid=self.user2)
self.vm3 = mfactory.VirtualMachineFactory(deleted=True,
userid=self.user1)
......@@ -96,7 +98,7 @@ class ServerAPITest(ComputeAPITest):
servers = json.loads(response.content)['servers']
db_server = self.vm1
server = servers[0]
self.assertEqual(server["name"], db_server.name)
self.assertEqual(server["name"], u"Hi \u2601")
self.assertEqual(server["id"], db_server.id)
def test_server_list_detail(self):
......@@ -332,12 +334,12 @@ class ServerCreateAPITest(ComputeAPITest):
self.backend = mfactory.BackendFactory()
self.request = {
"server": {
"name": "new-server-test",
"name": u"Server in the \u2601",
"userid": "test_user",
"imageRef": 1,
"flavorRef": self.flavor.id,
"metadata": {
"My Server Name": "Apache1"
u"Meta \u2601": u"Meta in the \u2601"
},
"personality": []
}
......@@ -365,12 +367,12 @@ class ServerCreateAPITest(ComputeAPITest):
api_server = json.loads(response.content)['server']
self.assertEqual(api_server['status'], "BUILD")
self.assertEqual(api_server['progress'], 0)
self.assertEqual(api_server['metadata'],
{"My Server Name": "Apache1"})
self.assertEqual(api_server['metadata'][u"Meta \u2601"],
u"Meta in the \u2601")
self.assertTrue('adminPass' in api_server)
db_vm = VirtualMachine.objects.get(userid='test_user')
self.assertEqual(api_server['name'], db_vm.name)
self.assertEqual(api_server['name'], u"Server in the \u2601")
self.assertEqual(api_server['status'], db_vm.operstate)
def test_create_server_wrong_flavor(self, mrapi):
......
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