Revision c25cc9ec api/tests.py
b/api/tests.py | ||
---|---|---|
1 | 1 |
# Copyright 2011 GRNET S.A. All rights reserved. |
2 |
#
|
|
2 |
# |
|
3 | 3 |
# Redistribution and use in source and binary forms, with or |
4 | 4 |
# without modification, are permitted provided that the following |
5 | 5 |
# conditions are met: |
6 |
#
|
|
6 |
# |
|
7 | 7 |
# 1. Redistributions of source code must retain the above |
8 | 8 |
# copyright notice, this list of conditions and the following |
9 | 9 |
# disclaimer. |
10 |
#
|
|
10 |
# |
|
11 | 11 |
# 2. Redistributions in binary form must reproduce the above |
12 | 12 |
# copyright notice, this list of conditions and the following |
13 | 13 |
# disclaimer in the documentation and/or other materials |
14 | 14 |
# provided with the distribution. |
15 |
#
|
|
15 |
# |
|
16 | 16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
17 | 17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | 18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
... | ... | |
25 | 25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
26 | 26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 | 27 |
# POSSIBILITY OF SUCH DAMAGE. |
28 |
#
|
|
28 |
# |
|
29 | 29 |
# The views and conclusions contained in the software and |
30 | 30 |
# documentation are those of the authors and should not be |
31 | 31 |
# interpreted as representing official policies, either expressed |
... | ... | |
68 | 68 |
def setUp(self): |
69 | 69 |
self.client = AaiClient() |
70 | 70 |
settings.MAX_VMS_PER_USER = 5 |
71 |
|
|
71 |
|
|
72 | 72 |
def test_api_version(self): |
73 | 73 |
"""Check API version.""" |
74 | 74 |
|
... | ... | |
137 | 137 |
self.assertEqual(vm_from_api['imageRef'], vm_from_db.flavor.id) |
138 | 138 |
self.assertEqual(vm_from_api['name'], vm_from_db.name) |
139 | 139 |
self.assertEqual(vm_from_api['status'], get_rsapi_state(vm_from_db)) |
140 |
self.assertTrue(response.status_code in [200,203]) |
|
140 |
self.assertTrue(response.status_code in [200, 203])
|
|
141 | 141 |
|
142 | 142 |
def test_wrong_server(self): |
143 | 143 |
"""Test 404 response if server does not exist.""" |
... | ... | |
347 | 347 |
name='User %d' % i, |
348 | 348 |
credit=0) |
349 | 349 |
|
350 |
|
|
350 | 351 |
def create_flavors(n=1): |
351 | 352 |
for i in range(n): |
352 | 353 |
Flavor.objects.create( |
... | ... | |
354 | 355 |
ram=randint(1, 8) * 512, |
355 | 356 |
disk=randint(1, 40)) |
356 | 357 |
|
358 |
|
|
357 | 359 |
def create_images(n=1): |
358 | 360 |
owner = SynnefoUser.objects.all()[0] |
359 | 361 |
for i in range(n): |
... | ... | |
362 | 364 |
state='ACTIVE', |
363 | 365 |
owner=owner) |
364 | 366 |
|
367 |
|
|
365 | 368 |
def create_image_metadata(n=1): |
366 | 369 |
images = Image.objects.all() |
367 | 370 |
for i in range(n): |
368 | 371 |
ImageMetadata.objects.create( |
369 | 372 |
meta_key='Key%d' % (i + 1), |
370 | 373 |
meta_value='Value %d' % (i + 1), |
371 |
image = choice(images)) |
|
374 |
image=choice(images)) |
|
375 |
|
|
372 | 376 |
|
373 | 377 |
def create_servers(n=1): |
374 | 378 |
owner = SynnefoUser.objects.all()[0] |
... | ... | |
382 | 386 |
hostid=str(i), |
383 | 387 |
flavor=choice(flavors)) |
384 | 388 |
|
389 |
|
|
385 | 390 |
def create_server_metadata(n=1): |
386 | 391 |
servers = VirtualMachine.objects.all() |
387 | 392 |
for i in range(n): |
388 | 393 |
VirtualMachineMetadata.objects.create( |
389 | 394 |
meta_key='Key%d' % (i + 1), |
390 | 395 |
meta_value='Value %d' % (i + 1), |
391 |
vm = choice(servers))
|
|
396 |
vm=choice(servers))
|
|
392 | 397 |
|
393 | 398 |
|
394 | 399 |
class AssertInvariant(object): |
... | ... | |
433 | 438 |
def assertItemNotFound(self, response): |
434 | 439 |
self.assertFault(response, 404, 'itemNotFound') |
435 | 440 |
|
436 |
|
|
437 | 441 |
def list_images(self, detail=False): |
438 | 442 |
path = '/api/v1.1/images' |
439 | 443 |
if detail: |
... | ... | |
758 | 762 |
response = self.client.get('/api/v1.1/images/0/meta') |
759 | 763 |
self.assertItemNotFound(response) |
760 | 764 |
|
765 |
|
|
761 | 766 |
class UpdateImageMetadata(BaseTestCase): |
762 | 767 |
IMAGE_METADATA = 10 |
763 | 768 |
|
... | ... | |
813 | 818 |
vm.operstate = 'STARTED' |
814 | 819 |
vm.save() |
815 | 820 |
server_id = vm.id |
816 |
|
|
821 |
|
|
817 | 822 |
path = '/api/v1.1/servers/%d/action' % server_id |
818 | 823 |
data = json.dumps({'console': {'type': 'vnc'}}) |
819 | 824 |
response = self.client.post(path, data, content_type='application/json') |
... | ... | |
838 | 843 |
response = self.client.get(self.apibase + '/servers', {}, |
839 | 844 |
**{'X-Auth-User': 'notme', |
840 | 845 |
'X-Auth-Key': '0xdeadbabe', |
841 |
'TEST-AAI' : 'true'})
|
|
846 |
'TEST-AAI': 'true'}) |
|
842 | 847 |
self.assertEquals(response.status_code, 401) |
843 | 848 |
|
844 | 849 |
def test_oapi_auth(self): |
... | ... | |
847 | 852 |
response = self.client.get(self.apibase + '/index.html', {}, |
848 | 853 |
**{'X-Auth-User': 'testdbuser', |
849 | 854 |
'X-Auth-Key': 'test@synnefo.gr', |
850 |
'TEST-AAI' : 'true'})
|
|
855 |
'TEST-AAI': 'true'}) |
|
851 | 856 |
self.assertEquals(response.status_code, 204) |
852 | 857 |
self.assertNotEqual(response['X-Auth-Token'], None) |
853 | 858 |
self.assertEquals(response['X-Server-Management-Url'], '') |
... | ... | |
912 | 917 |
|
913 | 918 |
class GetNetworkDetails(BaseTestCase): |
914 | 919 |
SERVERS = 5 |
915 |
|
|
920 |
|
|
916 | 921 |
def test_get_network_details(self): |
917 | 922 |
name = 'net' |
918 | 923 |
self.create_network(name) |
Also available in: Unified diff