Updates to API tests

This patch,
1) Tags some of the tests as smoke
2) Adds config option to include project_id in the url

Change-Id: I1a86b157d0dd5ffb7a92216ba5ac60a254be103d
This commit is contained in:
Malini Kamalambal
2014-12-11 11:45:41 -05:00
parent 07008f3236
commit 311377b4e0
7 changed files with 36 additions and 14 deletions

View File

@@ -45,15 +45,18 @@ class TestBase(fixtures.BaseTestFixture):
auth_token = 'dummy'
project_id = 'dummy'
cls.test_config = config.TestConfig()
cls.config = config.PoppyConfig()
cls.url = cls.config.base_url
if cls.test_config.project_id_in_url:
cls.url = cls.config.base_url + '/v1.0/' + project_id
else:
cls.url = cls.config.base_url + '/v1.0'
cls.client = client.PoppyClient(cls.url, auth_token, project_id,
serialize_format='json',
deserialize_format='json')
cls.test_config = config.TestConfig()
def assertSchema(self, response_json, expected_schema):
"""Verify response schema aligns with the expected schema."""
try:

View File

@@ -16,6 +16,7 @@
import uuid
import ddt
from nose.plugins import attrib
from tests.api import base
from tests.api.utils.schema import flavors
@@ -93,6 +94,7 @@ class TestFlavorActions(base.TestBase):
self.client.create_flavor(flavor_id=self.flavor_id,
provider_list=self.provider_list)
@attrib.attr('smoke')
def test_get_flavor(self):
resp = self.client.get_flavor(flavor_id=self.flavor_id)

View File

@@ -14,6 +14,7 @@
# limitations under the License.
import ddt
from nose.plugins import attrib
from tests.api import base
@@ -31,6 +32,7 @@ class TestHealth(base.TestBase):
resp = self.client.check_health()
self.assertEqual(resp.status_code, 200)
@attrib.attr('smoke')
def test_ping(self):
resp = self.client.ping()

View File

@@ -18,6 +18,7 @@
import uuid
import ddt
from nose.plugins import attrib
from tests.api import base
from tests.api import providers
@@ -43,6 +44,7 @@ class TestCreateService(providers.TestProviderBase):
"links": [{"href": "www.fastly.com",
"rel": "provider_url"}]}])
@attrib.attr('smoke')
@ddt.file_data('data_create_service.json')
def test_create_service_positive(self, test_data):
@@ -99,6 +101,7 @@ class TestCreateService(providers.TestProviderBase):
msg='Caching List Not Correct for {0} service name {1}'.
format(provider, self.service_name))
@attrib.attr('smoke')
@ddt.file_data('data_create_service_negative.json')
def test_create_service_negative(self, test_data):
@@ -164,6 +167,7 @@ class TestListServices(base.TestBase):
else:
self.flavor_id = self.test_config.default_flavor
@attrib.attr('smoke')
def test_list_single_service(self):
self.service_list.append(self._create_test_service())
resp = self.client.list_services()
@@ -181,6 +185,7 @@ class TestListServices(base.TestBase):
self.assertEqual(body['services'], [])
self.assertEqual(body['links'], [])
@attrib.attr('smoke')
@ddt.data(1, 5, 10)
def test_list_services_valid_limit(self, limit):
self.service_list = [self._create_test_service() for _ in range(limit)]
@@ -202,18 +207,21 @@ class TestListServices(base.TestBase):
self.assertEqual(len(body['services']), 10)
self.assertSchema(body, services.list_services)
@attrib.attr('smoke')
@ddt.data(-1, -10000000000, 0, 10000000, 'invalid', '')
def test_list_services_invalid_limits(self, limit):
url_param = {'limit': limit}
resp = self.client.list_services(param=url_param)
self.assertEqual(resp.status_code, 400)
@attrib.attr('smoke')
@ddt.data(-1, -10000000000, 0, 10000000, 'invalid', '学校', '')
def test_list_services_various_markers(self, marker):
url_param = {'marker': marker}
resp = self.client.list_services(param=url_param)
self.assertEqual(resp.status_code, 200)
@attrib.attr('smoke')
def test_list_services_invalid_param(self):
url_param = {'yummy': 123}
resp = self.client.list_services(param=url_param)
@@ -359,7 +367,7 @@ class TestServiceActions(base.TestBase):
self.assertEqual(body['status'], 'delete_in_progress')
# TODO(malini): find a better solution
# As is, the servvice is still available in the DB till deleted from
# 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(!).
# time.sleep(20)

