Commit 54ffba9b authored by Christos Stavrakakis's avatar Christos Stavrakakis

cyclades: Remove assumptions from tests

Remove some hard-coded IDs from tests.
parent 3bc2b7b8
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -50,12 +50,10 @@ class FlavorAPITest(BaseAPITest):
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.myget('flavors')
......@@ -88,7 +86,7 @@ class FlavorAPITest(BaseAPITest):
self.assertEqual(api_flavor['name'], db_flavor.name)
self.assertEqual(api_flavor['ram'], db_flavor.ram)
self.assertEqual(api_flavor['SNF:disk_template'],
db_flavor.disk_template)
db_flavor.disk_template)
def test_flavor_details(self):
"""Test if the expected flavor is returned."""
......@@ -133,14 +131,14 @@ class FlavorAPITest(BaseAPITest):
def test_wrong_flavor(self):
"""Test 404 result when requesting a flavor that does not exist."""
# XXX: flavors/22 below fails for no apparent reason
response = self.myget('flavors/%d' % 23)
flavor_id = max(Flavor.objects.values_list('id', flat=True)) + 1
response = self.myget('flavors/%d' % flavor_id)
self.assertItemNotFound(response)
def test_catch_wrong_api_paths(self, *args):
response = self.myget('nonexistent')
self.assertEqual(response.status_code, 400)
try:
error = json.loads(response.content)
json.loads(response.content)
except ValueError:
self.assertTrue(False)
......@@ -111,7 +111,8 @@ class FloatingIPAPITest(BaseAPITest):
self.assertEqual(ip.network, net)
self.assertEqual(json.loads(response.content)["floating_ip"],
{"instance_id": None, "ip": "192.168.2.1",
"fixed_ip": None, "id": "1", "pool": "1"})
"fixed_ip": None, "id": str(ip.id),
"pool": str(net.id)})
def test_reserve_no_pool(self):
# No networks
......@@ -132,9 +133,11 @@ class FloatingIPAPITest(BaseAPITest):
with mocked_quotaholder():
response = self.post(URL, "test_user", json.dumps({}), "json")
self.assertSuccess(response)
ip = FloatingIP.objects.get()
self.assertEqual(json.loads(response.content)["floating_ip"],
{"instance_id": None, "ip": "192.168.2.1",
"fixed_ip": None, "id": "1", "pool": str(net2.id)})
"fixed_ip": None, "id": str(ip.id),
"pool": str(net2.id)})
def test_reserve_full(self):
net = FloatingIPPoolFactory(userid="test_user",
......@@ -151,9 +154,11 @@ class FloatingIPAPITest(BaseAPITest):
with mocked_quotaholder():
response = self.post(URL, "test_user", json.dumps(request), "json")
self.assertSuccess(response)
ip = FloatingIP.objects.get()
self.assertEqual(json.loads(response.content)["floating_ip"],
{"instance_id": None, "ip": "192.168.2.10",
"fixed_ip": None, "id": "1", "pool": "1"})
"fixed_ip": None, "id": str(ip.id), "pool":
str(net.id)})
# Already reserved
FloatingIPFactory(network=net, ipv4="192.168.2.3")
......
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