Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
This patch fixes tests failing due to,
1. project_id not present in service url.
2. updates regex for href string format.
3. uses unique domain name per test.

Change-Id: I538208e4d76d98b1426dd293fd93670e7801fc92
  • Loading branch information
Malini Kamalambal committed Jan 5, 2015
1 parent 6f90e79 commit 4939d2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 51 deletions.
9 changes: 0 additions & 9 deletions tests/api/services/data_get_service_by_name.json

This file was deleted.

54 changes: 13 additions & 41 deletions tests/api/services/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
# limitations under the License.

import time
try:
import urllib.parse as urlparse
except ImportError:
import urlparse
import uuid

import ddt
Expand Down Expand Up @@ -55,6 +51,8 @@ def setUp(self):
def test_create_service_positive(self, test_data):

domain_list = test_data['domain_list']
for item in domain_list:
item['domain'] = str(uuid.uuid1()) + '.com'
origin_list = test_data['origin_list']
caching_list = test_data['caching_list']
flavor_id = self.flavor_id
Expand Down Expand Up @@ -334,30 +332,22 @@ def test_delete_service(self):
resp = self.client.delete_service(location=self.service_url)
self.assertEqual(resp.status_code, 202)

# As is, the service is still available in the DB till deleted from
# the provider. The test should be able to handle this with
# exponential sleep or whatever(!).
status_code = 0
count = 0
while (count < 5):
start_time = int(time.time())
stop_time = start_time + self.test_config.status_check_retry_timeout
current_status = 0
expected_status = 404
while (current_status != expected_status):
service_deleted = self.client.get_service(
location=self.service_url)
status_code = service_deleted.status_code
if status_code == 200:
time.sleep(1)
else:
current_status = service_deleted.status_code
current_time = int(time.time())
if current_time > stop_time:
break

count = count + 1

self.assertEqual(404, status_code)
self.assertEqual(404, current_status)

def test_delete_non_existing_service(self):
parsed_url = urlparse.urlparse(self.service_url)
url = "{0}://{1}{2}{3}".format(parsed_url.scheme,
parsed_url.netloc,
'/v1.0/services/',
uuid.uuid4())
url = self.service_url.rsplit('/', 1)[0] + str(uuid.uuid4())
resp = self.client.delete_service(location=url)
self.assertEqual(resp.status_code, 404)

Expand All @@ -367,20 +357,6 @@ def test_delete_failed_service(self):
# Placeholder till we figure out how to create provider side failure.
pass

@ddt.file_data('data_get_service_by_name.json')
def test_get_service_by_name(self, value):
resp = self.client.create_service(service_name=value,
domain_list=self.domain_list,
origin_list=self.origin_list,
caching_list=self.caching_list,
flavor_id=self.flavor_id)

self.assertEqual(resp.status_code, 202)
url = resp.headers["location"]

resp = self.client.get_service(location=url)
self.assertEqual(resp.status_code, 200)

def test_get_service(self):
resp = self.client.get_service(location=self.service_url)
self.assertEqual(resp.status_code, 200)
Expand All @@ -399,11 +375,7 @@ def test_get_service(self):
self.assertEqual(body['flavor_id'], self.flavor_id)

def test_get_non_existing_service(self):
parsed_url = urlparse.urlparse(self.service_url)
url = "{0}://{1}{2}{3}".format(parsed_url.scheme,
parsed_url.netloc,
'/v1.0/services/',
uuid.uuid4())
url = self.service_url.rsplit('/', 1)[0] + str(uuid.uuid4())
resp = self.client.get_service(location=url)
self.assertEqual(resp.status_code, 404)

Expand Down
2 changes: 1 addition & 1 deletion tests/api/utils/schema/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
restrictions = {'type': 'array'}
flavor_id = {'type': 'string', 'pattern': '([a-zA-Z0-9_\-]{1,256})'}
service_name = {'type': 'string', 'pattern': '([a-zA-Z0-9_\-\.]{1,256})'}
uuid4 = '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$' # noqa
uuid4 = '([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})' # noqa
service_id = {'type': 'string', 'pattern': uuid4}

# Response Schema Definition for Get Service API
Expand Down

0 comments on commit 4939d2a

Please sign in to comment.