Replace ' with " in tests/unit/verification

Partial bug: 1405884

Change-Id: I6f4e08a04ce1e67fa4bedf299b9c7f8def36902b
This commit is contained in:
jacobliberman 2015-02-03 11:19:43 -06:00
parent d347a9d9e5
commit 246975a5c9
9 changed files with 258 additions and 258 deletions

View File

@ -27,95 +27,95 @@ class DeploymentTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(DeploymentTestCase, self).setUp() super(DeploymentTestCase, self).setUp()
self.deployment = { self.deployment = {
'uuid': 'baa1bfb6-0c38-4f6c-9bd0-45968890e4f4', "uuid": "baa1bfb6-0c38-4f6c-9bd0-45968890e4f4",
'name': '', "name": "",
'config': {}, "config": {},
'endpoint': {}, "endpoint": {},
'status': consts.DeployStatus.DEPLOY_INIT, "status": consts.DeployStatus.DEPLOY_INIT,
} }
self.resource = { self.resource = {
'id': 42, "id": 42,
'deployment_uuid': self.deployment['uuid'], "deployment_uuid": self.deployment["uuid"],
'provider_name': 'provider', "provider_name": "provider",
'type': 'some', "type": "some",
'info': {'key': 'value'}, "info": {"key": "value"},
} }
@mock.patch('rally.objects.deploy.db.deployment_create') @mock.patch("rally.objects.deploy.db.deployment_create")
def test_init_with_create(self, mock_create): def test_init_with_create(self, mock_create):
mock_create.return_value = self.deployment mock_create.return_value = self.deployment
deploy = objects.Deployment() deploy = objects.Deployment()
mock_create.assert_called_once_with({}) mock_create.assert_called_once_with({})
self.assertEqual(deploy['uuid'], self.deployment['uuid']) self.assertEqual(deploy["uuid"], self.deployment["uuid"])
@mock.patch('rally.objects.deploy.db.deployment_create') @mock.patch("rally.objects.deploy.db.deployment_create")
def test_init_without_create(self, mock_create): def test_init_without_create(self, mock_create):
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
self.assertFalse(mock_create.called) self.assertFalse(mock_create.called)
self.assertEqual(deploy['uuid'], self.deployment['uuid']) self.assertEqual(deploy["uuid"], self.deployment["uuid"])
@mock.patch('rally.objects.deploy.db.deployment_get') @mock.patch("rally.objects.deploy.db.deployment_get")
def test_get(self, mock_get): def test_get(self, mock_get):
mock_get.return_value = self.deployment mock_get.return_value = self.deployment
deploy = objects.Deployment.get(self.deployment['uuid']) deploy = objects.Deployment.get(self.deployment["uuid"])
mock_get.assert_called_once_with(self.deployment['uuid']) mock_get.assert_called_once_with(self.deployment["uuid"])
self.assertEqual(deploy['uuid'], self.deployment['uuid']) self.assertEqual(deploy["uuid"], self.deployment["uuid"])
@mock.patch('rally.objects.deploy.db.deployment_delete') @mock.patch("rally.objects.deploy.db.deployment_delete")
@mock.patch('rally.objects.deploy.db.deployment_create') @mock.patch("rally.objects.deploy.db.deployment_create")
def test_create_and_delete(self, mock_create, mock_delete): def test_create_and_delete(self, mock_create, mock_delete):
mock_create.return_value = self.deployment mock_create.return_value = self.deployment
deploy = objects.Deployment() deploy = objects.Deployment()
deploy.delete() deploy.delete()
mock_delete.assert_called_once_with(self.deployment['uuid']) mock_delete.assert_called_once_with(self.deployment["uuid"])
@mock.patch('rally.objects.deploy.db.deployment_delete') @mock.patch("rally.objects.deploy.db.deployment_delete")
def test_delete_by_uuid(self, mock_delete): def test_delete_by_uuid(self, mock_delete):
objects.Deployment.delete_by_uuid(self.deployment['uuid']) objects.Deployment.delete_by_uuid(self.deployment["uuid"])
mock_delete.assert_called_once_with(self.deployment['uuid']) mock_delete.assert_called_once_with(self.deployment["uuid"])
@mock.patch('rally.objects.deploy.db.deployment_update') @mock.patch("rally.objects.deploy.db.deployment_update")
@mock.patch('rally.objects.deploy.db.deployment_create') @mock.patch("rally.objects.deploy.db.deployment_create")
def test_update(self, mock_create, mock_update): def test_update(self, mock_create, mock_update):
mock_create.return_value = self.deployment mock_create.return_value = self.deployment
mock_update.return_value = {'opt': 'val2'} mock_update.return_value = {"opt": "val2"}
deploy = objects.Deployment(opt='val1') deploy = objects.Deployment(opt="val1")
deploy._update({'opt': 'val2'}) deploy._update({"opt": "val2"})
mock_update.assert_called_once_with(self.deployment['uuid'], mock_update.assert_called_once_with(self.deployment["uuid"],
{'opt': 'val2'}) {"opt": "val2"})
self.assertEqual(deploy['opt'], 'val2') self.assertEqual(deploy["opt"], "val2")
@mock.patch('rally.objects.deploy.db.deployment_update') @mock.patch("rally.objects.deploy.db.deployment_update")
def test_update_status(self, mock_update): def test_update_status(self, mock_update):
mock_update.return_value = self.deployment mock_update.return_value = self.deployment
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
deploy.update_status(consts.DeployStatus.DEPLOY_FAILED) deploy.update_status(consts.DeployStatus.DEPLOY_FAILED)
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.deployment['uuid'], self.deployment["uuid"],
{'status': consts.DeployStatus.DEPLOY_FAILED}, {"status": consts.DeployStatus.DEPLOY_FAILED},
) )
@mock.patch('rally.objects.deploy.db.deployment_update') @mock.patch("rally.objects.deploy.db.deployment_update")
def test_update_name(self, mock_update): def test_update_name(self, mock_update):
mock_update.return_value = self.deployment mock_update.return_value = self.deployment
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
deploy.update_name('new_name') deploy.update_name("new_name")
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.deployment['uuid'], self.deployment["uuid"],
{'name': 'new_name'}, {"name": "new_name"},
) )
@mock.patch('rally.objects.deploy.db.deployment_update') @mock.patch("rally.objects.deploy.db.deployment_update")
def test_update_config(self, mock_update): def test_update_config(self, mock_update):
mock_update.return_value = self.deployment mock_update.return_value = self.deployment
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
deploy.update_config({'opt': 'val'}) deploy.update_config({"opt": "val"})
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.deployment['uuid'], self.deployment["uuid"],
{'config': {'opt': 'val'}}, {"config": {"opt": "val"}},
) )
@mock.patch('rally.objects.deploy.db.deployment_update') @mock.patch("rally.objects.deploy.db.deployment_update")
def test_update_endpoints(self, mock_update): def test_update_endpoints(self, mock_update):
mock_update.return_value = self.deployment mock_update.return_value = self.deployment
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
@ -141,7 +141,7 @@ class DeploymentTestCase(test.TestCase):
"users": expected_users "users": expected_users
}) })
@mock.patch('rally.objects.deploy.db.deployment_update') @mock.patch("rally.objects.deploy.db.deployment_update")
def test_update_empty_endpoints(self, mock_update): def test_update_empty_endpoints(self, mock_update):
mock_update.return_value = self.deployment mock_update.return_value = self.deployment
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
@ -149,55 +149,55 @@ class DeploymentTestCase(test.TestCase):
mock_update.assert_called_once_with(self.deployment["uuid"], mock_update.assert_called_once_with(self.deployment["uuid"],
{"admin": {}, "users": []}) {"admin": {}, "users": []})
@mock.patch('rally.objects.deploy.db.resource_create') @mock.patch("rally.objects.deploy.db.resource_create")
def test_add_resource(self, mock_create): def test_add_resource(self, mock_create):
mock_create.return_value = self.resource mock_create.return_value = self.resource
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
resource = deploy.add_resource('provider', type='some', resource = deploy.add_resource("provider", type="some",
info={'key': 'value'}) info={"key": "value"})
self.assertEqual(resource['id'], self.resource['id']) self.assertEqual(resource["id"], self.resource["id"])
mock_create.assert_called_once_with({ mock_create.assert_called_once_with({
'deployment_uuid': self.deployment['uuid'], "deployment_uuid": self.deployment["uuid"],
'provider_name': 'provider', "provider_name": "provider",
'type': 'some', "type": "some",
'info': {'key': 'value'}, "info": {"key": "value"},
}) })
@mock.patch('rally.objects.task.db.resource_delete') @mock.patch("rally.objects.task.db.resource_delete")
def test_delete(self, mock_delete): def test_delete(self, mock_delete):
objects.Deployment.delete_resource(42) objects.Deployment.delete_resource(42)
mock_delete.assert_called_once_with(42) mock_delete.assert_called_once_with(42)
@mock.patch('rally.objects.task.db.resource_get_all') @mock.patch("rally.objects.task.db.resource_get_all")
def test_get_resources(self, mock_get_all): def test_get_resources(self, mock_get_all):
mock_get_all.return_value = [self.resource] mock_get_all.return_value = [self.resource]
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
resources = deploy.get_resources(provider_name='provider', type='some') resources = deploy.get_resources(provider_name="provider", type="some")
self.assertEqual(len(resources), 1) self.assertEqual(len(resources), 1)
self.assertEqual(resources[0]['id'], self.resource['id']) self.assertEqual(resources[0]["id"], self.resource["id"])
@mock.patch('rally.objects.deploy.datetime.datetime') @mock.patch("rally.objects.deploy.datetime.datetime")
@mock.patch('rally.objects.deploy.db.deployment_update') @mock.patch("rally.objects.deploy.db.deployment_update")
def test_update_set_started(self, mock_update, mock_datetime): def test_update_set_started(self, mock_update, mock_datetime):
mock_datetime.now = mock.Mock(return_value='fake_time') mock_datetime.now = mock.Mock(return_value="fake_time")
mock_update.return_value = self.deployment mock_update.return_value = self.deployment
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
deploy.set_started() deploy.set_started()
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.deployment['uuid'], self.deployment["uuid"],
{'started_at': 'fake_time', {"started_at": "fake_time",
'status': consts.DeployStatus.DEPLOY_STARTED} "status": consts.DeployStatus.DEPLOY_STARTED}
) )
@mock.patch('rally.objects.deploy.datetime.datetime') @mock.patch("rally.objects.deploy.datetime.datetime")
@mock.patch('rally.objects.deploy.db.deployment_update') @mock.patch("rally.objects.deploy.db.deployment_update")
def test_update_set_completed(self, mock_update, mock_datetime): def test_update_set_completed(self, mock_update, mock_datetime):
mock_datetime.now = mock.Mock(return_value='fake_time') mock_datetime.now = mock.Mock(return_value="fake_time")
mock_update.return_value = self.deployment mock_update.return_value = self.deployment
deploy = objects.Deployment(deployment=self.deployment) deploy = objects.Deployment(deployment=self.deployment)
deploy.set_completed() deploy.set_completed()
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.deployment['uuid'], self.deployment["uuid"],
{'completed_at': 'fake_time', {"completed_at": "fake_time",
'status': consts.DeployStatus.DEPLOY_FINISHED} "status": consts.DeployStatus.DEPLOY_FINISHED}
) )

