Files
rally/tests/objects/test_task.py
Olga Kopylova c800370cfd Fix hacking 0.9.x issues
Fixed issues:
H202 assertRaises Exception too broad
H305 imports not grouped correctly
H307 like imports should be grouped together
H405 multi line docstring summary not separated with an empty line
H904 Wrap long lines in parentheses instead of a backslash
E122 continuation line missing indentation or outdented
E128 continuation line under-indented for visual indent
E131 continuation line unaligned for hanging indent
E251 unexpected spaces around keyword / parameter equals
E265 block comment should start with '# '

Change-Id: Ia2b8994c58686e3570f303f0725a2850d6b36e47
2014-06-18 14:59:18 +03:00

134 lines
5.2 KiB
Python

# Copyright 2013: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tests for db.task layer."""
import json
import uuid
import mock
from rally import consts
from rally import objects
from tests import test
class TaskTestCase(test.TestCase):
def setUp(self):
super(TaskTestCase, self).setUp()
self.task = {
'uuid': str(uuid.uuid4()),
'status': consts.TaskStatus.INIT,
'failed': False,
'verification_log': '',
}
@mock.patch('rally.objects.task.db.task_create')
def test_init_with_create(self, mock_create):
mock_create.return_value = self.task
task = objects.Task(failed=True)
mock_create.assert_called_once_with({'failed': True})
self.assertEqual(task['uuid'], self.task['uuid'])
@mock.patch('rally.objects.task.db.task_create')
def test_init_without_create(self, mock_create):
task = objects.Task(task=self.task)
self.assertFalse(mock_create.called)
self.assertEqual(task['uuid'], self.task['uuid'])
@mock.patch('rally.objects.task.db.task_get')
def test_get(self, mock_get):
mock_get.return_value = self.task
task = objects.Task.get(self.task['uuid'])
mock_get.assert_called_once_with(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_create')
def test_create_and_delete(self, mock_create, mock_delete):
mock_create.return_value = self.task
task = objects.Task()
task.delete()
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_create')
def test_create_and_delete_status(self, mock_create, mock_delete):
mock_create.return_value = self.task
task = objects.Task()
task.delete(status=consts.TaskStatus.FINISHED)
mock_delete.assert_called_once_with(self.task['uuid'],
status=consts.TaskStatus.FINISHED)
@mock.patch('rally.objects.task.db.task_delete')
def test_delete_by_uuid(self, mock_delete):
objects.Task.delete_by_uuid(self.task['uuid'])
mock_delete.assert_called_once_with(self.task['uuid'], status=None)
@mock.patch('rally.objects.task.db.task_delete')
def test_delete_by_uuid_status(self, mock_delete):
objects.Task.delete_by_uuid(self.task['uuid'],
consts.TaskStatus.FINISHED)
mock_delete.assert_called_once_with(self.task['uuid'],
status=consts.TaskStatus.FINISHED)
@mock.patch('rally.objects.deploy.db.task_update')
@mock.patch('rally.objects.task.db.task_create')
def test_update(self, mock_create, mock_update):
mock_create.return_value = self.task
mock_update.return_value = {'opt': 'val2'}
deploy = objects.Task(opt='val1')
deploy._update({'opt': 'val2'})
mock_update.assert_called_once_with(self.task['uuid'],
{'opt': 'val2'})
self.assertEqual(deploy['opt'], 'val2')
@mock.patch('rally.objects.task.db.task_update')
def test_update_status(self, mock_update):
mock_update.return_value = self.task
task = objects.Task(task=self.task)
task.update_status(consts.TaskStatus.FINISHED)
mock_update.assert_called_once_with(
self.task['uuid'],
{'status': consts.TaskStatus.FINISHED},
)
@mock.patch('rally.objects.task.db.task_update')
def test_update_verification_log(self, mock_update):
mock_update.return_value = self.task
task = objects.Task(task=self.task)
task.update_verification_log({"a": "fake"})
mock_update.assert_called_once_with(
self.task['uuid'],
{'verification_log': json.dumps({"a": "fake"})}
)
@mock.patch('rally.objects.task.db.task_result_create')
def test_append_results(self, mock_append_results):
task = objects.Task(task=self.task)
task.append_results('opt', 'val')
mock_append_results.assert_called_once_with(self.task['uuid'],
'opt', 'val')
@mock.patch('rally.objects.task.db.task_update')
def test_set_failed(self, mock_update):
mock_update.return_value = self.task
task = objects.Task(task=self.task)
task.set_failed()
mock_update.assert_called_once_with(
self.task['uuid'],
{'failed': True, 'status': 'failed', 'verification_log': '""'},
)