Skip to content

Commit

Permalink
[qacode] fix for v0.4.2+ update to v0.4.3 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
netzulo authored Apr 17, 2018
1 parent dec6b36 commit 3551785
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 29 deletions.
58 changes: 37 additions & 21 deletions qacode/core/testing/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,48 @@
import re
import time
import pytest
from qacode.core.exceptions.core_exception import CoreException
from qacode.core.bots.bot_base import BotBase
from qacode.core.loggers.logger_manager import LoggerManager
from qacode.core.utils import settings


ASSERT_MSG_DEFAULT = "Fails at '{}': actual={}, expected={}"
ASSERT_REGEX_URL = r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" # noqa: E501
SETTINGS = settings()
SETTINGS_BOT = SETTINGS.get('bot')
LOGGER_MANAGER = LoggerManager(
log_path="{}/".format(
SETTINGS_BOT.get('log_output_file')),
log_name=SETTINGS_BOT.get('log_name'),
log_level=SETTINGS_BOT.get('log_level')
)


class TestInfoBase(object):
"""Base class for inherit new Test classes"""

is_loaded = False
log = None
config = None

@classmethod
def bot_open(cls):
def load(cls, config):
"""Load default config dict"""
if config is None and not cls.is_loaded:
raise CoreException(message="Bad param 'config' provided")
cls.add_property('config', value=config)
if cls.log is None:
config_bot = cls.config.get('bot')
log_path = "{}/".format(
config_bot.get('log_output_file'))
lgm = LoggerManager(
log_path=log_path,
log_name=config_bot.get('log_name'),
log_level=config_bot.get('log_level')
)
cls.add_property('log', lgm.logger)
cls.is_loaded = True

@classmethod
def bot_open(cls, config):
"""Open browser using BotBase instance
Returns:
BotBase -- wrapper browser handler for selenium
"""
return BotBase(**SETTINGS)
return BotBase(**config)

@classmethod
def bot_close(cls, bot):
Expand All @@ -45,7 +57,9 @@ def bot_close(cls, bot):
@classmethod
def settings_apps(cls):
"""TODO: doc method"""
return SETTINGS['tests']['apps']
if cls.config is None:
raise CoreException(message="Call to cls.load() first")
return cls.config.get('tests').get('apps')

@classmethod
def settings_app(cls, app_name):
Expand Down Expand Up @@ -109,9 +123,9 @@ def settings_filter(cls, key_type, key_name):
else:
raise Exception("key_type not found")

def setup_method(self, test_method):
def setup_method(self, test_method, **kwargs):
"""Configure self.attribute"""
self.add_property('log', value=LOGGER_MANAGER.logger)
self.load(kwargs.get('config'))
self.log.info("Started testcase named='{}'".format(
test_method.__name__))

Expand Down Expand Up @@ -381,41 +395,43 @@ def teardown_method(self, test_method, close=True):
"Fails at try to close bot: {}".format(
err))

def setup_method(self, test_method):
def setup_method(self, test_method, **kwargs):
"""Configure self.attribute.
If skipIf mark applied and True as first param for args tuple
then not open bot
"""
super(TestInfoBot, self).setup_method(test_method)
super(TestInfoBot, self).setup_method(test_method, **kwargs)
if 'skipIf' in dir(test_method) and test_method.skipIf.args[0]:
pytest.skip(test_method.skipIf.args[1])
return
if not isinstance(self.bot, BotBase):
self.add_property('bot', value=self.bot_open())
self.add_property('bot', value=self.bot_open(self.config))


class TestInfoBotUnique(TestInfoBot):
"""Inherit class what implements bot on each testcase"""

@classmethod
def setup_class(cls):
def setup_class(cls, **kwargs):
"""If name start with 'test_' and have decorator skipIf
with value True, then not open bot
"""
tests_methods = []
skip_methods = []
skip_force = kwargs.get('skip_force')
for method_name in dir(cls):
if method_name.startswith("test_"):
method = getattr(cls, method_name)
tests_methods.append(method)
if 'skipIf' in dir(method) and method.skipIf.args[0]:
skip_methods.append(method)
if tests_methods == skip_methods:
if tests_methods == skip_methods or skip_force:
pytest.skip("Testsuite skipped")
else:
if not isinstance(cls.bot, BotBase):
cls.add_property('bot', value=cls.bot_open())
cls.add_property('log', value=LOGGER_MANAGER.logger)
cls.load(kwargs.get('config'))
cls.add_property(
'bot', value=cls.bot_open(cls.config))

@classmethod
def teardown_class(cls):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from qacode.core.utils import path_format


VERSION = "0.4.2"
VERSION = "0.4.3"
CURR_PATH = "{}{}".format(path.abspath(path.dirname(__file__)), '/')


Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sonar.projectKey=qacode
sonar.projectName=qacode
sonar.projectDescription=Python library to automate functional testing
sonar.projectVersion=4.2
sonar.projectVersion=4.3
# Language
sonar.language=py
# Comma-separated paths to directories with sources (required)
Expand Down
3 changes: 3 additions & 0 deletions tests/000_unitaries/suite_001_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
class TestConfig(TestInfoBase):
"""Testcases for class TestInfoBase"""

def setup_method(self, test_method):
super(TestConfig, self).setup_method(test_method, config=settings())

# Error Messages
ERR_KEY_NOT_FOUND = "Required key '{}', can't be None"
ERR_KEY_INVALID_VALUE = "Required key '{}', just can be in '{}'"
Expand Down
6 changes: 4 additions & 2 deletions tests/000_unitaries/suite_002_testinfobase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
import logging
import pytest
from qacode.core.testing.test_info import TestInfoBase
from qacode.core.utils import settings