View File

@ -28,59 +28,59 @@ class TaskTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(TaskTestCase, self).setUp() super(TaskTestCase, self).setUp()
self.task = { self.task = {
'uuid': '00ef46a2-c5b8-4aea-a5ca-0f54a10cbca1', "uuid": "00ef46a2-c5b8-4aea-a5ca-0f54a10cbca1",
'status': consts.TaskStatus.INIT, "status": consts.TaskStatus.INIT,
'verification_log': '', "verification_log": "",
} }
@mock.patch('rally.objects.task.db.task_create') @mock.patch("rally.objects.task.db.task_create")
def test_init_with_create(self, mock_create): def test_init_with_create(self, mock_create):
mock_create.return_value = self.task mock_create.return_value = self.task
task = objects.Task(status=consts.TaskStatus.FAILED) task = objects.Task(status=consts.TaskStatus.FAILED)
mock_create.assert_called_once_with({ mock_create.assert_called_once_with({
'status': consts.TaskStatus.FAILED}) "status": consts.TaskStatus.FAILED})
self.assertEqual(task['uuid'], self.task['uuid']) self.assertEqual(task["uuid"], self.task["uuid"])
@mock.patch('rally.objects.task.db.task_create') @mock.patch("rally.objects.task.db.task_create")
def test_init_without_create(self, mock_create): def test_init_without_create(self, mock_create):
task = objects.Task(task=self.task) task = objects.Task(task=self.task)
self.assertFalse(mock_create.called) self.assertFalse(mock_create.called)
self.assertEqual(task['uuid'], self.task['uuid']) self.assertEqual(task["uuid"], self.task["uuid"])
@mock.patch('rally.objects.task.db.task_get') @mock.patch("rally.objects.task.db.task_get")
def test_get(self, mock_get): def test_get(self, mock_get):
mock_get.return_value = self.task mock_get.return_value = self.task
task = objects.Task.get(self.task['uuid']) task = objects.Task.get(self.task["uuid"])
mock_get.assert_called_once_with(self.task['uuid']) mock_get.assert_called_once_with(self.task["uuid"])
self.assertEqual(task['uuid'], self.task['uuid']) self.assertEqual(task["uuid"], self.task["uuid"])
@mock.patch('rally.objects.task.db.task_delete') @mock.patch("rally.objects.task.db.task_delete")
@mock.patch('rally.objects.task.db.task_create') @mock.patch("rally.objects.task.db.task_create")
def test_create_and_delete(self, mock_create, mock_delete): def test_create_and_delete(self, mock_create, mock_delete):
mock_create.return_value = self.task mock_create.return_value = self.task
task = objects.Task() task = objects.Task()
task.delete() task.delete()
mock_delete.assert_called_once_with(self.task['uuid'], status=None) mock_delete.assert_called_once_with(self.task["uuid"], status=None)
@mock.patch('rally.objects.task.db.task_delete') @mock.patch("rally.objects.task.db.task_delete")
@mock.patch('rally.objects.task.db.task_create') @mock.patch("rally.objects.task.db.task_create")
def test_create_and_delete_status(self, mock_create, mock_delete): def test_create_and_delete_status(self, mock_create, mock_delete):
mock_create.return_value = self.task mock_create.return_value = self.task
task = objects.Task() task = objects.Task()
task.delete(status=consts.TaskStatus.FINISHED) task.delete(status=consts.TaskStatus.FINISHED)
mock_delete.assert_called_once_with(self.task['uuid'], mock_delete.assert_called_once_with(self.task["uuid"],
status=consts.TaskStatus.FINISHED) status=consts.TaskStatus.FINISHED)
@mock.patch('rally.objects.task.db.task_delete') @mock.patch("rally.objects.task.db.task_delete")
def test_delete_by_uuid(self, mock_delete): def test_delete_by_uuid(self, mock_delete):
objects.Task.delete_by_uuid(self.task['uuid']) objects.Task.delete_by_uuid(self.task["uuid"])
mock_delete.assert_called_once_with(self.task['uuid'], status=None) mock_delete.assert_called_once_with(self.task["uuid"], status=None)
@mock.patch('rally.objects.task.db.task_delete') @mock.patch("rally.objects.task.db.task_delete")
def test_delete_by_uuid_status(self, mock_delete): def test_delete_by_uuid_status(self, mock_delete):
objects.Task.delete_by_uuid(self.task['uuid'], objects.Task.delete_by_uuid(self.task["uuid"],
consts.TaskStatus.FINISHED) consts.TaskStatus.FINISHED)
mock_delete.assert_called_once_with(self.task['uuid'], mock_delete.assert_called_once_with(self.task["uuid"],
status=consts.TaskStatus.FINISHED) status=consts.TaskStatus.FINISHED)
@mock.patch("rally.objects.task.db.task_list", @mock.patch("rally.objects.task.db.task_list",
@ -97,35 +97,35 @@ class TaskTestCase(test.TestCase):
self.assertEqual(mock_db_task_list.return_value["uuis"], self.assertEqual(mock_db_task_list.return_value["uuis"],
tasks[0]["uuid"]) tasks[0]["uuid"])
@mock.patch('rally.objects.deploy.db.task_update') @mock.patch("rally.objects.deploy.db.task_update")
@mock.patch('rally.objects.task.db.task_create') @mock.patch("rally.objects.task.db.task_create")
def test_update(self, mock_create, mock_update): def test_update(self, mock_create, mock_update):
mock_create.return_value = self.task mock_create.return_value = self.task
mock_update.return_value = {'opt': 'val2'} mock_update.return_value = {"opt": "val2"}
deploy = objects.Task(opt='val1') deploy = objects.Task(opt="val1")
deploy._update({'opt': 'val2'}) deploy._update({"opt": "val2"})
mock_update.assert_called_once_with(self.task['uuid'], mock_update.assert_called_once_with(self.task["uuid"],
{'opt': 'val2'}) {"opt": "val2"})
self.assertEqual(deploy['opt'], 'val2') self.assertEqual(deploy["opt"], "val2")
@mock.patch('rally.objects.task.db.task_update') @mock.patch("rally.objects.task.db.task_update")
def test_update_status(self, mock_update): def test_update_status(self, mock_update):
mock_update.return_value = self.task mock_update.return_value = self.task
task = objects.Task(task=self.task) task = objects.Task(task=self.task)
task.update_status(consts.TaskStatus.FINISHED) task.update_status(consts.TaskStatus.FINISHED)
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.task['uuid'], self.task["uuid"],
{'status': consts.TaskStatus.FINISHED}, {"status": consts.TaskStatus.FINISHED},
) )
@mock.patch('rally.objects.task.db.task_update') @mock.patch("rally.objects.task.db.task_update")
def test_update_verification_log(self, mock_update): def test_update_verification_log(self, mock_update):
mock_update.return_value = self.task mock_update.return_value = self.task
task = objects.Task(task=self.task) task = objects.Task(task=self.task)
task.update_verification_log({"a": "fake"}) task.update_verification_log({"a": "fake"})
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.task['uuid'], self.task["uuid"],
{'verification_log': json.dumps({"a": "fake"})} {"verification_log": json.dumps({"a": "fake"})}
) )
@mock.patch("rally.objects.task.db.task_result_get_all_by_uuid", @mock.patch("rally.objects.task.db.task_result_get_all_by_uuid",
@ -136,19 +136,19 @@ class TaskTestCase(test.TestCase):
mock_get.assert_called_once_with(self.task["uuid"]) mock_get.assert_called_once_with(self.task["uuid"])
self.assertEqual(results, "foo_results") self.assertEqual(results, "foo_results")
@mock.patch('rally.objects.task.db.task_result_create') @mock.patch("rally.objects.task.db.task_result_create")
def test_append_results(self, mock_append_results): def test_append_results(self, mock_append_results):
task = objects.Task(task=self.task) task = objects.Task(task=self.task)
task.append_results('opt', 'val') task.append_results("opt", "val")
mock_append_results.assert_called_once_with(self.task['uuid'], mock_append_results.assert_called_once_with(self.task["uuid"],
'opt', 'val') "opt", "val")
@mock.patch('rally.objects.task.db.task_update') @mock.patch("rally.objects.task.db.task_update")
def test_set_failed(self, mock_update): def test_set_failed(self, mock_update):
mock_update.return_value = self.task mock_update.return_value = self.task
task = objects.Task(task=self.task) task = objects.Task(task=self.task)
task.set_failed() task.set_failed()
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.task['uuid'], self.task["uuid"],
{'status': consts.TaskStatus.FAILED, 'verification_log': '""'}, {"status": consts.TaskStatus.FAILED, "verification_log": '""'},
) )

