profiles and nose_discovery fix

This commit is contained in:
Artem Roma 2013-09-23 14:33:50 +03:00
parent 95f6dd84a9
commit d65e4b2c77
10 changed files with 138 additions and 12 deletions

2
.gitignore vendored
View File

@ -9,3 +9,5 @@ build
dist
*.out
.coverage
.ropeproject
*.swp

View File

@ -13,3 +13,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
'''
Main purpose of following attribute is
to supply general information about test set.
This information will be stored in ostf database
in test_sets table.
'''
__profile__ = {
"id": "ha",
"driver": "nose",
"test_path": "fuel-ostf-tests/fuel_health/tests/ha",
"description": "HA tests. Duration sec - min"
}

View File

@ -13,3 +13,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
'''
Main purpose of following attribute is
to supply general information about test set.
This information will be stored in ostf database
in test_sets table.
'''
__profile__ = {
"id": "sanity",
"driver": "nose",
"test_path": "fuel-ostf-tests/fuel_health/tests/sanity",
"description": "Sanity tests. Duration 30sec - 2 min"
}

View File

@ -13,3 +13,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
'''
Main purpose of following attribute is
to supply general information about test set.
This information will be stored in ostf database
in test_sets table.
'''
__profile__ = {
"id": "smoke",
"driver": "nose",
"test_path": "fuel-ostf-tests/fuel_health/tests/smoke",
"description": "Smoke tests. Duration 3 min - 14 min"
}

View File

@ -24,7 +24,7 @@ def parse_cli():
action='store_true', dest='debug')
parser.add_argument(
'--dbpath', metavar='DB_PATH',
default='postgresql+psycopg2://adapter:demo@localhost/testing_adapter')
default='postgresql+psycopg2://ostf:ostf@localhost/ostf')
parser.add_argument('--host', default='127.0.0.1')
parser.add_argument('--port', default='8989')
parser.add_argument('--log_file', default=None, metavar='PATH')

View File

@ -18,8 +18,12 @@ import json
import os
import multiprocessing
import logging
from nose import case
LOG = logging.getLogger(__name__)
def parse_json_file(file_path):
current_directory = os.path.dirname(os.path.realpath(__file__))
@ -40,12 +44,22 @@ def get_exc_message(exception_value):
def get_description(test_obj):
'''
Parses docstring of test object in order
to get necessary data.
test_obj.test._testMethodDoc is using directly
instead of calling test_obj.shortDescription()
for the sake of compability with python 2.6 where
this method works pretty buggy.
'''
if isinstance(test_obj, case.Test):
docstring = test_obj.shortDescription()
docstring = test_obj.test._testMethodDoc
if docstring:
duration_pattern = r'Duration:.?(?P<duration>.+)'
duration_matcher = re.search(duration_pattern, docstring)
if duration_matcher:
duration = duration_matcher.group(1)
docstring = docstring[:duration_matcher.start()]

View File

@ -35,9 +35,15 @@ PECAN_DEFAULT = {
}
def setup_config(pecan_config):
pecan_config.update(PECAN_DEFAULT)
pecan.conf.update(pecan_config)
def setup_config(custom_pecan_config):
'''
Updates defaults values for pecan server
by those supplied via command line arguments
when ostf-server is started
'''
config_to_use = PECAN_DEFAULT
config_to_use.update(custom_pecan_config)
pecan.conf.update(config_to_use)
def setup_app(config=None):

View File

@ -15,7 +15,7 @@
__profile__ = {
"id": "general_test",
"driver": "nose",
"test_path": "fuel_plugin/tests/functional/dummy_tests/general_test.py",
"test_path": "fuel-ostf-tests/fuel_plugin/tests/functional/dummy_tests/general_test.py",
"description": "General fake tests"
}
@ -56,4 +56,6 @@ class Dummy_test(unittest.TestCase):
conn.request("GET", "/random.aspx")
def test_fail_with_step(self):
"""Fast fail with step
"""
self.fail('Step 3 Failed: Fake fail message')

View File

@ -15,7 +15,7 @@
__profile__ = {
"id": "stopped_test",
"driver": "nose",
"test_path": "fuel_plugin.tests.functional.dummy_tests.stopped_test.py",
"test_path": "fuel-ostf-tests/fuel_plugin/tests/functional/dummy_tests/stopped_test.py",
"description": "Long running 25 secs fake tests"
}

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from mock import patch
import unittest2
from mock import patch
from fuel_plugin.ostf_adapter.nose_plugin import nose_discovery
@ -38,12 +38,75 @@ general__profile__ = {
class TestNoseDiscovery(unittest2.TestCase):
def setUp(self):
self.fixtures = [models.TestSet(**stopped__profile__),
models.TestSet(**general__profile__)]
self.fixtures = [models.TestSet(**general__profile__),
models.TestSet(**stopped__profile__)]
self.fixtures_iter = iter(self.fixtures)
def test_discovery(self, engine):
engine.get_session().merge.return_value = \
engine.get_session().merge.side_effect = \
lambda *args, **kwargs: self.fixtures_iter.next()
nose_discovery.discovery(path='fuel_plugin/tests/functional/dummy_tests')
nose_discovery.discovery(
path='fuel_plugin/tests/functional/dummy_tests'
)
self.assertEqual(engine.get_session().merge.call_count, 2)
def test_get_proper_description(self, engine):
'''
Checks whether retrived docsctrings from tests
are correct (in this occasion -- full).
Magic that is used here is based on using
data that is stored deeply in passed to test
method mock object.
'''
#etalon data is list of docstrings of tests
#of particular test set
expected = {
'title': 'fast pass test',
'name':
'fuel_plugin.tests.functional.dummy_tests.general_test.Dummy_test.test_fast_pass',
'duration': '1sec',
'description':
' This is a simple always pass test\n '
}
#mocking behaviour of afterImport hook from DiscoveryPlugin
#so that another hook -- addSuccess could process data properly
engine.get_session().merge = lambda arg: arg
#following code provide mocking logic for
#addSuccess hook from DiscoveryPlugin that
#(mentioned logic) in turn allows us to
#capture data about test object that are processed
engine.get_session()\
.query()\
.filter_by()\
.update\
.return_value = None
nose_discovery.discovery(
path='fuel_plugin/tests/functional/dummy_tests'
)
#now we can refer to captured test objects (not test_sets) in order to
#make test comparison against etalon
test_obj_to_compare = [
call[0][0] for call in engine.get_session().add.call_args_list
if (
isinstance(call[0][0], models.Test)
and
call[0][0].name.rsplit('.')[-1] == 'test_fast_pass'
)
][0]
self.assertTrue(
all(
[
expected[key] == test_obj_to_compare.__dict__[key]
for key in expected.keys()
]
)
)