class TestTestInfoBase(TestInfoBase):
"""Testcases for class TestInfoBase"""

def setup_method(self, test_method):
"""Configure self.attribute"""
super(TestTestInfoBase, self).setup_method(test_method)
super(TestTestInfoBase, self).setup_method(
test_method, config=settings())

def test_001_inheritance(self):
"""Test: test_001_inheritance"""
self.assert_is_instance(self, object)
self.assert_is_instance(self, TestInfoBase)
self.assert_is_instance(self.log, logging.Logger)
self.assert_is_instance(self.config, dict)

@pytest.mark.parametrize("log_level", [
"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
Expand Down
4 changes: 4 additions & 0 deletions tests/001_functionals/suite_001_botbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
class TestBotBase(TestInfoBase):
"""Testcases for class BotBase"""

def setup_method(self, test_method):
super(TestBotBase, self).setup_method(
test_method, config=settings())

def teardown_method(self, method):
"""TODO: doc method"""
try:
Expand Down
4 changes: 4 additions & 0 deletions tests/001_functionals/suite_002_testinfobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
class TestTestInfoBot(TestInfoBot):
"""Testcases for class TestInfoBot"""

def setup_method(self, test_method):
super(TestTestInfoBot, self).setup_method(
test_method, config=settings())

@pytest.mark.parametrize('run_time', [1, 2])
@pytest.mark.skipIf(SKIP_BOT_MULTIPLE, SKIP_BOT_MULTIPLE_MSG)
def test_002_multiple_bots(self, run_time):
Expand Down
6 changes: 6 additions & 0 deletions tests/001_functionals/suite_003_testinfobotunique.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
class TestTestInfoBotUnique(TestInfoBotUnique):
"""Testcases for class TestInfoBot"""

@classmethod
def setup_class(cls, **kwargs):
super(TestTestInfoBotUnique, cls).setup_class(
config=settings(),
skip_force=SKIP_BOT_UNIQUE)

@pytest.mark.parametrize('run_time', [1, 2])
@pytest.mark.skipIf(SKIP_BOT_UNIQUE, SKIP_BOT_UNIQUE_MSG)
def test_001_unique_bot_multiple_tests(self, run_time):
Expand Down
8 changes: 7 additions & 1 deletion tests/001_functionals/suite_004_navbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ class TestNavBase(TestInfoBotUnique):
app = None
page_home = None

@classmethod
def setup_class(cls, **kwargs):
super(TestNavBase, cls).setup_class(
config=settings(),
skip_force=SKIP_REMOTES)

def setup_method(self, test_method, close=True):
"""Configure self.attribute"""
super(TestNavBase, self).setup_method(test_method)
super(TestNavBase, self).setup_method(test_method, config=settings())
self.add_property('app', self.settings_app('nav_tests'))
self.add_property('page_home', self.settings_page('nav_tests_home'))

Expand Down
9 changes: 8 additions & 1 deletion tests/001_functionals/suite_005_controlbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ class TestControlBase(TestInfoBotUnique):
app = None
page_login_config = None

@classmethod
def setup_class(cls, **kwargs):
super(TestControlBase, cls).setup_class(
config=settings(),
skip_force=SKIP_CONTROLS)

def setup_method(self, test_method):
"""Configure self.attribute"""
super(TestControlBase, self).setup_method(test_method)
super(TestControlBase, self).setup_method(
test_method, config=settings())
self.add_property(
'app', value=self.settings_app('pages_tests'))
self.add_property(
Expand Down
9 changes: 8 additions & 1 deletion tests/001_functionals/suite_006_controlform.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ class TestControlForm(TestInfoBotUnique):
app = None
page_login_config = None

@classmethod
def setup_class(cls, **kwargs):
super(TestControlForm, cls).setup_class(
config=settings(),
skip_force=SKIP_CONTROLS)

def setup_method(self, test_method):
"""Configure self.attribute"""
super(TestControlForm, self).setup_method(test_method)
super(TestControlForm, self).setup_method(
test_method, config=settings())
self.add_property(
'app', value=self.settings_app('pages_tests'))
self.add_property(
Expand Down
9 changes: 8 additions & 1 deletion tests/001_functionals/suite_007_pagebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ class TestPageBase(TestInfoBotUnique):
page_base_config = None
page_login_config = None

@classmethod
def setup_class(cls, **kwargs):
super(TestPageBase, cls).setup_class(
config=settings(),
skip_force=SKIP_PAGES)

def setup_method(self, test_method, close=True):
"""Unload self.attribute"""
super(TestPageBase, self).setup_method(test_method)
super(TestPageBase, self).setup_method(
test_method, config=settings())
self.add_property('app', self.settings_app('pages_tests'))
self.page_base_config = self.settings_page('page_base')
self.page_login_config = self.settings_page('page_login')
Expand Down
5 changes: 5 additions & 0 deletions tests/001_functionals/suite_008_tlbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
class TestTlBase(TestInfoBase):
"""Test Suite for class TlBase"""

def setup_method(self, test_method):
"""Unload self.attribute"""
super(TestTlBase, self).setup_method(
test_method, config=settings())

@pytest.mark.skipIf(True, "Functionality it's not working yet")
def test_001_instance(self):
"""Test: test_001_instance"""
Expand Down

0 comments on commit 3551785

Please sign in to comment.