View File

@ -24,67 +24,67 @@ class VerificationTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(VerificationTestCase, self).setUp() super(VerificationTestCase, self).setUp()
self.db_obj = { self.db_obj = {
'id': 777, "id": 777,
'uuid': 'test_uuid', "uuid": "test_uuid",
'failures': 0, 'tests': 2, 'errors': 0, 'time': '0.54', "failures": 0, "tests": 2, "errors": 0, "time": "0.54",
'details': { "details": {
'failures': 0, 'tests': 2, 'errors': 0, 'time': '0.54', "failures": 0, "tests": 2, "errors": 0, "time": "0.54",
'test_cases': [ "test_cases": [
{'classname': 'foo.Test', {"classname": "foo.Test",
'name': 'foo_test[gate,negative]', "name": "foo_test[gate,negative]",
'time': '0.25'}, "time": "0.25"},
{'classname': 'bar.Test', {"classname": "bar.Test",
'name': 'bar_test[gate,negative]', "name": "bar_test[gate,negative]",
'time': '0.29'}]}} "time": "0.29"}]}}
@mock.patch('rally.objects.verification.db.verification_create') @mock.patch("rally.objects.verification.db.verification_create")
def test_init_with_create(self, mock_create): def test_init_with_create(self, mock_create):
objects.Verification(deployment_uuid='some_deployment_uuid') objects.Verification(deployment_uuid="some_deployment_uuid")
mock_create.assert_called_once_with('some_deployment_uuid') mock_create.assert_called_once_with("some_deployment_uuid")
@mock.patch('rally.objects.verification.db.verification_create') @mock.patch("rally.objects.verification.db.verification_create")
def test_init_without_create(self, mock_create): def test_init_without_create(self, mock_create):
verification = objects.Verification(db_object=self.db_obj) verification = objects.Verification(db_object=self.db_obj)
self.assertEqual(0, mock_create.call_count) self.assertEqual(0, mock_create.call_count)
self.assertEqual(self.db_obj['failures'], verification.failures) self.assertEqual(self.db_obj["failures"], verification.failures)
self.assertEqual(self.db_obj['tests'], verification.tests) self.assertEqual(self.db_obj["tests"], verification.tests)
self.assertEqual(self.db_obj['errors'], verification.errors) self.assertEqual(self.db_obj["errors"], verification.errors)
self.assertEqual(self.db_obj['time'], verification.time) self.assertEqual(self.db_obj["time"], verification.time)
@mock.patch('rally.objects.verification.db.verification_get') @mock.patch("rally.objects.verification.db.verification_get")
def test_get(self, mock_get): def test_get(self, mock_get):
objects.Verification.get(self.db_obj['id']) objects.Verification.get(self.db_obj["id"])
mock_get.assert_called_once_with(self.db_obj['id']) mock_get.assert_called_once_with(self.db_obj["id"])
@mock.patch('rally.objects.verification.db.verification_delete') @mock.patch("rally.objects.verification.db.verification_delete")
@mock.patch('rally.objects.verification.db.verification_create') @mock.patch("rally.objects.verification.db.verification_create")
def test_create_and_delete(self, mock_create, mock_delete): def test_create_and_delete(self, mock_create, mock_delete):
verification = objects.Verification(db_object=self.db_obj) verification = objects.Verification(db_object=self.db_obj)
verification.delete() verification.delete()
mock_delete.assert_called_once_with(self.db_obj['uuid']) mock_delete.assert_called_once_with(self.db_obj["uuid"])
@mock.patch('rally.objects.verification.db.verification_update') @mock.patch("rally.objects.verification.db.verification_update")
def test_set_failed(self, mock_update): def test_set_failed(self, mock_update):
mock_update.return_value = self.db_obj mock_update.return_value = self.db_obj
verification = objects.Verification(db_object=self.db_obj) verification = objects.Verification(db_object=self.db_obj)
verification.set_failed() verification.set_failed()
mock_update.assert_called_once_with(self.db_obj['uuid'], mock_update.assert_called_once_with(self.db_obj["uuid"],
{'status': 'failed'}) {"status": "failed"})
@mock.patch('rally.objects.verification.db.verification_result_create') @mock.patch("rally.objects.verification.db.verification_result_create")
@mock.patch('rally.objects.verification.db.verification_update') @mock.patch("rally.objects.verification.db.verification_update")
def test_finish_verification(self, mock_update, mock_create): def test_finish_verification(self, mock_update, mock_create):
verification = objects.Verification(db_object=self.db_obj) verification = objects.Verification(db_object=self.db_obj)
fake_results = fakes.get_fake_test_case() fake_results = fakes.get_fake_test_case()
verification.finish_verification( verification.finish_verification(
fake_results['total'], fake_results["total"],
fake_results['test_cases']) fake_results["test_cases"])
expected_values = {'status': 'finished'} expected_values = {"status": "finished"}
expected_values.update(fake_results['total']) expected_values.update(fake_results["total"])
mock_update.assert_called_with(self.db_obj['uuid'], expected_values) mock_update.assert_called_with(self.db_obj["uuid"], expected_values)
expected_data = fake_results['total'].copy() expected_data = fake_results["total"].copy()
expected_data['test_cases'] = fake_results['test_cases'] expected_data["test_cases"] = fake_results["test_cases"]
mock_create.assert_called_once_with(verification.uuid, expected_data) mock_create.assert_called_once_with(verification.uuid, expected_data)

