Commit 80678f1a authored by Giorgos Verigakis's avatar Giorgos Verigakis
Browse files

Port tests to the new API

manage.py test api should work now
parent 5da8e700
[
{
"model": "db.Image",
"pk": 1,
"fields": {
"name": "Debian Unstable",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"state": "ACTIVE",
"description": "Debian Sid, full installation",
"size": 4096
}
},
{
"model": "db.Image",
"pk": 2,
"fields": {
"name": "Red Hat Enterprise Linux",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"state": "ACTIVE",
"description": "Red Hat Enterprise Linux, full installation",
"size": 2048
}
},
{
"model": "db.Image",
"pk": 3,
"fields": {
"name": "Ubuntu 10.10",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"state": "ACTIVE",
"description": "Ubuntu 10.10, full installation",
"size": 8192
}
},
{
"model": "db.Flavor",
"pk": 1,
"fields": {
"cpu": 1,
"ram": 1024,
"disk": 20
}
},
{
"model": "db.Flavor",
"pk": 2,
"fields": {
"cpu": 1,
"ram": 1024,
"disk": 40
}
},
{
"model": "db.Flavor",
"pk": 3,
"fields": {
"cpu": 1,
"ram": 1024,
"disk": 80
}
}
]
......@@ -249,9 +249,7 @@
"name": "Debian Squeeze",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"state": "ACTIVE",
"description": "Full Debian Squeeze Installation",
"size": 5678
"state": "ACTIVE"
}
},
{
......@@ -330,33 +328,8 @@
"created": "2011-02-10 00:00:00",
"updated": "2011-02-10 00:00:00",
"state": "ACTIVE",
"description": "Full Slackware 13.1 Installation",
"size": 1234,
"owner" : 1,
"sourcevm": 1001
}
},
{
"model": "db.VirtualMachineGroup",
"pk": 1,
"fields": {
"name": "one group of vms",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"owner" : 1,
"machines" : [1001,1002]
}
},
{
"model": "db.VirtualMachineGroup",
"pk": 2,
"fields": {
"name": "a second group of vms",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"owner" : 1,
"machines" : [1003,1004]
}
}
]
This diff is collapsed.
#
# Copyright (c) 2010 Greek Research and Technology Network
#
from django.test import TestCase
from django.test.client import Client
from django.utils import simplejson as json
API = 'v1.1redux'
class APIReduxTestCase(TestCase):
fixtures = [ 'api_redux_test_data' ]
def setUp(self):
self.client = Client()
self.server_id = 0
def create_server_name(self):
self.server_id += 1
return 'server%d' % self.server_id
def test_create_server_json(self):
TEMPLATE = '''
{
"server" : {
"name" : "%(name)s",
"flavorRef" : "%(flavorRef)s",
"imageRef" : "%(imageRef)s"
}
}
'''
def new_server(imageRef=1, flavorRef=1):
name = self.create_server_name()
return name, TEMPLATE % dict(name=name, imageRef=imageRef, flavorRef=flavorRef)
def verify_response(response, name):
assert response.status_code == 202
reply = json.loads(response.content)
server = reply['server']
assert server['name'] == name
assert server['imageRef'] == 1
assert server['flavorRef'] == 1
assert server['status'] == 'BUILD'
assert server['adminPass']
assert server['addresses']
def verify_error(response, code, name):
assert response.status_code == code
reply = json.loads(response.content)
assert name in reply
assert reply[name]['code'] == code
name, data = new_server()
url = '/api/%s/servers' % API
response = self.client.post(url, content_type='application/json', data=data)
verify_response(response, name)
name, data = new_server()
url = '/api/%s/servers.json' % API
response = self.client.post(url, content_type='application/json', data=data)
verify_response(response, name)
name, data = new_server()
url = '/api/%s/servers.json' % API
response = self.client.post(url, content_type='application/json', data=data,
HTTP_ACCEPT='application/xml')
verify_response(response, name)
name, data = new_server(imageRef=0)
url = '/api/%s/servers' % API
response = self.client.post(url, content_type='application/json', data=data)
verify_error(response, 404, 'itemNotFound')
name, data = new_server(flavorRef=0)
url = '/api/%s/servers' % API
response = self.client.post(url, content_type='application/json', data=data)
verify_error(response, 404, 'itemNotFound')
url = '/api/%s/servers' % API
response = self.client.post(url, content_type='application/json', data='INVALID')
verify_error(response, 400, 'badRequest')
......@@ -6,7 +6,7 @@
"name": "Debian Unstable",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"state": "ACTIVE",
"state": "ACTIVE"
}
},
{
......@@ -16,7 +16,7 @@
"name": "Red Hat Enterprise Linux",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"state": "ACTIVE",
"state": "ACTIVE"
}
},
{
......@@ -26,7 +26,7 @@
"name": "Ubuntu 10.10",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"state": "ACTIVE",
"state": "ACTIVE"
}
},
{
......
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