View File

@@ -66,6 +66,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
deserialize_format)
self.url = url
self.auth_token = auth_token
self.project_id = project_id
self.default_headers['X-Auth-Token'] = auth_token
self.default_headers['X-Project-Id'] = project_id
self.default_headers['Content-Type'] = 'application/json'
@@ -84,7 +85,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
PUT
services/{service_name}
"""
url = '{0}/v1.0/services'.format(self.url)
url = '{0}/services'.format(self.url)
request_object = requests.CreateService(service_name=service_name,
domain_list=domain_list,
origin_list=origin_list,
@@ -101,7 +102,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
PATCH
services/{service_name}
"""
url = '{0}/v1.0/services/{1}'.format(self.url, service_name)
url = '{0}/services/{1}'.format(self.url, service_name)
request_object = requests.PatchService(request_body=request_body)
return self.request('PATCH', url, request_entity=request_object,
requestslib_kwargs=requestslib_kwargs)
@@ -118,7 +119,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
if location:
url = location
else:
url = '{0}/v1.0/services/{1}'.format(self.url, service_name)
url = '{0}/services/{1}'.format(self.url, service_name)
return self.request('GET', url)
def list_services(self, param=None):
@@ -130,7 +131,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
services
"""
url = '{0}/v1.0/services'.format(self.url)
url = '{0}/services'.format(self.url)
return self.request('GET', url, params=param)
def delete_service(self, service_name):
@@ -141,7 +142,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
services/{service_name}
"""
url = '{0}/v1.0/services/{1}'.format(self.url, service_name)
url = '{0}/services/{1}'.format(self.url, service_name)
return self.request('DELETE', url)
def check_health(self):
@@ -152,7 +153,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
health
"""
url = '{0}/v1.0/health'.format(self.url)
url = '{0}/health'.format(self.url)
return self.request('GET', url)
def ping(self):
@@ -163,7 +164,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
ping
"""
url = '{0}/v1.0/ping'.format(self.url)
url = '{0}/ping'.format(self.url)
return self.request('GET', url)
def create_flavor(self, flavor_id=None, provider_list=None, limits=None,
@@ -175,7 +176,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
PUT
flavors/{flavor_id}
"""
url = '{0}/v1.0/flavors'.format(self.url)
url = '{0}/flavors'.format(self.url)
request_object = requests.CreateFlavor(
flavor_id=flavor_id,
provider_list=provider_list,
@@ -195,7 +196,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
if flavor_location:
url = flavor_location
else:
url = '{0}/v1.0/flavors/{1}'.format(self.url, flavor_id)
url = '{0}/flavors/{1}'.format(self.url, flavor_id)
return self.request('GET', url)
@@ -209,7 +210,7 @@ class PoppyClient(client.AutoMarshallingHTTPClient):
if flavor_location:
url = flavor_location
else:
url = u'{0}/v1.0/flavors/{1}'.format(self.url, flavor_id)
url = u'{0}/flavors/{1}'.format(self.url, flavor_id)
return self.request('DELETE', url)

View File

@@ -62,6 +62,11 @@ class TestConfig(data_interfaces.ConfigSectionInterface):
"""String value to set the default flavor to use in tests."""
return self.get('default_flavor')
@property
def project_id_in_url(self):
"""Flag to indicate if project_id should be present in the url."""
return self.get_boolean('project_id_in_url')
class AuthConfig(data_interfaces.ConfigSectionInterface):
"""Defines the auth config values."""

View File

@@ -18,6 +18,7 @@ status_check_retry_interval=2
status_check_retry_timeout=30
generate_flavors=False
default_flavor=standard
project_id_in_url = False
[provider_1]
api_key=INSERT_YOUR_API_KEY