diff --git a/tox.ini b/tox.ini index fee859cd7d..6160c5be9a 100644 --- a/tox.ini +++ b/tox.ini @@ -37,7 +37,7 @@ commands = {posargs} [flake8] show-source = True -ignore = F403,F821,H301,H306,H402,H404 +ignore = F821,H301,H306,H402,H404 builtins = _ exclude=.venv,.tox,dist,doc,openstack,*egg,rsdns,tools,etc,build filename=*.py,trove-* diff --git a/trove/common/rpc/impl_fake.py b/trove/common/rpc/impl_fake.py index f153a0239a..0b5b0fe8b9 100644 --- a/trove/common/rpc/impl_fake.py +++ b/trove/common/rpc/impl_fake.py @@ -19,7 +19,10 @@ Standard openstack.common.rpc.impl_fake with nonblocking cast """ -from trove.openstack.common.rpc.impl_fake import * +import eventlet + +from trove.openstack.common.rpc.impl_fake import cast +from trove.openstack.common.rpc.impl_fake import create_connection original_cast = cast @@ -30,3 +33,7 @@ def non_blocking_cast(*args, **kwargs): cast = non_blocking_cast + + +# Asserting create_connection, workaround for pep8-F401 for unused import. +assert create_connection diff --git a/trove/tests/api/header.py b/trove/tests/api/header.py index b1e6fa2b4d..9c2e0d6ebc 100644 --- a/trove/tests/api/header.py +++ b/trove/tests/api/header.py @@ -17,7 +17,7 @@ # from proboscis import test -from proboscis.asserts import * +from proboscis import asserts from proboscis import SkipTest from functools import wraps @@ -54,7 +54,7 @@ def must_work_with_blank_accept_headers(): versions.test_list_versions_index() # now change headers to XML to make sure the test fails morph_content_type_to('application/xml') - assert_raises(exceptions.ResponseFormatError, - versions.test_list_versions_index) + asserts.assert_raises(exceptions.ResponseFormatError, + versions.test_list_versions_index) finally: client.client.morph_request = original_morph_request diff --git a/trove/tests/api/instances_actions.py b/trove/tests/api/instances_actions.py index fdf7f10ec5..05f0cf11f0 100644 --- a/trove/tests/api/instances_actions.py +++ b/trove/tests/api/instances_actions.py @@ -18,7 +18,7 @@ import time from proboscis import after_class from proboscis import before_class from proboscis import test -from proboscis.asserts import * +from proboscis import asserts from proboscis.decorators import time_out from proboscis import SkipTest @@ -185,8 +185,8 @@ def create_user(): except BadRequest: pass # Ignore this if the user already exists. helper.connection.connect() - assert_true(helper.connection.is_connected(), - "Test user must be able to connect to MySQL.") + asserts.assert_true(helper.connection.is_connected(), + "Test user must be able to connect to MySQL.") class RebootTestBase(ActionTestBase): @@ -211,7 +211,7 @@ class RebootTestBase(ActionTestBase): instance = self.instance if instance.status == "REBOOT": return False - assert_equal("ACTIVE", instance.status) + asserts.assert_equal("ACTIVE", instance.status) return True poll_until(is_finished_rebooting, time_out=TIME_OUT_TIME) @@ -220,8 +220,8 @@ class RebootTestBase(ActionTestBase): if not USE_IP: return new_proc_id = self.find_mysql_proc_on_instance() - assert_not_equal(new_proc_id, self.proc_id, - "MySQL process ID should be different!") + asserts.assert_not_equal(new_proc_id, self.proc_id, + "MySQL process ID should be different!") def successful_restart(self): """Restart MySQL via the REST API successfully.""" @@ -259,7 +259,7 @@ class RebootTestBase(ActionTestBase): # The reason we check for BLOCKED as well as SHUTDOWN is because # Upstart might try to bring mysql back up after the borked # connection and the guest status can be either - assert_true(instance.status in ("SHUTDOWN", "BLOCKED")) + asserts.assert_true(instance.status in ("SHUTDOWN", "BLOCKED")) return True poll_until(is_finished_rebooting, time_out=TIME_OUT_TIME) @@ -285,7 +285,7 @@ class RestartTests(RebootTestBase): def call_reboot(self): self.instance.restart() - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) @before_class def test_set_up(self): @@ -368,8 +368,8 @@ class RebootTests(RebootTestBase): @before_class def test_set_up(self): self.set_up() - assert_true(hasattr(self, 'dbaas')) - assert_true(self.dbaas is not None) + asserts.assert_true(hasattr(self, 'dbaas')) + asserts.assert_true(self.dbaas is not None) @test def test_ensure_mysql_is_running(self): @@ -412,7 +412,7 @@ class ResizeInstanceTest(ActionTestBase): instance = self.instance if instance.status == "RESIZE": return False - assert_equal("ACTIVE", instance.status) + asserts.assert_equal("ACTIVE", instance.status) return True poll_until(is_finished_resizing, time_out=TIME_OUT_TIME) @@ -421,14 +421,14 @@ class ResizeInstanceTest(ActionTestBase): self.set_up() if USE_IP: self.connection.connect() - assert_true(self.connection.is_connected(), - "Should be able to connect before resize.") + asserts.assert_true(self.connection.is_connected(), + "Should be able to connect before resize.") self.user_was_deleted = False @test def test_instance_resize_same_size_should_fail(self): - assert_raises(BadRequest, self.dbaas.instances.resize_instance, - self.instance_id, self.flavor_id) + asserts.assert_raises(BadRequest, self.dbaas.instances.resize_instance, + self.instance_id, self.flavor_id) @test(enabled=VOLUME_SUPPORT) def test_instance_resize_to_ephemeral_in_volume_support_should_fail(self): @@ -439,20 +439,21 @@ class ResizeInstanceTest(ActionTestBase): def is_active(): return self.instance.status == 'ACTIVE' poll_until(is_active, time_out=TIME_OUT_TIME) - assert_equal(self.instance.status, 'ACTIVE') + asserts.assert_equal(self.instance.status, 'ACTIVE') self.get_flavor_href( flavor_id=self.expected_old_flavor_id) - assert_raises(HTTPNotImplemented, self.dbaas.instances.resize_instance, - self.instance_id, flavors[0].id) + asserts.assert_raises(HTTPNotImplemented, + self.dbaas.instances.resize_instance, + self.instance_id, flavors[0].id) @test(enabled=EPHEMERAL_SUPPORT) def test_instance_resize_to_non_ephemeral_flavor_should_fail(self): flavor_name = CONFIG.values.get('instance_bigger_flavor_name', 'm1-small') flavors = self.dbaas.find_flavors_by_name(flavor_name) - assert_raises(BadRequest, self.dbaas.instances.resize_instance, - self.instance_id, flavors[0].id) + asserts.assert_raises(BadRequest, self.dbaas.instances.resize_instance, + self.instance_id, flavors[0].id) def obtain_flavor_ids(self): old_id = self.instance.flavor['id'] @@ -466,15 +467,18 @@ class ResizeInstanceTest(ActionTestBase): flavor_name = CONFIG.values.get('instance_bigger_flavor_name', 'm1.small') flavors = self.dbaas.find_flavors_by_name(flavor_name) - assert_equal(len(flavors), 1, "Number of flavors with name '%s' " - "found was '%d'." % (flavor_name, len(flavors))) + asserts.assert_equal(len(flavors), 1, + "Number of flavors with name '%s' " + "found was '%d'." % (flavor_name, + len(flavors))) flavor = flavors[0] self.old_dbaas_flavor = instance_info.dbaas_flavor instance_info.dbaas_flavor = flavor - assert_true(flavor is not None, "Flavor '%s' not found!" % flavor_name) + asserts.assert_true(flavor is not None, + "Flavor '%s' not found!" % flavor_name) flavor_href = self.dbaas.find_flavor_self_href(flavor) - assert_true(flavor_href is not None, - "Flavor href '%s' not found!" % flavor_name) + asserts.assert_true(flavor_href is not None, + "Flavor href '%s' not found!" % flavor_name) self.expected_new_flavor_id = flavor.id @test(depends_on=[test_instance_resize_same_size_should_fail]) @@ -484,7 +488,7 @@ class ResizeInstanceTest(ActionTestBase): self.dbaas.instances.resize_instance( self.instance_id, self.get_flavor_href(flavor_id=self.expected_new_flavor_id)) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) #(WARNING) IF THE RESIZE IS WAY TOO FAST THIS WILL FAIL assert_unprocessable( @@ -535,7 +539,7 @@ class ResizeInstanceTest(ActionTestBase): def test_instance_has_new_flavor_after_resize(self): actual = self.get_flavor_href(self.instance.flavor['id']) expected = self.get_flavor_href(flavor_id=self.expected_new_flavor_id) - assert_equal(actual, expected) + asserts.assert_equal(actual, expected) @test(depends_on=[test_instance_has_new_flavor_after_resize]) @time_out(TIME_OUT_TIME) @@ -545,18 +549,18 @@ class ResizeInstanceTest(ActionTestBase): def is_active(): return self.instance.status == 'ACTIVE' poll_until(is_active, time_out=TIME_OUT_TIME) - assert_equal(self.instance.status, 'ACTIVE') + asserts.assert_equal(self.instance.status, 'ACTIVE') old_flavor_href = self.get_flavor_href( flavor_id=self.expected_old_flavor_id) self.dbaas.instances.resize_instance(self.instance_id, old_flavor_href) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) self.old_dbaas_flavor = instance_info.dbaas_flavor instance_info.dbaas_flavor = expected_dbaas_flavor self.wait_for_resize() - assert_equal(str(self.instance.flavor['id']), - str(self.expected_old_flavor_id)) + asserts.assert_equal(str(self.instance.flavor['id']), + str(self.expected_old_flavor_id)) @test(depends_on=[test_resize_down], groups=["dbaas.usage"]) @@ -617,7 +621,7 @@ class ResizeInstanceVolume(ActionTestBase): poll_until(check_resize_status, sleep_time=2, time_out=300) instance = instance_info.dbaas.instances.get(instance_info.id) - assert_equal(instance.volume['size'], self.new_volume_size) + asserts.assert_equal(instance.volume['size'], self.new_volume_size) @test(depends_on=[test_volume_resize_success], groups=["dbaas.usage"]) def test_resize_volume_usage_event_sent(self): @@ -663,7 +667,7 @@ class UpdateGuest(object): """Make sure we have the old version before proceeding.""" self.old_version = self.get_version() self.next_version = UPDATE_GUEST_CONF["next-version"] - assert_not_equal(self.old_version, self.next_version) + asserts.assert_not_equal(self.old_version, self.next_version) @test(enabled=UPDATE_GUEST_CONF is not None) def upload_update_to_repo(self): diff --git a/trove/tests/api/instances_delete.py b/trove/tests/api/instances_delete.py index 8785c84010..100720cc4b 100644 --- a/trove/tests/api/instances_delete.py +++ b/trove/tests/api/instances_delete.py @@ -20,7 +20,7 @@ import time from proboscis import before_class from proboscis import test -from proboscis.asserts import * +from proboscis import asserts from proboscis.decorators import time_out from troveclient.compat import exceptions @@ -74,12 +74,12 @@ class TestBase(object): instance = self.dbaas.instances.get(instance_id) instance.delete() if assert_deleted: - assert_true(self.is_instance_deleted(instance_id)) + asserts.assert_true(self.is_instance_deleted(instance_id)) def delete_errored_instance(self, instance_id): self.wait_for_instance_status(instance_id, 'ERROR') status, desc = self.get_task_info(instance_id) - assert_equal(status, "ERROR") + asserts.assert_equal(status, "ERROR") self.delete_instance(instance_id) @@ -130,13 +130,15 @@ class ErroredInstanceDelete(TestBase): self.wait_for_instance_status(id, 'ACTIVE') self.wait_for_instance_task_status(id, 'No tasks for the instance.') instance = self.dbaas.management.show(id) - assert_equal(instance.status, "ACTIVE") - assert_equal(instance.task_description, 'No tasks for the instance.') + asserts.assert_equal(instance.status, "ACTIVE") + asserts.assert_equal(instance.task_description, + 'No tasks for the instance.') # Try to delete the instance. This fails the first time due to how # the test fake is setup. self.delete_instance(id, assert_deleted=False) instance = self.dbaas.management.show(id) - assert_equal(instance.status, "SHUTDOWN") - assert_equal(instance.task_description, "Deleting the instance.") + asserts.assert_equal(instance.status, "SHUTDOWN") + asserts.assert_equal(instance.task_description, + "Deleting the instance.") # Try a second time. This will succeed. self.delete_instance(id) diff --git a/trove/tests/api/instances_mysql_down.py b/trove/tests/api/instances_mysql_down.py index 72da0e1960..f7e87a8736 100644 --- a/trove/tests/api/instances_mysql_down.py +++ b/trove/tests/api/instances_mysql_down.py @@ -19,7 +19,7 @@ Extra tests to create an instance, shut down MySQL, and delete it. from proboscis.decorators import time_out from proboscis import before_class from proboscis import test -from proboscis.asserts import * +from proboscis import asserts import time from datetime import datetime @@ -56,7 +56,7 @@ class TestBase(object): # Get the resize to flavor. flavors2 = self.client.find_flavors_by_name(flavor2_name) self.new_flavor_id = flavors2[0].id - assert_not_equal(self.flavor_id, self.new_flavor_id) + asserts.assert_not_equal(self.flavor_id, self.new_flavor_id) def _wait_for_active(self): poll_until(lambda: self.client.instances.get(self.id), @@ -115,7 +115,7 @@ class TestBase(object): while True: try: instance = self.client.instances.get(self.id) - assert_equal("SHUTDOWN", instance.status) + asserts.assert_equal("SHUTDOWN", instance.status) except exceptions.NotFound: break time.sleep(0.25) diff --git a/trove/tests/api/mgmt/accounts.py b/trove/tests/api/mgmt/accounts.py index 55958fbba9..1cbb4c6ecf 100644 --- a/trove/tests/api/mgmt/accounts.py +++ b/trove/tests/api/mgmt/accounts.py @@ -19,7 +19,7 @@ from nose.plugins.skip import SkipTest from proboscis import after_class from proboscis import before_class from proboscis import test -from proboscis.asserts import * +from proboscis import asserts from proboscis.decorators import time_out from trove import tests @@ -46,29 +46,29 @@ class AccountsBeforeInstanceCreation(object): @test def test_invalid_account(self): raise SkipTest("Don't have a good way to know if accounts are valid.") - assert_raises(exceptions.NotFound, self.client.accounts.show, - "asd#4#@fasdf") + asserts.assert_raises(exceptions.NotFound, self.client.accounts.show, + "asd#4#@fasdf") @test def test_invalid_account_fails(self): account_info = self.client.accounts.show("badaccount") - assert_not_equal(self.user.tenant_id, account_info.id) + asserts.assert_not_equal(self.user.tenant_id, account_info.id) @test def test_account_zero_instances(self): account_info = self.client.accounts.show(self.user.tenant_id) expected_instances = 0 if not existing_instance() else 1 - assert_equal(expected_instances, len(account_info.instances)) + asserts.assert_equal(expected_instances, len(account_info.instances)) expected = self.user.tenant_id if expected is None: expected = "None" - assert_equal(expected, account_info.id) + asserts.assert_equal(expected, account_info.id) @test def test_list_empty_accounts(self): accounts_info = self.client.accounts.index() expected_accounts = 0 if not existing_instance() else 1 - assert_equal(expected_accounts, len(accounts_info.accounts)) + asserts.assert_equal(expected_accounts, len(accounts_info.accounts)) @test(groups=[tests.INSTANCES, GROUP], depends_on_groups=["dbaas.listing"]) @@ -90,27 +90,27 @@ class AccountsAfterInstanceCreation(object): expected = "None" print("account_id.id = '%s'" % account_info.id) print("expected = '%s'" % expected) - assert_equal(account_info.id, expected) + asserts.assert_equal(account_info.id, expected) # Instances: Here we know we've only created one instance. - assert_equal(1, len(account_info.instances)) - assert_is_not_none(account_info.instances[0]['host']) + asserts.assert_equal(1, len(account_info.instances)) + asserts.assert_is_not_none(account_info.instances[0]['host']) # We know the there's only 1 instance instance = account_info.instances[0] print("instances in account: %s" % instance) - assert_equal(instance['id'], instance_info.id) - assert_equal(instance['name'], instance_info.name) - assert_equal(instance['status'], "ACTIVE") - assert_is_not_none(instance['host']) + asserts.assert_equal(instance['id'], instance_info.id) + asserts.assert_equal(instance['name'], instance_info.name) + asserts.assert_equal(instance['status'], "ACTIVE") + asserts.assert_is_not_none(instance['host']) @test def test_list_accounts(self): if test_config.auth_strategy == "fake": raise SkipTest("Skipping this as auth is faked anyway.") accounts_info = self.client.accounts.index() - assert_equal(1, len(accounts_info.accounts)) + asserts.assert_equal(1, len(accounts_info.accounts)) account = accounts_info.accounts[0] - assert_equal(1, account['num_instances']) - assert_equal(instance_info.user.tenant_id, account['id']) + asserts.assert_equal(1, account['num_instances']) + asserts.assert_equal(instance_info.user.tenant_id, account['id']) @test(groups=[tests.POST_INSTANCES, GROUP], @@ -125,7 +125,7 @@ class AccountsAfterInstanceDeletion(object): @test def test_no_details_empty_account(self): account_info = self.client.accounts.show(instance_info.user.tenant_id) - assert_equal(0, len(account_info.instances)) + asserts.assert_equal(0, len(account_info.instances)) @test(groups=["fake.dbaas.api.mgmt.allaccounts"], @@ -170,8 +170,8 @@ class AllAccounts(object): def test_list_accounts_with_multiple_users(self): accounts_info = self.admin_client.accounts.index() for account in accounts_info.accounts: - assert_true(account['id'] in self.user_tenant_ids) - assert_equal(self.max, account['num_instances']) + asserts.assert_true(account['id'] in self.user_tenant_ids) + asserts.assert_equal(self.max, account['num_instances']) @after_class(always_run=True) @time_out(60) @@ -203,7 +203,7 @@ class AccountWithBrokenInstance(object): self.instance = self.client.instances.get(self.response.id) print("Status: %s" % self.instance.status) msg = "Instance did not drop to error after server prov failure." - assert_equal(self.instance.status, "ERROR", msg) + asserts.assert_equal(self.instance.status, "ERROR", msg) @test def no_compute_instance_no_problem(self): @@ -213,12 +213,12 @@ class AccountWithBrokenInstance(object): account_info = self.client.accounts.show(self.user.tenant_id) # All we care about is that accounts.show doesn't 500 on us # for having a broken instance in the roster. - assert_equal(len(account_info.instances), 1) + asserts.assert_equal(len(account_info.instances), 1) instance = account_info.instances[0] - assert_true(isinstance(instance['id'], basestring)) - assert_equal(len(instance['id']), 36) - assert_equal(instance['name'], self.name) - assert_equal(instance['status'], "ERROR") + asserts.assert_true(isinstance(instance['id'], basestring)) + asserts.assert_equal(len(instance['id']), 36) + asserts.assert_equal(instance['name'], self.name) + asserts.assert_equal(instance['status'], "ERROR") assert_is_none(instance['host']) @after_class diff --git a/trove/tests/api/mgmt/malformed_json.py b/trove/tests/api/mgmt/malformed_json.py index 573745d4d8..ab728df0e6 100644 --- a/trove/tests/api/mgmt/malformed_json.py +++ b/trove/tests/api/mgmt/malformed_json.py @@ -18,7 +18,7 @@ from collections import deque from proboscis import test -from proboscis.asserts import * +from proboscis import asserts from proboscis import after_class from proboscis import before_class import troveclient.compat @@ -63,19 +63,20 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Create instance failed with code %s, exception %s" - % (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Create instance failed with code %s," + " exception %s" % (httpCode, e)) if not isinstance(self.dbaas.client, troveclient.compat.xml.TroveXmlClient): databases = "u'foo'" users = "u'bar'" - assert_equal(e.message, - "Validation error: " - "instance['databases'] %s is not of type 'array';" - " instance['users'] %s is not of type 'array'; " - "instance['volume'] 3 is not of type 'object'" % - (databases, users)) + asserts.assert_equal(e.message, + "Validation error: " + "instance['databases'] %s is not of type" + " 'array'; instance['users'] %s is not of" + " type 'array'; instance['volume'] 3 is " + "not of type 'object'" + % (databases, users)) @test def test_bad_database_data(self): @@ -86,16 +87,16 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Create database failed with code %s, exception %s" - % (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Create database failed with code %s, " + "exception %s" % (httpCode, e)) if not isinstance(self.dbaas.client, troveclient.compat.xml.TroveXmlClient): _bad_db_data = "u'{foo}'" - assert_equal(e.message, - "Validation error: " - "databases %s is not of type 'array'" % - _bad_db_data) + asserts.assert_equal(e.message, + "Validation error: " + "databases %s is not of type 'array'" % + _bad_db_data) @test def test_bad_user_data(self): @@ -115,15 +116,15 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Create user failed with code %s, exception %s" - % (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Create user failed with code %s, " + "exception %s" % (httpCode, e)) err_1 = format_path(deque(('users', 0))) - assert_equal(e.message, - "Validation error: " - "%(err_1)s 'name' is a required property; " - "%(err_1)s 'password' is a required property" % - {'err_1': err_1}) + asserts.assert_equal(e.message, + "Validation error: " + "%(err_1)s 'name' is a required property; " + "%(err_1)s 'password' is a required property" + % {'err_1': err_1}) @test def test_bad_resize_instance_data(self): @@ -140,9 +141,9 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Resize instance failed with code %s, exception %s" - % (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Resize instance failed with code %s, " + "exception %s" % (httpCode, e)) @test def test_bad_resize_vol_data(self): @@ -160,17 +161,17 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Resize instance failed with code %s, exception %s" - % (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Resize instance failed with code %s, " + "exception %s" % (httpCode, e)) data = "u'bad data'" - assert_equal(e.message, - "Validation error: " - "resize['volume']['size'] %s " - "is not valid under any of the given schemas; " - "%s is not of type 'integer'; " - "%s does not match '[0-9]+'" % - (data, data, data)) + asserts.assert_equal(e.message, + "Validation error: " + "resize['volume']['size'] %s " + "is not valid under any of the given schemas;" + " %s is not of type 'integer'; " + "%s does not match '[0-9]+'" % + (data, data, data)) @test def test_bad_change_user_password(self): @@ -190,19 +191,19 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Change usr/passwd failed with code %s, exception %s" - % (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Change usr/passwd failed with code %s, " + "exception %s" % (httpCode, e)) if not isinstance(self.dbaas.client, troveclient.compat.xml.TroveXmlClient): password = "u''" - assert_equal(e.message, - "Validation error: " - "users[0] 'password' is a required property; " - "users[0]['name'] %s is too short; " - "users[0]['name'] %s does not match " - "'^.*[0-9a-zA-Z]+.*$'" % - (password, password)) + asserts.assert_equal(e.message, + "Validation error: users[0] 'password' is" + " a required property; " + "users[0]['name'] %s is too short; " + "users[0]['name'] %s does not match " + "'^.*[0-9a-zA-Z]+.*$'" + % (password, password)) @test def test_bad_grant_user_access(self): @@ -221,10 +222,9 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Grant user access failed with code %s, exception " - "%s" % - (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Grant user access failed with code %s, " + "exception %s" % (httpCode, e)) @test def test_bad_revoke_user_access(self): @@ -243,10 +243,10 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 404, - "Revoke user access failed w/code %s, exception %s" % - (httpCode, e)) - assert_equal(e.message, "The resource could not be found.") + asserts.assert_equal(httpCode, 404, + "Revoke user access failed w/code %s, " + "exception %s" % (httpCode, e)) + asserts.assert_equal(e.message, "The resource could not be found.") @test def test_bad_body_flavorid_create_instance(self): @@ -260,22 +260,22 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Create instance failed with code %s, exception %s" % - (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Create instance failed with code %s, " + "exception %s" % (httpCode, e)) if not isinstance(self.dbaas.client, troveclient.compat.xml.TroveXmlClient): flavorId = [u'?'] - assert_equal(e.message, - "Validation error: " - "instance['flavorRef'] %s is not valid under any " - "of the given schemas; " - "%s is not of type 'string'; " - "%s is not of type 'string'; " - "%s is not of type 'integer'; " - "instance['volume'] 2 is not of type 'object'" % - (flavorId, flavorId, flavorId, flavorId)) + asserts.assert_equal(e.message, + "Validation error: " + "instance['flavorRef'] %s is not valid " + "under any of the given schemas; %s is " + "not of type 'string'; %s is not of type" + " 'string'; %s is not of type 'integer'; " + "instance['volume'] 2 is not of" + " type 'object'" % + (flavorId, flavorId, flavorId, flavorId)) @test def test_bad_body_datastore_create_instance(self): @@ -291,18 +291,20 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Create instance failed with code %s, exception %s" % - (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Create instance failed with code %s, " + "exception %s" % (httpCode, e)) if not isinstance(self.dbaas.client, troveclient.compat.xml.TroveXmlClient): - assert_equal(e.message, - "Validation error: instance['datastore']['type']" - " u'%s' does not match '^.*[0-9a-zA-Z]+.*$'; " - "instance['datastore']['version'] u'%s' does not" - " match '^.*[0-9a-zA-Z]+.*$'" % - (datastore, datastore_version)) + asserts.assert_equal(e.message, + "Validation error: " + "instance['datastore']['type']" + " u'%s' does not match" + " '^.*[0-9a-zA-Z]+.*$'; " + "instance['datastore']['version'] u'%s' " + "does not match '^.*[0-9a-zA-Z]+.*$'" % + (datastore, datastore_version)) @test def test_bad_body_volsize_create_instance(self): @@ -314,13 +316,13 @@ class MalformedJson(object): except Exception as e: resp, body = self.dbaas.client.last_response httpCode = resp.status - assert_equal(httpCode, 400, - "Create instance failed with code %s, exception %s" % - (httpCode, e)) + asserts.assert_equal(httpCode, 400, + "Create instance failed with code %s, " + "exception %s" % (httpCode, e)) if not isinstance(self.dbaas.client, troveclient.compat.xml.TroveXmlClient): volsize = "u'h3ll0'" - assert_equal(e.message, - "Validation error: " - "instance['volume'] %s is not of type 'object'" % - volsize) + asserts.assert_equal(e.message, + "Validation error: " + "instance['volume'] %s is not of " + "type 'object'" % volsize) diff --git a/trove/tests/api/mgmt/quotas.py b/trove/tests/api/mgmt/quotas.py index 5666bf8db9..b6001841f9 100644 --- a/trove/tests/api/mgmt/quotas.py +++ b/trove/tests/api/mgmt/quotas.py @@ -17,7 +17,7 @@ # from proboscis import test -from proboscis.asserts import * +from proboscis import asserts from proboscis import after_class from proboscis import before_class from proboscis.asserts import Check @@ -34,8 +34,9 @@ class QuotasBase(object): def setUp(self): self.user1 = CONFIG.users.find_user(Requirements(is_admin=False)) self.user2 = CONFIG.users.find_user(Requirements(is_admin=False)) - assert_not_equal(self.user1.tenant, self.user2.tenant, - "Not enough users to run QuotasTest. Needs >=2.") + asserts.assert_not_equal(self.user1.tenant, self.user2.tenant, + "Not enough users to run QuotasTest." + + " Needs >=2.") self.client1 = create_dbaas_client(self.user1) self.client2 = create_dbaas_client(self.user2) self.mgmt_client = create_client(is_admin=True) @@ -71,7 +72,7 @@ class DefaultQuotasTest(QuotasBase): quotas["instances"]) check.equal(CONFIG.trove_max_volumes_per_user, quotas["volumes"]) - assert_equal(len(quotas), 2) + asserts.assert_equal(len(quotas), 2) @test(groups=["dbaas.api.mgmt.quotas"]) @@ -81,7 +82,7 @@ class ChangeInstancesQuota(QuotasBase): def setUp(self): super(ChangeInstancesQuota, self).setUp() self.mgmt_client.quota.update(self.user1.tenant, {"instances": 0}) - assert_equal(200, self.mgmt_client.last_http_code) + asserts.assert_equal(200, self.mgmt_client.last_http_code) @after_class def tearDown(self): @@ -90,10 +91,11 @@ class ChangeInstancesQuota(QuotasBase): @test def check_user2_is_not_affected_on_instances_quota_change(self): user2_current_quota = self.mgmt_client.quota.show(self.user2.tenant) - assert_equal(self.original_quotas2, user2_current_quota, - "Changing one user's quota affected another user's quota." - + " Original: %s. After Quota Change: %s" % - (self.original_quotas2, user2_current_quota)) + asserts.assert_equal(self.original_quotas2, user2_current_quota, + "Changing one user's quota affected another" + + "user's quota." + + " Original: %s. After Quota Change: %s" % + (self.original_quotas2, user2_current_quota)) @test def verify_correct_update(self): @@ -102,17 +104,16 @@ class ChangeInstancesQuota(QuotasBase): check.equal(0, quotas["instances"]) check.equal(CONFIG.trove_max_volumes_per_user, quotas["volumes"]) - assert_equal(len(quotas), 2) + asserts.assert_equal(len(quotas), 2) @test def create_too_many_instances(self): flavor, flavor_href = get_standby_instance_flavor(self.client1) - assert_raises(exceptions.OverLimit, - self.client1.instances.create, - "too_many_instances", - flavor_href, - {'size': 1}) - assert_equal(413, self.client1.last_http_code) + asserts.assert_raises(exceptions.OverLimit, + self.client1.instances.create, + "too_many_instances", + flavor_href, {'size': 1}) + asserts.assert_equal(413, self.client1.last_http_code) @test(groups=["dbaas.api.mgmt.quotas"]) @@ -122,7 +123,7 @@ class ChangeVolumesQuota(QuotasBase): def setUp(self): super(ChangeVolumesQuota, self).setUp() self.mgmt_client.quota.update(self.user1.tenant, {"volumes": 0}) - assert_equal(200, self.mgmt_client.last_http_code) + asserts.assert_equal(200, self.mgmt_client.last_http_code) @after_class def tearDown(self): @@ -131,20 +132,22 @@ class ChangeVolumesQuota(QuotasBase): @test def check_volumes_overlimit(self): flavor, flavor_href = get_standby_instance_flavor(self.client1) - assert_raises(exceptions.OverLimit, - self.client1.instances.create, - "too_large_volume", - flavor_href, - {'size': CONFIG.trove_max_accepted_volume_size + 1}) - assert_equal(413, self.client1.last_http_code) + asserts.assert_raises(exceptions.OverLimit, + self.client1.instances.create, + "too_large_volume", + flavor_href, + {'size': CONFIG.trove_max_accepted_volume_size + + 1}) + asserts.assert_equal(413, self.client1.last_http_code) @test def check_user2_is_not_affected_on_volumes_quota_change(self): user2_current_quota = self.mgmt_client.quota.show(self.user2.tenant) - assert_equal(self.original_quotas2, user2_current_quota, - "Changing one user's quota affected another user's quota." - + " Original: %s. After Quota Change: %s" % - (self.original_quotas2, user2_current_quota)) + asserts.assert_equal(self.original_quotas2, user2_current_quota, + "Changing one user's quota affected another" + + "user's quota." + + " Original: %s. After Quota Change: %s" % + (self.original_quotas2, user2_current_quota)) @test def verify_correct_update(self): @@ -153,17 +156,18 @@ class ChangeVolumesQuota(QuotasBase): check.equal(CONFIG.trove_max_instances_per_user, quotas["instances"]) check.equal(0, quotas["volumes"]) - assert_equal(len(quotas), 2) + asserts.assert_equal(len(quotas), 2) @test def create_too_large_volume(self): flavor, flavor_href = get_standby_instance_flavor(self.client1) - assert_raises(exceptions.OverLimit, - self.client1.instances.create, - "too_large_volume", - flavor_href, - {'size': CONFIG.trove_max_accepted_volume_size + 1}) - assert_equal(413, self.client1.last_http_code) + asserts.assert_raises(exceptions.OverLimit, + self.client1.instances.create, + "too_large_volume", + flavor_href, + {'size': CONFIG.trove_max_accepted_volume_size + + 1}) + asserts.assert_equal(413, self.client1.last_http_code) #create an instance when I set the limit back to #multiple updates to the quota and it should do what you expect diff --git a/trove/tests/api/mgmt/storage.py b/trove/tests/api/mgmt/storage.py index 74445d21f5..ac46e453f0 100644 --- a/trove/tests/api/mgmt/storage.py +++ b/trove/tests/api/mgmt/storage.py @@ -17,7 +17,7 @@ from nose.plugins.skip import SkipTest from proboscis import before_class from proboscis import test -from proboscis.asserts import * +from proboscis import asserts from trove import tests from trove.tests.api.instances import CheckInstance @@ -46,30 +46,32 @@ class StorageBeforeInstanceCreation(object): storage = self.client.storage.index() print("storage : %r" % storage) for device in storage: - assert_true(hasattr(device, 'name'), - "device.name: %r" % device.name) - assert_true(hasattr(device, 'type'), - "device.type: %r" % device.name) - assert_true(hasattr(device, 'used'), - "device.used: %r" % device.used) + asserts.assert_true(hasattr(device, 'name'), + "device.name: %r" % device.name) + asserts.assert_true(hasattr(device, 'type'), + "device.type: %r" % device.name) + asserts.assert_true(hasattr(device, 'used'), + "device.used: %r" % device.used) - assert_true(hasattr(device, 'provision'), - "device.provision: %r" % device.provision) + asserts.assert_true(hasattr(device, 'provision'), + "device.provision: %r" % device.provision) provision = device.provision - assert_true('available' in provision, - "provision.available: %r" % provision['available']) - assert_true('percent' in provision, - "provision.percent: %r" % provision['percent']) - assert_true('total' in provision, - "provision.total: %r" % provision['total']) + asserts.assert_true('available' in provision, + "provision.available: " + + "%r" % provision['available']) + asserts.assert_true('percent' in provision, + "provision.percent: %r" % provision['percent']) + asserts.assert_true('total' in provision, + "provision.total: %r" % provision['total']) - assert_true(hasattr(device, 'capacity'), - "device.capacity: %r" % device.capacity) + asserts.assert_true(hasattr(device, 'capacity'), + "device.capacity: %r" % device.capacity) capacity = device.capacity - assert_true('available' in capacity, - "capacity.available: %r" % capacity['available']) - assert_true('total' in capacity, - "capacity.total: %r" % capacity['total']) + asserts.assert_true('available' in capacity, + "capacity.available: " + + "%r" % capacity['available']) + asserts.assert_true('total' in capacity, + "capacity.total: %r" % capacity['total']) instance_info.storage = storage @@ -93,15 +95,21 @@ class StorageAfterInstanceCreation(object): for index, device in enumerate(storage): CheckInstance(None).attrs_exist(device._info, expected_attrs, msg="Storage") - assert_equal(device.name, instance_info.storage[index].name) - assert_equal(device.used, instance_info.storage[index].used) - assert_equal(device.type, instance_info.storage[index].type) + asserts.assert_equal(device.name, + instance_info.storage[index].name) + asserts.assert_equal(device.used, + instance_info.storage[index].used) + asserts.assert_equal(device.type, + instance_info.storage[index].type) provision = instance_info.storage[index].provision - assert_equal(device.provision['available'], provision['available']) - assert_equal(device.provision['percent'], provision['percent']) - assert_equal(device.provision['total'], provision['total']) + asserts.assert_equal(device.provision['available'], + provision['available']) + asserts.assert_equal(device.provision['percent'], + provision['percent']) + asserts.assert_equal(device.provision['total'], provision['total']) capacity = instance_info.storage[index].capacity - assert_equal(device.capacity['available'], capacity['available']) - assert_equal(device.capacity['total'], capacity['total']) + asserts.assert_equal(device.capacity['available'], + capacity['available']) + asserts.assert_equal(device.capacity['total'], capacity['total']) diff --git a/trove/tests/api/user_access.py b/trove/tests/api/user_access.py index 6a8a5424aa..acbd3b94d4 100644 --- a/trove/tests/api/user_access.py +++ b/trove/tests/api/user_access.py @@ -19,7 +19,7 @@ from troveclient.compat import exceptions from proboscis import after_class from proboscis import before_class from proboscis import test -from proboscis.asserts import * +from proboscis import asserts from trove import tests from trove.tests.api.instances import instance_info @@ -58,13 +58,13 @@ class UserAccessBase(object): try: self.dbaas.users.grant(instance_info.id, user, databases) except exceptions.BadRequest: - assert_equal(400, expected_response) + asserts.assert_equal(400, expected_response) except exceptions.NotFound: - assert_equal(404, expected_response) + asserts.assert_equal(404, expected_response) except exceptions.ClientException: - assert_equal(500, expected_response) + asserts.assert_equal(500, expected_response) finally: - assert_equal(expected_response, self.dbaas.last_http_code) + asserts.assert_equal(expected_response, self.dbaas.last_http_code) def _grant_access_plural(self, users, databases, expected_response=202): """Grant each user in the list access to all the databases listed. @@ -79,11 +79,11 @@ class UserAccessBase(object): """ try: self.dbaas.users.revoke(instance_info.id, user, database) - assert_true(expected_response, self.dbaas.last_http_code) + asserts.assert_true(expected_response, self.dbaas.last_http_code) except exceptions.BadRequest: - assert_equal(400, self.dbaas.last_http_code) + asserts.assert_equal(400, self.dbaas.last_http_code) except exceptions.NotFound: - assert_equal(404, self.dbaas.last_http_code) + asserts.assert_equal(404, self.dbaas.last_http_code) def _revoke_access_plural(self, users, databases, expected_response=202): """Revoke from each user access to each database. @@ -101,16 +101,17 @@ class UserAccessBase(object): """ for user in users: access = self.dbaas.users.list_access(instance_info.id, user) - assert_equal(expected_response, self.dbaas.last_http_code) + asserts.assert_equal(expected_response, self.dbaas.last_http_code) access = [db.name for db in access] - assert_equal(set(access), set(databases)) + asserts.assert_equal(set(access), set(databases)) def _reset_access(self): for user in self.users: for database in self.databases + self.ghostdbs: try: self.dbaas.users.revoke(instance_info.id, user, database) - assert_true(self.dbaas.last_http_code in [202, 404]) + asserts.assert_true(self.dbaas.last_http_code in [202, 404] + ) except exceptions.NotFound: # This is all right here, since we're resetting. pass @@ -150,31 +151,31 @@ class TestUserAccessPasswordChange(UserAccessBase): def test_change_password_bogus_user(self): user = self._pick_a_user() user["name"] = "thisuserhasanamethatstoolong" - assert_raises(exceptions.BadRequest, - self.dbaas.users.change_passwords, - instance_info.id, [user]) - assert_equal(400, self.dbaas.last_http_code) + asserts.assert_raises(exceptions.BadRequest, + self.dbaas.users.change_passwords, + instance_info.id, [user]) + asserts.assert_equal(400, self.dbaas.last_http_code) @test() def test_change_password_nonexistent_user(self): user = self._pick_a_user() user["name"] = "thisuserDNE" - assert_raises(exceptions.NotFound, - self.dbaas.users.change_passwords, - instance_info.id, [user]) - assert_equal(404, self.dbaas.last_http_code) + asserts.assert_raises(exceptions.NotFound, + self.dbaas.users.change_passwords, + instance_info.id, [user]) + asserts.assert_equal(404, self.dbaas.last_http_code) @test() def test_create_user_and_dbs(self): users = self._user_list_from_names(self.users) # Default password for everyone is 'password'. self.dbaas.users.create(instance_info.id, users) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) databases = [{"name": db} for db in self.databases] self.dbaas.databases.create(instance_info.id, databases) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) @test(depends_on=[test_create_user_and_dbs]) def test_initial_connection(self): @@ -219,7 +220,7 @@ class TestUserAccessPasswordChange(UserAccessBase): def tearDown(self): for database in self.databases: self.dbaas.databases.delete(instance_info.id, database) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) for username in self.users: self.dbaas.users.delete(instance_info.id, username) @@ -246,22 +247,22 @@ class TestUserAccessPositive(UserAccessBase): databases = self.dbaas.databases.list(instance_info.id) database_names = [db.name for db in databases] for ghost in self.ghostdbs: - assert_true(ghost not in database_names) + asserts.assert_true(ghost not in database_names) users = self.dbaas.users.list(instance_info.id) user_names = [user.name for user in users] for ghost in self.ghostusers: - assert_true(ghost not in user_names) + asserts.assert_true(ghost not in user_names) @test() def test_create_user_and_dbs(self): users = self._user_list_from_names(self.users) self.dbaas.users.create(instance_info.id, users) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) databases = [{"name": db} for db in self.databases] self.dbaas.databases.create(instance_info.id, databases) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) @test(depends_on=[test_create_user_and_dbs]) def test_no_access(self): @@ -346,7 +347,7 @@ class TestUserAccessPositive(UserAccessBase): self._reset_access() for database in self.databases: self.dbaas.databases.delete(instance_info.id, database) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) for username in self.users: self.dbaas.users.delete(instance_info.id, username) @@ -370,10 +371,10 @@ class TestUserAccessNegative(UserAccessBase): user_list = self._user_list_from_names(users) try: self.dbaas.users.create(instance_info.id, user_list) - assert_equal(self.dbaas.last_http_code, 202) + asserts.assert_equal(self.dbaas.last_http_code, 202) except exceptions.BadRequest: - assert_equal(self.dbaas.last_http_code, 400) - assert_equal(expected_response, self.dbaas.last_http_code) + asserts.assert_equal(self.dbaas.last_http_code, 400) + asserts.assert_equal(expected_response, self.dbaas.last_http_code) @test() def test_create_duplicate_user_and_dbs(self): @@ -382,10 +383,10 @@ class TestUserAccessNegative(UserAccessBase): """ users = self._user_list_from_names(self.users) self.dbaas.users.create(instance_info.id, users) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) databases = [{"name": db} for db in self.databases] self.dbaas.databases.create(instance_info.id, databases) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) @test(depends_on=[test_create_duplicate_user_and_dbs]) def test_neg_duplicate_useraccess(self): @@ -410,10 +411,10 @@ class TestUserAccessNegative(UserAccessBase): # drop the user temporarily self.dbaas.users.delete(instance_info.id, user_list[0]) # check his access - user should not be found - assert_raises(exceptions.NotFound, - self.dbaas.users.list_access, - instance_info.id, - user_list[0]) + asserts.assert_raises(exceptions.NotFound, + self.dbaas.users.list_access, + instance_info.id, + user_list[0]) # re-create the user self._add_users(user_list) # check his access - should not exist @@ -434,16 +435,16 @@ class TestUserAccessNegative(UserAccessBase): access = None try: access = self.dbaas.users.list_access(instance_info.id, username) - assert_equal(200, self.dbaas.last_http_code) + asserts.assert_equal(200, self.dbaas.last_http_code) except exceptions.BadRequest: - assert_equal(400, self.dbaas.last_http_code) + asserts.assert_equal(400, self.dbaas.last_http_code) except exceptions.NotFound: - assert_equal(404, self.dbaas.last_http_code) + asserts.assert_equal(404, self.dbaas.last_http_code) finally: - assert_equal(access_response, self.dbaas.last_http_code) + asserts.assert_equal(access_response, self.dbaas.last_http_code) if access is not None: access = [db.name for db in access] - assert_equal(set(access), set(self.databases)) + asserts.assert_equal(set(access), set(self.databases)) self._revoke_access_plural([username], databases, revoke_response) @@ -465,23 +466,24 @@ class TestUserAccessNegative(UserAccessBase): # Try and fail to create the user. empty_user = {"name": "", "host": "%", "password": "password", "databases": []} - assert_raises(exceptions.BadRequest, - self.dbaas.users.create, - instance_info.id, - [empty_user]) - assert_equal(400, self.dbaas.last_http_code) + asserts.assert_raises(exceptions.BadRequest, + self.dbaas.users.create, + instance_info.id, + [empty_user]) + asserts.assert_equal(400, self.dbaas.last_http_code) - assert_raises(exceptions.BadRequest, self.dbaas.users.grant, - instance_info.id, "", [], "%") - assert_equal(400, self.dbaas.last_http_code) + asserts.assert_raises(exceptions.BadRequest, self.dbaas.users.grant, + instance_info.id, "", [], "%") + asserts.assert_equal(400, self.dbaas.last_http_code) - assert_raises(exceptions.BadRequest, self.dbaas.users.list_access, - instance_info.id, "", "%") - assert_equal(400, self.dbaas.last_http_code) + asserts.assert_raises(exceptions.BadRequest, + self.dbaas.users.list_access, + instance_info.id, "", "%") + asserts.assert_equal(400, self.dbaas.last_http_code) - assert_raises(exceptions.BadRequest, self.dbaas.users.revoke, - instance_info.id, "", "db", "%") - assert_equal(400, self.dbaas.last_http_code) + asserts.assert_raises(exceptions.BadRequest, self.dbaas.users.revoke, + instance_info.id, "", "db", "%") + asserts.assert_equal(400, self.dbaas.last_http_code) @test def test_user_nametoolong(self): @@ -500,6 +502,6 @@ class TestUserAccessNegative(UserAccessBase): for database in self.databases: self.dbaas.databases.delete(instance_info.id, database) - assert_equal(202, self.dbaas.last_http_code) + asserts.assert_equal(202, self.dbaas.last_http_code) for username in self.users: self.dbaas.users.delete(instance_info.id, username) diff --git a/trove/tests/unittests/common/test_remote.py b/trove/tests/unittests/common/test_remote.py index ebb4765136..3139c045d3 100644 --- a/trove/tests/unittests/common/test_remote.py +++ b/trove/tests/unittests/common/test_remote.py @@ -18,7 +18,7 @@ from mockito import mock, when, unstub import testtools -from testtools.matchers import * +from testtools import matchers import swiftclient.client @@ -59,18 +59,19 @@ class TestRemote(testtools.TestCase): # interact conn = swiftclient.client.Connection() account_info = conn.get_account() - self.assertThat(account_info, Not(Is(None))) - self.assertThat(len(account_info), Is(2)) - self.assertThat(account_info, IsInstance(tuple)) - self.assertThat(account_info[0], IsInstance(dict)) + self.assertThat(account_info, matchers.Not(matchers.Is(None))) + self.assertThat(len(account_info), matchers.Is(2)) + self.assertThat(account_info, matchers.IsInstance(tuple)) + self.assertThat(account_info[0], matchers.IsInstance(dict)) self.assertThat(account_info[0], - KeysEqual('content-length', 'accept-ranges', - 'x-timestamp', 'x-trans-id', 'date', - 'x-account-bytes-used', - 'x-account-container-count', 'content-type', - 'x-account-object-count')) - self.assertThat(account_info[1], IsInstance(list)) - self.assertThat(len(account_info[1]), Is(0)) + matchers.KeysEqual('content-length', 'accept-ranges', + 'x-timestamp', 'x-trans-id', 'date', + 'x-account-bytes-used', + 'x-account-container-count', + 'content-type', + 'x-account-object-count')) + self.assertThat(account_info[1], matchers.IsInstance(list)) + self.assertThat(len(account_info[1]), matchers.Is(0)) def test_one_container(self): """ @@ -86,29 +87,27 @@ class TestRemote(testtools.TestCase): conn.get_auth() conn.put_container(cont_name) # get headers plus container metadata - self.assertThat(len(conn.get_account()), Is(2)) + self.assertThat(len(conn.get_account()), matchers.Is(2)) # verify container details account_containers = conn.get_account()[1] - self.assertThat(len(account_containers), Is(1)) + self.assertThat(len(account_containers), matchers.Is(1)) self.assertThat(account_containers[0], - KeysEqual('count', 'bytes', 'name')) - self.assertThat(account_containers[0]['name'], Is(cont_name)) + matchers.KeysEqual('count', 'bytes', 'name')) + self.assertThat(account_containers[0]['name'], matchers.Is(cont_name)) # get container details cont_info = conn.get_container(cont_name) self.assertIsNotNone(cont_info) - self.assertThat(cont_info[0], KeysEqual('content-length', - "x-container-object-count", - 'accept-ranges', - 'x-container-bytes-used', - 'x-timestamp', 'x-trans-id', - 'date', 'content-type')) - self.assertThat(len(cont_info[1]), Equals(0)) + self.assertThat(cont_info[0], matchers.KeysEqual('content-length', + 'x-container-object-count', 'accept-ranges', + 'x-container-bytes-used', 'x-timestamp', + 'x-trans-id', 'date', 'content-type')) + self.assertThat(len(cont_info[1]), matchers.Equals(0)) # remove container swift_stub.without_container(cont_name) with testtools.ExpectedException(swiftclient.ClientException): conn.get_container(cont_name) # ensure there are no more containers in account - self.assertThat(len(conn.get_account()[1]), Is(0)) + self.assertThat(len(conn.get_account()[1]), matchers.Is(0)) def test_one_object(self): swift_stub = SwiftClientStub() @@ -121,19 +120,22 @@ class TestRemote(testtools.TestCase): cont_info = conn.get_container('bob') self.assertIsNotNone(cont_info) self.assertThat(cont_info[0], - KeysEqual('content-length', 'x-container-object-count', - 'accept-ranges', 'x-container-bytes-used', - 'x-timestamp', 'x-trans-id', 'date', - 'content-type')) + matchers.KeysEqual('content-length', + 'x-container-object-count', + 'accept-ranges', + 'x-container-bytes-used', + 'x-timestamp', 'x-trans-id', 'date', + 'content-type')) cont_objects = cont_info[1] - self.assertThat(len(cont_objects), Equals(1)) + self.assertThat(len(cont_objects), matchers.Equals(1)) obj_1 = cont_objects[0] - self.assertThat(obj_1, Equals( + self.assertThat(obj_1, matchers.Equals( {'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950', 'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test', 'content_type': 'application/octet-stream'})) # test object api - not much to do here - self.assertThat(conn.get_object('bob', 'test')[1], Is('test_contents')) + self.assertThat(conn.get_object('bob', 'test')[1], + matchers.Is('test_contents')) # test remove object swift_stub.without_object('bob', 'test') @@ -141,7 +143,7 @@ class TestRemote(testtools.TestCase): conn.delete_object('bob', 'test') with testtools.ExpectedException(swiftclient.ClientException): conn.delete_object('bob', 'test') - self.assertThat(len(conn.get_container('bob')[1]), Is(0)) + self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(0)) def test_two_objects(self): swift_stub = SwiftClientStub() @@ -157,30 +159,33 @@ class TestRemote(testtools.TestCase): cont_info = conn.get_container('bob') self.assertIsNotNone(cont_info) self.assertThat(cont_info[0], - KeysEqual('content-length', 'x-container-object-count', - 'accept-ranges', 'x-container-bytes-used', - 'x-timestamp', 'x-trans-id', 'date', - 'content-type')) - self.assertThat(len(cont_info[1]), Equals(2)) - self.assertThat(cont_info[1][0], Equals( + matchers.KeysEqual('content-length', + 'x-container-object-count', + 'accept-ranges', + 'x-container-bytes-used', + 'x-timestamp', 'x-trans-id', 'date', + 'content-type')) + self.assertThat(len(cont_info[1]), matchers.Equals(2)) + self.assertThat(cont_info[1][0], matchers.Equals( {'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950', 'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test', 'content_type': 'application/octet-stream'})) - self.assertThat(conn.get_object('bob', 'test')[1], Is('test_contents')) + self.assertThat(conn.get_object('bob', 'test')[1], + matchers.Is('test_contents')) self.assertThat(conn.get_object('bob', 'test2')[1], - Is('test_contents2')) + matchers.Is('test_contents2')) swift_stub.without_object('bob', 'test') conn.delete_object('bob', 'test') with testtools.ExpectedException(swiftclient.ClientException): conn.delete_object('bob', 'test') - self.assertThat(len(conn.get_container('bob')[1]), Is(1)) + self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(1)) swift_stub.without_container('bob') with testtools.ExpectedException(swiftclient.ClientException): conn.get_container('bob') - self.assertThat(len(conn.get_account()), Is(2)) + self.assertThat(len(conn.get_account()), matchers.Is(2)) def test_nonexisting_container(self): """ @@ -212,9 +217,9 @@ class TestRemote(testtools.TestCase): conn.put_object('new-container', 'new-object', 'new-object-contents') obj_resp = conn.get_object('new-container', 'new-object') - self.assertThat(obj_resp, Not(Is(None))) - self.assertThat(len(obj_resp), Is(2)) - self.assertThat(obj_resp[1], Is('new-object-contents')) + self.assertThat(obj_resp, matchers.Not(matchers.Is(None))) + self.assertThat(len(obj_resp), matchers.Is(2)) + self.assertThat(obj_resp[1], matchers.Is('new-object-contents')) # set expected behavior - trivial here since it is the intended # behavior however keep in mind this is just to support testing of @@ -225,8 +230,9 @@ class TestRemote(testtools.TestCase): conn.put_object('new-container', 'new-object', 'updated-object-contents') obj_resp = conn.get_object('new-container', 'new-object') - self.assertThat(obj_resp, Not(Is(None))) - self.assertThat(len(obj_resp), Is(2)) - self.assertThat(obj_resp[1], Is('updated-object-contents')) + self.assertThat(obj_resp, matchers.Not(matchers.Is(None))) + self.assertThat(len(obj_resp), matchers.Is(2)) + self.assertThat(obj_resp[1], matchers.Is('updated-object-contents')) # ensure object count has not increased - self.assertThat(len(conn.get_container('new-container')[1]), Is(1)) + self.assertThat(len(conn.get_container('new-container')[1]), + matchers.Is(1)) diff --git a/trove/tests/util/client.py b/trove/tests/util/client.py index b15e428d99..3b8180adb3 100644 --- a/trove/tests/util/client.py +++ b/trove/tests/util/client.py @@ -27,7 +27,8 @@ """ -from proboscis.asserts import * +from proboscis import asserts + from trove.tests.config import CONFIG from troveclient.compat.xml import TroveXmlClient from trove.openstack.common import processutils @@ -65,7 +66,7 @@ class TestClient(object): def assert_http_code(self, expected_http_code): resp, body = self.real_client.client.last_response - assert_equal(resp.status, expected_http_code) + asserts.assert_equal(resp.status, expected_http_code) @property def last_http_code(self): @@ -75,9 +76,10 @@ class TestClient(object): @staticmethod def find_flavor_self_href(flavor): self_links = [link for link in flavor.links if link['rel'] == 'self'] - assert_true(len(self_links) > 0, "Flavor had no self href!") + asserts.assert_true(len(self_links) > 0, "Flavor had no self href!") flavor_href = self_links[0]['href'] - assert_false(flavor_href is None, "Flavor link self href missing.") + asserts.assert_false(flavor_href is None, + "Flavor link self href missing.") return flavor_href def find_flavors_by(self, condition, flavor_manager=None): @@ -96,9 +98,9 @@ class TestClient(object): def find_flavor_and_self_href(self, flavor_id, flavor_manager=None): """Given an ID, returns flavor and its self href.""" flavor_manager = flavor_manager or self.flavors - assert_false(flavor_id is None) + asserts.assert_false(flavor_id is None) flavor = flavor_manager.get(flavor_id) - assert_false(flavor is None) + asserts.assert_false(flavor is None) flavor_href = self.find_flavor_self_href(flavor) return flavor, flavor_href