Revision 40777cc8 api/tests.py

b/api/tests.py
15 15
from django.test import TestCase
16 16
from django.test.client import Client
17 17

  
18
#from synnefo.api.tests_auth import AuthTestCase
19 18
from synnefo.db.models import *
20
from synnefo.logic import utils
19
from synnefo.logic.utils import get_rsapi_state
20

  
21

  
22
class AaiClient(Client):
23
    def request(self, **request):
24
        request['HTTP_X_AUTH_TOKEN'] = '46e427d657b20defe352804f0eb6f8a2'
25
        return super(AaiClient, self).request(**request)
21 26

  
22 27

  
23 28
class APITestCase(TestCase):
......
33 38
    #make the testing with these id's
34 39

  
35 40
    def setUp(self):
36
        self.client = Client()
41
        self.client = AaiClient()
37 42

  
38 43
    def test_api_version(self):
39 44
        """Check API version."""
......
68 73
        self.assertEqual(vm_from_api['id'], vm_from_db.id)
69 74
        self.assertEqual(vm_from_api['imageRef'], vm_from_db.flavor.id)
70 75
        self.assertEqual(vm_from_api['name'], vm_from_db.name)
71
        self.assertEqual(vm_from_api['status'], utils.get_rsapi_state(vm_from_db))
76
        self.assertEqual(vm_from_api['status'], get_rsapi_state(vm_from_db))
72 77
        self.assertTrue(response.status_code in [200, 203])
73 78

  
74 79
    def test_servers_details(self):
......
93 98
            self.assertEqual(vm_from_api['id'], vm_from_db.id)
94 99
            self.assertEqual(vm_from_api['imageRef'], vm_from_db.flavor.id)
95 100
            self.assertEqual(vm_from_api['name'], vm_from_db.name)
96
            self.assertEqual(vm_from_api['status'], utils.get_rsapi_state(vm_from_db))
101
            self.assertEqual(vm_from_api['status'], get_rsapi_state(vm_from_db))
97 102
            number += 1
98 103
        for vm_from_api in vms_from_api:
99 104
            vm_from_db = VirtualMachine.objects.get(id=vm_from_api['id'])
......
102 107
            self.assertEqual(vm_from_api['id'], vm_from_db.id)
103 108
            self.assertEqual(vm_from_api['imageRef'], vm_from_db.flavor.id)
104 109
            self.assertEqual(vm_from_api['name'], vm_from_db.name)
105
            self.assertEqual(vm_from_api['status'], utils.get_rsapi_state(vm_from_db))
110
            self.assertEqual(vm_from_api['status'], get_rsapi_state(vm_from_db))
106 111
        self.assertTrue(response.status_code in [200,203])
107 112

  
108 113
    def test_wrong_server(self):
......
125 130
        request = {
126 131
                    "server": {
127 132
                        "name": "new-server-test",
133
                        "owner": 1,
128 134
                        "imageRef": 1,
129 135
                        "flavorRef": 1,
130 136
                        "metadata": {
......
414 420

  
415 421

  
416 422
class BaseTestCase(TestCase):
417
    USERS = 1
423
    USERS = 0
418 424
    FLAVORS = 1
419 425
    IMAGES = 1
420 426
    SERVERS = 1
......
422 428
    IMAGE_METADATA = 0
423 429
    
424 430
    def setUp(self):
425
        self.client = Client()
431
        self.client = AaiClient()
426 432
        create_users(self.USERS)
427 433
        create_flavors(self.FLAVORS)
428 434
        create_images(self.IMAGES)

Also available in: Unified diff