Commit 2f9140db authored by Georgios D. Tsoukalas's avatar Georgios D. Tsoukalas

cyclades: fix URLs in compute/flavors tests

parent 40cf00b4
......@@ -36,6 +36,9 @@ import json
from snf_django.utils.testing import BaseAPITest
from synnefo.db.models import Flavor
from synnefo.db.models_factory import FlavorFactory
from synnefo.lib.services import get_service_path
from synnefo.cyclades_settings import cyclades_services
from synnefo.lib import join_urls
class FlavorAPITest(BaseAPITest):
......@@ -44,10 +47,18 @@ class FlavorAPITest(BaseAPITest):
self.flavor1 = FlavorFactory()
self.flavor2 = FlavorFactory(deleted=True)
self.flavor3 = FlavorFactory()
self.compute_path = get_service_path(cyclades_services, 'compute',
version='v2.0')
def myget(self, path):
path = join_urls(self.compute_path, path)
return self.get(path)
def test_flavor_list(self):
"""Test if the expected list of flavors is returned."""
response = self.get('/api/v1.1/flavors')
response = self.myget('flavors')
self.assertSuccess(response)
api_flavors = json.loads(response.content)['flavors']
......@@ -60,7 +71,7 @@ class FlavorAPITest(BaseAPITest):
def test_flavors_details(self):
"""Test if the flavors details are returned."""
response = self.get('/api/v1.1/flavors/detail')
response = self.myget('flavors/detail')
self.assertSuccess(response)
db_flavors = Flavor.objects.filter(deleted=False)
......@@ -83,7 +94,7 @@ class FlavorAPITest(BaseAPITest):
"""Test if the expected flavor is returned."""
flavor = self.flavor3
response = self.get('/api/v1.1/flavors/%d' % flavor.id)
response = self.myget('flavors/%d' % flavor.id)
self.assertSuccess(response)
api_flavor = json.loads(response.content)['flavor']
......@@ -99,14 +110,14 @@ class FlavorAPITest(BaseAPITest):
def test_deleted_flavor_details(self):
"""Test that API returns details for deleted flavors"""
flavor = self.flavor2
response = self.get('/api/v1.1/flavors/%d' % flavor.id)
response = self.myget('flavors/%d' % flavor.id)
self.assertSuccess(response)
api_flavor = json.loads(response.content)['flavor']
self.assertEquals(api_flavor['name'], flavor.name)
def test_deleted_flavors_list(self):
"""Test that deleted flavors do not appear to flavors list"""
response = self.get('/api/v1.1/flavors')
response = self.myget('flavors')
self.assertSuccess(response)
api_flavors = json.loads(response.content)['flavors']
self.assertEqual(len(api_flavors), 2)
......@@ -114,7 +125,7 @@ class FlavorAPITest(BaseAPITest):
def test_deleted_flavors_details(self):
"""Test that deleted flavors do not appear to flavors detail list"""
FlavorFactory(deleted=True)
response = self.get('/api/v1.1/flavors/detail')
response = self.myget('flavors/detail')
self.assertSuccess(response)
api_flavors = json.loads(response.content)['flavors']
self.assertEqual(len(api_flavors), 2)
......@@ -122,5 +133,6 @@ class FlavorAPITest(BaseAPITest):
def test_wrong_flavor(self):
"""Test 404 result when requesting a flavor that does not exist."""
response = self.get('/api/v1.1/flavors/%d' % 22)
# XXX: flavors/22 below fails for no apparent reason
response = self.myget('flavors/%d' % 23)
self.assertItemNotFound(response)
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