From 54ffba9bdf95cb0b2366c11b25b90934016e9e2c Mon Sep 17 00:00:00 2001 From: Christos Stavrakakis Date: Mon, 5 Aug 2013 13:29:22 +0300 Subject: [PATCH] cyclades: Remove assumptions from tests Remove some hard-coded IDs from tests. --- snf-cyclades-app/synnefo/api/tests/flavors.py | 12 +++++------- snf-cyclades-app/synnefo/api/tests/floating_ips.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/snf-cyclades-app/synnefo/api/tests/flavors.py b/snf-cyclades-app/synnefo/api/tests/flavors.py index bc97987ac..428144314 100644 --- a/snf-cyclades-app/synnefo/api/tests/flavors.py +++ b/snf-cyclades-app/synnefo/api/tests/flavors.py @@ -1,4 +1,4 @@ -# 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) diff --git a/snf-cyclades-app/synnefo/api/tests/floating_ips.py b/snf-cyclades-app/synnefo/api/tests/floating_ips.py index 8f6880f3d..61871604d 100644 --- a/snf-cyclades-app/synnefo/api/tests/floating_ips.py +++ b/snf-cyclades-app/synnefo/api/tests/floating_ips.py @@ -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") -- GitLab