fix: service limit api tests

- Have a separate user for service limit tests.

Change-Id: I856a71644d4f806ae5b4c17fa07459483080412c
This commit is contained in:
Sriram Madapusi Vasudevan 2015-10-13 10:28:28 -04:00
parent 7bb9a09e5f
commit 2fc65d4dc8
5 changed files with 47 additions and 38 deletions

View File

@ -55,7 +55,7 @@ class TestServiceLimits(base.TestBase):
]
self.service_list = []
def _alt_create_test_service(self, resp_code=False):
def _service_limit_create_test_service(self, resp_code=False):
service_name = str(uuid.uuid1())
domain_list = [{"domain": self.generate_random_string(
@ -68,7 +68,7 @@ class TestServiceLimits(base.TestBase):
self.log_delivery = {"enabled": False}
resp = self.alt_user_client.create_service(
resp = self.service_limit_user_client.create_service(
service_name=service_name,
domain_list=domain_list,
origin_list=origin_list,
@ -96,27 +96,27 @@ class TestServiceLimits(base.TestBase):
def test_check_imposed_limit_on_services(self, limit):
resp = self.operator_client.admin_service_limit(
project_id=self.alt_user_client.project_id,
project_id=self.service_limit_user_client.project_id,
limit=limit)
self.assertEqual(resp.status_code, 201)
self.service_list = [self._alt_create_test_service()
self.service_list = [self._service_limit_create_test_service()
for _ in range(limit)]
resp = self._alt_create_test_service(resp_code=True)
resp = self._service_limit_create_test_service(resp_code=True)
self.assertEqual(resp.status_code, 403)
resp = self.operator_client.get_admin_service_limit(
project_id=self.alt_user_client.project_id
project_id=self.service_limit_user_client.project_id
)
self.assertEqual(resp.status_code, 200)
self.assertEqual(json.loads(resp.content)['limit'], limit)
def tearDown(self):
for service in self.service_list:
self.alt_user_client.delete_service(location=service)
self.alt_user_client.wait_for_service_delete(
self.service_limit_user_client.delete_service(location=service)
self.service_limit_user_client.wait_for_service_delete(
location=service,
retry_timeout=self.test_config.status_check_retry_timeout,
retry_interval=self.test_config.status_check_retry_interval)

View File

@ -82,6 +82,23 @@ class TestBase(fixtures.BaseTestFixture):
serialize_format='json',
deserialize_format='json')
service_limit_auth_token, service_limit_project_id = \
cls.auth_client.authenticate_user(
cls.auth_config.base_url,
cls.auth_config.service_limit_user_name,
cls.auth_config.service_limit_api_key)
if cls.test_config.project_id_in_url:
service_limit_url = cls.config.base_url \
+ '/v1.0/' + service_limit_project_id
else:
service_limit_url = cls.config.base_url + '/v1.0'
cls.service_limit_user_client = client.PoppyClient(
service_limit_url, service_limit_auth_token,
service_limit_project_id,
serialize_format='json',
deserialize_format='json')
if cls.test_config.run_operator_tests:
operator_auth_token, operator_project_id = \
cls.auth_client.authenticate_user(

View File

@ -147,6 +147,16 @@ class AuthConfig(data_interfaces.ConfigSectionInterface):
"""The alternate user's api key, if applicable."""
return self.get_raw('alt_api_key')
@property
def service_limit_user_name(self):
"""The name of the service limit user, if applicable."""
return self.get('service_limit_user_name')
@property
def service_limit_api_key(self):
"""The service limit user's api key, if applicable."""
return self.get_raw('service_limit_api_key')
@property
def operator_user_name(self):
"""The name of the user, if applicable."""

View File

@ -11,6 +11,8 @@ base_url=https://identity.api.rackspacecloud.com/v2.0
multi_user=False
alt_user_name={user name of the alternate cloud account}
alt_api_key={api key of the alternate cloud account}
service_limit_user_name={user name of the alternate cloud account for testing service limits}
service_limit_api_key={api key of the alternate cloud account for testing service limits}
operator_user_name={user name of the operator cloud account}
operator_api_key={api key of the operator cloud account}

View File

@ -21,26 +21,16 @@ from tests.functional.transport.pecan import base
class TestServicesLimit(base.FunctionalTest):
# def test_services_limit_missing_limits(self):
# # missing limits field
# response = self.app.put('/v1.0/admin/limits/{0}'.format(
# str(uuid.uuid1())), headers={
# 'Content-Type': 'application/json',
# 'X-Project-ID': str(uuid.uuid4())
# }, expect_errors=True)
#
# self.assertEqual(response.status_code, 400)
#
# def test_services_limits_invalid_limits(self):
# # invalid limits field
# response = self.app.put('/v1.0/admin/limits/{0}'.format(
# str(uuid.uuid1())),
# params=json.dumps({'limit': -5}),
# headers={'Content-Type': 'application/json',
# 'X-Project-ID': str(uuid.uuid4())},
# expect_errors=True)
#
# self.assertEqual(response.status_code, 400)
def test_services_limits_invalid_limits(self):
# invalid limits field
response = self.app.put('/v1.0/admin/limits/{0}'.format(
str(uuid.uuid1())),
params=json.dumps({'limit': -5}),
headers={'Content-Type': 'application/json',
'X-Project-ID': str(uuid.uuid4())},
expect_errors=True)
self.assertEqual(response.status_code, 400)
def test_service_limits_invalid_projectid(self):
# invalid projectid
@ -52,13 +42,3 @@ class TestServicesLimit(base.FunctionalTest):
expect_errors=True)
self.assertEqual(response.status_code, 400)
# def test_services_limit_with_good_input(self):
# # valid limits and project_id field
# project_id = str(uuid.uuid1())
# response = self.app.put('/v1.0/admin/limits/{0}'.format(
# str(project_id)),
# params=json.dumps({'limit': 10}),
# headers={'Content-Type': 'application/json',
# 'X-Project-ID': str(uuid.uuid4())})
# self.assertEqual(response.status_code, 201)