View File

@ -94,7 +94,7 @@ class TaskAPITestCase(test.TestCase):
self.assertRaises(TypeError, api.Task.render_template, "{{a}}") self.assertRaises(TypeError, api.Task.render_template, "{{a}}")
@mock.patch("rally.objects.Deployment.get", @mock.patch("rally.objects.Deployment.get",
return_value={'uuid': 'b0d9cd6c-2c94-4417-a238-35c7019d0257'}) return_value={"uuid": "b0d9cd6c-2c94-4417-a238-35c7019d0257"})
@mock.patch("rally.objects.Task") @mock.patch("rally.objects.Task")
def test_create(self, mock_task, mock_d_get): def test_create(self, mock_task, mock_d_get):
tag = "a" tag = "a"
@ -207,7 +207,7 @@ class DeploymentAPITestCase(BaseDeploymentTestCase):
@mock.patch("rally.objects.deploy.db.deployment_update") @mock.patch("rally.objects.deploy.db.deployment_update")
@mock.patch("rally.objects.deploy.db.deployment_create") @mock.patch("rally.objects.deploy.db.deployment_create")
@mock.patch("rally.deploy.engine.EngineFactory.validate", @mock.patch("rally.deploy.engine.EngineFactory.validate",
side_effect=jsonschema.ValidationError('ValidationError')) side_effect=jsonschema.ValidationError("ValidationError"))
def test_create_validation_error(self, mock_validate, mock_create, def test_create_validation_error(self, mock_validate, mock_create,
mock_update): mock_update):
mock_create.return_value = self.deployment mock_create.return_value = self.deployment
@ -216,12 +216,12 @@ class DeploymentAPITestCase(BaseDeploymentTestCase):
self.deployment_config, "fake_deployment") self.deployment_config, "fake_deployment")
mock_update.assert_called_once_with( mock_update.assert_called_once_with(
self.deployment_uuid, self.deployment_uuid,
{'status': consts.DeployStatus.DEPLOY_FAILED}) {"status": consts.DeployStatus.DEPLOY_FAILED})
@mock.patch("rally.api.LOG") @mock.patch("rally.api.LOG")
@mock.patch("rally.objects.deploy.db.deployment_create", @mock.patch("rally.objects.deploy.db.deployment_create",
side_effect=exceptions.DeploymentNameExists( side_effect=exceptions.DeploymentNameExists(
deployment='fake_deploy')) deployment="fake_deploy"))
def test_create_duplication_error(self, mock_d_create, mock_log): def test_create_duplication_error(self, mock_d_create, mock_log):
self.assertRaises(exceptions.DeploymentNameExists, self.assertRaises(exceptions.DeploymentNameExists,
api.Deployment.create, self.deployment_config, api.Deployment.create, self.deployment_config,

View File

@ -16,27 +16,27 @@
def get_fake_test_case(): def get_fake_test_case():
return { return {
'total': { "total": {
'failures': 1, "failures": 1,
'tests': 2, "tests": 2,
'errors': 0, "errors": 0,
'time': 1.412}, "time": 1.412},
'test_cases': { "test_cases": {
'fake.failed.TestCase.with_StringException[gate,negative]': { "fake.failed.TestCase.with_StringException[gate,negative]": {
'name': "name":
'fake.failed.TestCase.with_StringException[gate,negative]', "fake.failed.TestCase.with_StringException[gate,negative]",
'failure': { "failure": {
'type': 'testtools.testresult.real._StringException', "type": "testtools.testresult.real._StringException",
'log': "log":
('_StringException: Empty attachments:\nOops...There ' ("_StringException: Empty attachments:\nOops...There "
'was supposed to be fake traceback, but it is not.\n') "was supposed to be fake traceback, but it is not.\n")
}, },
'time': 0.706, "time": 0.706,
'status': 'FAIL'}, "status": "FAIL"},
'fake.successful.TestCase.fake_test[gate,negative]': { "fake.successful.TestCase.fake_test[gate,negative]": {
'name': 'fake.successful.TestCase.fake_test[gate,negative]', "name": "fake.successful.TestCase.fake_test[gate,negative]",
'time': 0.706, "time": 0.706,
'status': 'OK' "status": "OK"
} }
} }
} }

View File

@ -19,12 +19,12 @@ from tests.unit import test
class Compare2HtmlTestCase(test.TestCase): class Compare2HtmlTestCase(test.TestCase):
def test_main(self): def test_main(self):
results = [{'val2': 0.0111, 'field': u'time', 'val1': 0.0222, results = [{"val2": 0.0111, "field": u"time", "val1": 0.0222,
'type': 'CHANGED', 'test_name': u'test.one'}, "type": "CHANGED", "test_name": u"test.one"},
{'val2': 0.111, 'field': u'time', 'val1': 0.222, {"val2": 0.111, "field": u"time", "val1": 0.222,
'type': 'CHANGED', 'test_name': u'test.two'}, "type": "CHANGED", "test_name": u"test.two"},
{'val2': 1.11, 'field': u'time', 'val1': 2.22, {"val2": 1.11, "field": u"time", "val1": 2.22,
'type': 'CHANGED', 'test_name': u'test.three'}] "type": "CHANGED", "test_name": u"test.three"}]
fake_kw = {"heading": fake_kw = {"heading":
{"title": compare2html.__title__, {"title": compare2html.__title__,
@ -34,6 +34,6 @@ class Compare2HtmlTestCase(test.TestCase):
"generator": "compare2html %s" % compare2html.__version__, "generator": "compare2html %s" % compare2html.__version__,
"results": results} "results": results}
with mock.patch('mako.template.Template') as mock_mako: with mock.patch("mako.template.Template") as mock_mako:
compare2html.create_report(results) compare2html.create_report(results)
mock_mako().render.assert_called_once_with(**fake_kw) mock_mako().render.assert_called_once_with(**fake_kw)

View File

@ -297,14 +297,14 @@ class ConfigTestCase(test.TestCase):
self.assertEqual(self.conf_generator.conf.get( self.assertEqual(self.conf_generator.conf.get(
"service_available", "horizon"), "True") "service_available", "horizon"), "True")
@mock.patch('six.moves.builtins.open', side_effect=mock.mock_open(), @mock.patch("six.moves.builtins.open", side_effect=mock.mock_open(),
create=True) create=True)
def test_write_config(self, mock_open): def test_write_config(self, mock_open):
self.conf_generator.conf = mock.Mock() self.conf_generator.conf = mock.Mock()
file_name = '/path/to/fake/conf' file_name = "/path/to/fake/conf"
self.conf_generator.write_config(file_name) self.conf_generator.write_config(file_name)
mock_open.assert_called_once_with(file_name, 'w+') mock_open.assert_called_once_with(file_name, "w+")
self.conf_generator.conf.write.assert_called_once_with( self.conf_generator.conf.write.assert_called_once_with(
mock_open.side_effect()) mock_open.side_effect())

View File

@ -16,74 +16,74 @@ from tests.unit import test
class DiffTestCase(test.TestCase): class DiffTestCase(test.TestCase):
def test_main(self): def test_main(self):
results1 = {'test.NONE': {'name': 'test.NONE', results1 = {"test.NONE": {"name": "test.NONE",
'output': 'test.NONE', "output": "test.NONE",
'status': 'SKIPPED', "status": "SKIPPED",
'time': 0.000}, "time": 0.000},
'test.zerofive': {'name': 'test.zerofive', "test.zerofive": {"name": "test.zerofive",
'output': 'test.zerofive', "output": "test.zerofive",
'status': 'FAILED', "status": "FAILED",
'time': 0.05}, "time": 0.05},
'test.one': {'name': 'test.one', "test.one": {"name": "test.one",
'output': 'test.one', "output": "test.one",
'status': 'OK', "status": "OK",
'time': 0.111}, "time": 0.111},
'test.two': {'name': 'test.two', "test.two": {"name": "test.two",
'output': 'test.two', "output": "test.two",
'status': 'OK', "status": "OK",
'time': 0.222}, "time": 0.222},
'test.three': {'name': 'test.three', "test.three": {"name": "test.three",
'output': 'test.three', "output": "test.three",
'status': 'FAILED', "status": "FAILED",
'time': 0.333}, "time": 0.333},
'test.four': {'name': 'test.four', "test.four": {"name": "test.four",
'output': 'test.four', "output": "test.four",
'status': 'OK', "status": "OK",
'time': 0.444}, "time": 0.444},
'test.five': {'name': 'test.five', "test.five": {"name": "test.five",
'output': 'test.five', "output": "test.five",
'status': 'OK', "status": "OK",
'time': 0.555} "time": 0.555}
} }
results2 = {'test.one': {'name': 'test.one', results2 = {"test.one": {"name": "test.one",
'output': 'test.one', "output": "test.one",
'status': 'FAIL', "status": "FAIL",
'time': 0.1111}, "time": 0.1111},
'test.two': {'name': 'test.two', "test.two": {"name": "test.two",
'output': 'test.two', "output": "test.two",
'status': 'OK', "status": "OK",
'time': 0.222}, "time": 0.222},
'test.three': {'name': 'test.three', "test.three": {"name": "test.three",
'output': 'test.three', "output": "test.three",
'status': 'OK', "status": "OK",
'time': 0.3333}, "time": 0.3333},
'test.four': {'name': 'test.four', "test.four": {"name": "test.four",
'output': 'test.four', "output": "test.four",
'status': 'FAIL', "status": "FAIL",
'time': 0.4444}, "time": 0.4444},
'test.five': {'name': 'test.five', "test.five": {"name": "test.five",
'output': 'test.five', "output": "test.five",
'status': 'OK', "status": "OK",
'time': 0.555}, "time": 0.555},
'test.six': {'name': 'test.six', "test.six": {"name": "test.six",
'output': 'test.six', "output": "test.six",
'status': 'OK', "status": "OK",
'time': 0.666}, "time": 0.666},
'test.seven': {'name': 'test.seven', "test.seven": {"name": "test.seven",
'output': 'test.seven', "output": "test.seven",
'status': 'OK', "status": "OK",
'time': 0.777} "time": 0.777}
} }
diff_ = diff.Diff(results1, results2, 0) diff_ = diff.Diff(results1, results2, 0)
assert len(diff_.diffs) == 10 assert len(diff_.diffs) == 10
assert len([test for test in diff_.diffs assert len([test for test in diff_.diffs
if test['type'] == 'removed_test']) == 2 if test["type"] == "removed_test"]) == 2
assert len([test for test in diff_.diffs assert len([test for test in diff_.diffs
if test['type'] == 'new_test']) == 2 if test["type"] == "new_test"]) == 2
assert len([test for test in diff_.diffs assert len([test for test in diff_.diffs
if test['type'] == 'value_changed']) == 6 if test["type"] == "value_changed"]) == 6
assert diff_.to_csv() != '' assert diff_.to_csv() != ""
assert diff_.to_html() != '' assert diff_.to_html() != ""
assert diff_.to_json() != '' assert diff_.to_json() != ""

View File

@ -34,7 +34,7 @@ TEMPEST_PATH = "rally.verification.tempest"
class BaseTestCase(test.TestCase): class BaseTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(BaseTestCase, self).setUp() super(BaseTestCase, self).setUp()
self.verifier = tempest.Tempest('fake_deployment_id', self.verifier = tempest.Tempest("fake_deployment_id",
verification=mock.MagicMock()) verification=mock.MagicMock())
self.verifier._path = "/tmp" self.verifier._path = "/tmp"
@ -135,24 +135,24 @@ class TempestUtilsTestCase(BaseTestCase):
mock_isdir.assert_called_once_with( mock_isdir.assert_called_once_with(
self.verifier.path(".testrepository")) self.verifier.path(".testrepository"))
mock_sp.assert_called_once_with( mock_sp.assert_called_once_with(
'%s testr init' % self.verifier.venv_wrapper, shell=True, "%s testr init" % self.verifier.venv_wrapper, shell=True,
cwd=self.verifier.path(), stderr=subprocess.STDOUT) cwd=self.verifier.path(), stderr=subprocess.STDOUT)
@mock.patch.object(subunit2json, 'main') @mock.patch.object(subunit2json, "main")
@mock.patch('os.path.isfile', return_value=False) @mock.patch("os.path.isfile", return_value=False)
def test__save_results_without_log_file(self, mock_isfile, mock_parse): def test__save_results_without_log_file(self, mock_isfile, mock_parse):
self.verifier._save_results() self.verifier._save_results()
mock_isfile.assert_called_once_with(self.verifier.log_file_raw) mock_isfile.assert_called_once_with(self.verifier.log_file_raw)
self.assertEqual(0, mock_parse.call_count) self.assertEqual(0, mock_parse.call_count)
@mock.patch('os.path.isfile', return_value=True) @mock.patch("os.path.isfile", return_value=True)
def test__save_results_with_log_file(self, mock_isfile): def test__save_results_with_log_file(self, mock_isfile):
with mock.patch.object(subunit2json, 'main') as mock_main: with mock.patch.object(subunit2json, "main") as mock_main:
data = {'total': True, 'test_cases': True} data = {"total": True, "test_cases": True}
mock_main.return_value = jsonutils.dumps(data) mock_main.return_value = jsonutils.dumps(data)
self.verifier.log_file_raw = os.path.join( self.verifier.log_file_raw = os.path.join(
os.path.dirname(__file__), 'subunit.stream') os.path.dirname(__file__), "subunit.stream")
self.verifier._save_results() self.verifier._save_results()
mock_isfile.assert_called_once_with(self.verifier.log_file_raw) mock_isfile.assert_called_once_with(self.verifier.log_file_raw)
mock_main.assert_called_once_with( mock_main.assert_called_once_with(
@ -168,7 +168,7 @@ class TempestInstallAndUninstallTestCase(BaseTestCase):
def test__clone_successful(self, mock_sp): def test__clone_successful(self, mock_sp):
self.verifier._clone() self.verifier._clone()
mock_sp.assert_called_once_with( mock_sp.assert_called_once_with(
['git', 'clone', 'https://github.com/openstack/tempest', ["git", "clone", "https://github.com/openstack/tempest",
tempest.Tempest.base_repo]) tempest.Tempest.base_repo])
@mock.patch(TEMPEST_PATH + ".tempest.subprocess.check_call") @mock.patch(TEMPEST_PATH + ".tempest.subprocess.check_call")
@ -178,7 +178,7 @@ class TempestInstallAndUninstallTestCase(BaseTestCase):
self.assertRaises(subprocess.CalledProcessError, self.verifier._clone) self.assertRaises(subprocess.CalledProcessError, self.verifier._clone)
mock_sp.assert_called_once_with( mock_sp.assert_called_once_with(
['git', 'clone', 'https://github.com/openstack/tempest', ["git", "clone", "https://github.com/openstack/tempest",
tempest.Tempest.base_repo]) tempest.Tempest.base_repo])
@mock.patch(TEMPEST_PATH + ".tempest.Tempest._initialize_testr") @mock.patch(TEMPEST_PATH + ".tempest.Tempest._initialize_testr")