Add tests for methods of Test model class

Change-Id: Iaedb7120d8620b43dcc0ce8169fda1d0c4f804f8
Partial-Bug: #1435229
This commit is contained in:
Artem Roma 2015-09-16 11:49:23 +03:00 committed by tatyana-leontovich
parent 07b86655b7
commit 30848e6dc6
3 changed files with 159 additions and 8 deletions

View File

@ -173,7 +173,8 @@ class Test(BASE):
@classmethod
def add_result(cls, session, test_run_id, test_name, data):
session.query(cls).\
filter_by(name=test_name, test_run_id=test_run_id).\
filter(cls.name == test_name,
cls.test_run_id == test_run_id).\
update(data, synchronize_session=False)
@classmethod

View File

@ -190,6 +190,13 @@ class BaseIntegrationTest(BaseUnitTest):
if transaction.nested and not transaction._parent.nested:
session.begin_nested()
def discovery(self):
"""Discover dummy tests used for testsing."""
mixins.TEST_REPOSITORY = []
nose_discovery.discovery(path=TEST_PATH, session=self.session)
mixins.cache_test_repository(self.session)
self.session.flush()
def tearDown(self):
# rollback changes to database
# made by tests
@ -264,13 +271,6 @@ class BaseWSGITest(BaseIntegrationTest):
self.app = webtest.TestApp(app.setup_app(session=self.session))
def discovery(self):
"""Discover dummy tests used for testsing."""
mixins.TEST_REPOSITORY = []
nose_discovery.discovery(path=TEST_PATH, session=self.session)
mixins.cache_test_repository(self.session)
self.session.flush()
def is_background_working(self):
is_working = True

View File

@ -0,0 +1,150 @@
# Copyright 2015 Mirantis, Inc.
#
# 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.
import six
from fuel_plugin.testing.tests import base
from fuel_plugin.ostf_adapter import mixins
from fuel_plugin.ostf_adapter.storage import models
class TestModelTestMethods(base.BaseIntegrationTest):
def setUp(self):
super(TestModelTestMethods, self).setUp()
self.discovery()
self.test_set_id = 'general_test'
self.cluster_id = 1
self.mock_api_for_cluster(self.cluster_id)
mixins.discovery_check(self.session, self.cluster_id)
self.session.flush()
self.test_obj = self.session.query(models.Test)\
.filter_by(test_set_id=self.test_set_id)\
.first()
self.test_run = models.TestRun.add_test_run(
self.session,
self.test_obj.test_set_id,
self.cluster_id,
status='running',
tests=[self.test_obj.name]
)
self.session.flush()
@property
def test_to_check(self):
return self.session.query(models.Test)\
.filter_by(test_run_id=self.test_run.id)\
.filter_by(name=self.test_obj.name)\
.first()
def check_model_obj_attrs(self, obj, attrs):
for attr_name, attr_val in six.iteritems(attrs):
self.assertEqual(attr_val, getattr(obj, attr_name))
def test_add_result(self):
expected_data = {
'message': 'test_message',
'status': 'error',
'time_taken': 10.4
}
models.Test.add_result(self.session,
self.test_run.id,
self.test_obj.name,
expected_data)
self.check_model_obj_attrs(self.test_to_check, expected_data)
def test_update_running_tests_default_status(self):
models.Test.update_running_tests(self.session,
self.test_run.id)
self.assertEqual(self.test_to_check.status, 'stopped')
def test_update_running_tests_with_status(self):
expected_status = 'success'
models.Test.update_running_tests(self.session,
self.test_run.id,
status=expected_status)
self.assertEqual(self.test_to_check.status, expected_status)
def test_update_only_running_tests(self):
# the method should update only running tests
expected_status = 'error'
models.Test.add_result(self.session, self.test_run.id,
self.test_obj.name,
{'status': expected_status})
models.Test.update_running_tests(self.session, self.test_run.id)
# check that status of test is not updated to 'stopped'
self.assertEqual(self.test_to_check.status, expected_status)
def test_update_test_run_tests_default_status(self):
models.Test.add_result(self.session, self.test_run.id,
self.test_obj.name,
{'time_taken': 10.4})
models.Test.update_test_run_tests(self.session, self.test_run.id,
[self.test_obj.name])
expected_attrs = {
'status': 'wait_running',
'time_taken': None
}
self.check_model_obj_attrs(self.test_to_check, expected_attrs)
def test_properly_copied_test(self):
new_test = self.test_obj.copy_test(self.test_run, predefined_tests=[])
copied_attrs_list = [
'name',
'title',
'description',
'duration',
'message',
'traceback',
'step',
'time_taken',
'meta',
'deployment_tags',
'available_since_release',
'test_set_id',
]
attrs = {}
for attr_name in copied_attrs_list:
attrs[attr_name] = getattr(self.test_obj, attr_name)
self.check_model_obj_attrs(new_test, attrs)
self.assertEqual(new_test.test_run_id, self.test_run.id)
self.assertEqual(new_test.status, 'wait_running')
def test_copy_test_with_predefined_list(self):
predefined_tests_names = ['some_other_test']
new_test = self.test_obj.copy_test(self.test_run,
predefined_tests_names)
self.assertEqual(new_test.status, 'disabled')