Skip to content

Commit

Permalink
fix: remove deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed Apr 3, 2023
1 parent df47f7a commit 590e568
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 203 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -23,6 +23,9 @@ v3.0.0
- New optional config property `options` in [Chromer] section to configure Chrome options instead of using old
property `goog:chromeOptions` in [Capabilities] section.
- Update [RANDOM_PHONE_NUMBER] replacement using new `DataGenerator` class
- Remove deprecated parameter `context` from `map_param` and POEditor methods
- Remove deprecated config property `restart_driver_fail` in [Driver] section
- Remove deprecated environment variables `Config_environment` and `env`

v2.7.0
------
Expand Down
4 changes: 0 additions & 4 deletions toolium/behave/environment.py
Expand Up @@ -45,10 +45,6 @@ def before_all(context):

# Get 'TOOLIUM_CONFIG_ENVIRONMENT' property from user input (e.g. -D TOOLIUM_CONFIG_ENVIRONMENT=ios)
env = context.config.userdata.get('TOOLIUM_CONFIG_ENVIRONMENT')
# Deprecated: use TOOLIUM_CONFIG_ENVIRONMENT property
env = env if env else context.config.userdata.get('Config_environment')
# Deprecated: use TOOLIUM_CONFIG_ENVIRONMENT property
env = env if env else context.config.userdata.get('env')
if env:
os.environ['TOOLIUM_CONFIG_ENVIRONMENT'] = env

Expand Down
11 changes: 4 additions & 7 deletions toolium/driver_wrapper.py
Expand Up @@ -86,16 +86,14 @@ def configure_logger(self, tc_config_log_filename=None, tc_output_log_filename=N
"""
# Get config logger filename
config_log_filename = DriverWrappersPool.get_configured_value('TOOLIUM_CONFIG_LOG_FILENAME',
'Config_log_filename', tc_config_log_filename,
'logging.conf')
tc_config_log_filename, 'logging.conf')
config_log_filename = os.path.join(DriverWrappersPool.config_directory, config_log_filename)

# Configure logger only if logging filename has changed
if self.config_log_filename != config_log_filename:
# Get output logger filename
output_log_filename = DriverWrappersPool.get_configured_value('TOOLIUM_OUTPUT_LOG_FILENAME',
'Output_log_filename', tc_output_log_filename,
'toolium.log')
tc_output_log_filename, 'toolium.log')
output_log_filename = os.path.join(DriverWrappersPool.output_directory, output_log_filename)
output_log_filename = output_log_filename.replace('\\', '\\\\')

Expand All @@ -114,7 +112,7 @@ def configure_properties(self, tc_config_prop_filenames=None, behave_properties=
:param behave_properties: dict with behave user data properties
"""
prop_filenames = DriverWrappersPool.get_configured_value('TOOLIUM_CONFIG_PROPERTIES_FILENAMES',
'Config_prop_filenames', tc_config_prop_filenames,
tc_config_prop_filenames,
'properties.cfg;local-properties.cfg')
prop_filenames = [os.path.join(DriverWrappersPool.config_directory, filename) for filename in
prop_filenames.split(';')]
Expand Down Expand Up @@ -346,8 +344,7 @@ def should_reuse_driver(self, scope, test_passed, context=None):
"""
reuse_driver = self.config.getboolean_optional('Driver', 'reuse_driver')
reuse_driver_session = self.config.getboolean_optional('Driver', 'reuse_driver_session')
restart_driver_after_failure = (self.config.getboolean_optional('Driver', 'restart_driver_after_failure') or
self.config.getboolean_optional('Driver', 'restart_driver_fail'))
restart_driver_after_failure = self.config.getboolean_optional('Driver', 'restart_driver_after_failure')
if context and scope == 'function':
reuse_driver = reuse_driver or (hasattr(context, 'reuse_driver_from_tags')
and context.reuse_driver_from_tags)
Expand Down
17 changes: 6 additions & 11 deletions toolium/driver_wrappers_pool.py
Expand Up @@ -251,22 +251,18 @@ def save_all_webdriver_or_ggr_logs(cls, test_name, test_passed, ggr=False):
driver_index += 1

@staticmethod
def get_configured_value(system_property_name, deprecated_system_property_name, specific_value, default_value):
def get_configured_value(system_property_name, specific_value, default_value):
"""Get configured value from system properties, method parameters or default value
:param system_property_name: system property name
:param deprecated_system_property_name: deprecated system property name
:param specific_value: test case specific value
:param default_value: default value
:returns: configured value
"""
try:
return os.environ[system_property_name]
except KeyError:
try:
return os.environ[deprecated_system_property_name]
except KeyError:
return specific_value if specific_value else default_value
return specific_value if specific_value else default_value

@classmethod
def configure_common_directories(cls, tc_config_files):
Expand All @@ -276,14 +272,14 @@ def configure_common_directories(cls, tc_config_files):
"""
if cls.config_directory is None:
# Get config directory from properties
config_directory = cls.get_configured_value('TOOLIUM_CONFIG_DIRECTORY', 'Config_directory',
config_directory = cls.get_configured_value('TOOLIUM_CONFIG_DIRECTORY',
tc_config_files.config_directory, 'conf')
prop_filenames = cls.get_configured_value('TOOLIUM_CONFIG_PROPERTIES_FILENAMES', 'Config_prop_filenames',
prop_filenames = cls.get_configured_value('TOOLIUM_CONFIG_PROPERTIES_FILENAMES',
tc_config_files.config_properties_filenames, 'properties.cfg')
cls.config_directory = cls._find_parent_directory(config_directory, prop_filenames.split(';')[0])

# Get output directory from properties and create it
cls.output_directory = cls.get_configured_value('TOOLIUM_OUTPUT_DIRECTORY', 'Output_directory',
cls.output_directory = cls.get_configured_value('TOOLIUM_OUTPUT_DIRECTORY',
tc_config_files.output_directory, 'output')
if not os.path.isabs(cls.output_directory):
# If output directory is relative, we use the same path as config directory
Expand All @@ -293,7 +289,6 @@ def configure_common_directories(cls, tc_config_files):
# Get visual baseline directory from properties
default_baseline = os.path.join(cls.output_directory, 'visualtests', 'baseline')
cls.visual_baseline_directory = cls.get_configured_value('TOOLIUM_VISUAL_BASELINE_DIRECTORY',
'Visual_baseline_directory',
tc_config_files.visual_baseline_directory,
default_baseline)
if not os.path.isabs(cls.visual_baseline_directory):
Expand Down Expand Up @@ -364,7 +359,7 @@ def initialize_config_files(tc_config_files=None):
tc_config_files = ConfigFiles()

# Update properties and log file names if an environment is configured
env = DriverWrappersPool.get_configured_value('TOOLIUM_CONFIG_ENVIRONMENT', 'Config_environment', None, None)
env = DriverWrappersPool.get_configured_value('TOOLIUM_CONFIG_ENVIRONMENT', None, None)
if env:
# Update config properties filenames
prop_filenames = tc_config_files.config_properties_filenames
Expand Down
12 changes: 2 additions & 10 deletions toolium/test/behave/test_environment.py
Expand Up @@ -65,19 +65,11 @@ def test_before_all(create_and_configure_wrapper):
assert context.config_files.config_log_filename is None


properties = (
'TOOLIUM_CONFIG_ENVIRONMENT',
'Config_environment',
'env'
)


@pytest.mark.parametrize("property_name", properties)
@mock.patch('toolium.behave.environment.create_and_configure_wrapper')
def test_before_all_config_environment(create_and_configure_wrapper, property_name):
def test_before_all_config_environment(create_and_configure_wrapper):
# Create context mock
context = mock.MagicMock()
context.config.userdata.get.side_effect = lambda x: 'os' if x == property_name else None
context.config.userdata.get.side_effect = lambda x: 'os' if x == 'TOOLIUM_CONFIG_ENVIRONMENT' else None
context.config_files = ConfigFiles()

before_all(context)
Expand Down
56 changes: 18 additions & 38 deletions toolium/test/test_driver_wrapper.py
Expand Up @@ -156,20 +156,6 @@ def test_configure_environment(driver_wrapper):
assert driver_wrapper.config.get('Driver', 'type') == 'android'


def test_configure_environment_deprecated_property(driver_wrapper):
# Check previous values
assert driver_wrapper.config.get('Driver', 'type') == 'firefox'

# Change environment and try to configure again
environment_properties.append('Config_environment')
os.environ['Config_environment'] = 'android'
config_files = DriverWrappersPool.initialize_config_files(ConfigFiles())
driver_wrapper.configure(config_files)

# Check that configuration has been initialized
assert driver_wrapper.config.get('Driver', 'type') == 'android'


@mock.patch('toolium.driver_wrapper.ConfigDriver.create_driver')
def test_connect(create_driver, driver_wrapper):
# Mock data
Expand Down Expand Up @@ -280,45 +266,39 @@ def test_is_maximizable(driver_type, is_maximizable, driver_wrapper):
assert driver_wrapper.is_maximizable() == is_maximizable


# (reuse_driver, reuse_driver_session, restart_driver_after_failure, restart_driver_fail,
# (reuse_driver, reuse_driver_session, restart_driver_after_failure,
# reuse_driver_from_tags, scope, test_passed, expected_should_reuse_driver)
should_be_reused = (
('true', 'true', 'true', 'true', True, 'function', True, True), # all = true
('true', 'true', 'true', True, 'function', True, True), # all = true
# reuse_driver
('true', 'false', 'false', 'false', False, 'function', True, True), # reuse = true, function
('true', 'false', 'false', 'false', False, 'module', True, False), # reuse = true, module
('true', 'false', 'false', 'false', False, 'session', True, False), # reuse = true, session
('false', 'false', 'false', 'false', False, 'function', True, False), # reuse = false
('true', 'false', 'false', False, 'function', True, True), # reuse = true, function
('true', 'false', 'false', False, 'module', True, False), # reuse = true, module
('true', 'false', 'false', False, 'session', True, False), # reuse = true, session
('false', 'false', 'false', False, 'function', True, False), # reuse = false
# restart_driver_after_failure
('true', 'false', 'false', 'false', False, 'function', True, True), # restart = false, test passed
('true', 'false', 'true', 'false', False, 'function', True, True), # restart = true, test passed
('true', 'false', 'false', 'false', False, 'function', False, True), # restart = false, test failed
('true', 'false', 'true', 'false', False, 'function', False, False), # restart = true, test failed
# restart_driver_fail (deprecated)
('true', 'false', 'false', 'false', False, 'function', True, True), # restart = false, test passed
('true', 'false', 'false', 'true', False, 'function', True, True), # restart = true, test passed
('true', 'false', 'false', 'false', False, 'function', False, True), # restart = false, test failed
('true', 'false', 'false', 'true', False, 'function', False, False), # restart = true, test failed
('true', 'false', 'false', False, 'function', True, True), # restart = false, test passed
('true', 'false', 'true', False, 'function', True, True), # restart = true, test passed
('true', 'false', 'false', False, 'function', False, True), # restart = false, test failed
('true', 'false', 'true', False, 'function', False, False), # restart = true, test failed
# reuse_driver_session
('false', 'true', 'false', 'false', False, 'function', True, True), # reuse = true, function
('false', 'true', 'false', 'false', False, 'module', True, True), # reuse = true, module
('false', 'true', 'false', 'false', False, 'session', True, False), # reuse = true, session
('false', 'true', 'false', False, 'function', True, True), # reuse = true, function
('false', 'true', 'false', False, 'module', True, True), # reuse = true, module
('false', 'true', 'false', False, 'session', True, False), # reuse = true, session
# reuse_driver_from_tags
('false', 'false', 'false', 'false', True, 'function', True, True), # reuse = true, function
('false', 'false', 'false', 'false', True, 'module', True, False), # reuse = true, module
('false', 'false', 'false', 'false', True, 'session', True, False), # reuse = true, session
('false', 'false', 'false', True, 'function', True, True), # reuse = true, function
('false', 'false', 'false', True, 'module', True, False), # reuse = true, module
('false', 'false', 'false', True, 'session', True, False), # reuse = true, session
)


@pytest.mark.parametrize("reuse_driver, reuse_driver_session, restart_driver_after_failure, restart_driver_fail, "
@pytest.mark.parametrize("reuse_driver, reuse_driver_session, restart_driver_after_failure, "
"reuse_driver_from_tags, scope, test_passed, expected_should_reuse_driver", should_be_reused)
def test_should_reuse_driver(reuse_driver, reuse_driver_session, restart_driver_after_failure, restart_driver_fail,
def test_should_reuse_driver(reuse_driver, reuse_driver_session, restart_driver_after_failure,
reuse_driver_from_tags, scope, test_passed, expected_should_reuse_driver, driver_wrapper):
# Set config properties
driver_wrapper.config.set('Driver', 'reuse_driver', reuse_driver)
driver_wrapper.config.set('Driver', 'reuse_driver_session', reuse_driver_session)
driver_wrapper.config.set('Driver', 'restart_driver_after_failure', restart_driver_after_failure)
driver_wrapper.config.set('Driver', 'restart_driver_fail', restart_driver_fail)

# Create context mock
context = mock.MagicMock()
Expand Down
7 changes: 0 additions & 7 deletions toolium/test/test_driver_wrapper_logger.py
Expand Up @@ -51,13 +51,6 @@ def driver_wrapper():
environment_properties = []


def test_configure_logger_deprecated(driver_wrapper):
environment_properties.append('Config_log_filename')
os.environ['Config_log_filename'] = 'logging.conf'
driver_wrapper.configure_logger()
assert logging.getLevelName(driver_wrapper.logger.getEffectiveLevel()) == 'DEBUG'


def test_configure_logger(driver_wrapper):
environment_properties.append('TOOLIUM_CONFIG_LOG_FILENAME')
os.environ['TOOLIUM_CONFIG_LOG_FILENAME'] = 'logging.conf'
Expand Down
9 changes: 0 additions & 9 deletions toolium/test/test_driver_wrapper_properties.py
Expand Up @@ -57,15 +57,6 @@ def driver_wrapper():
environment_properties = []


def test_configure_properties_deprecated(driver_wrapper):
environment_properties.append('Config_prop_filenames')
os.environ['Config_prop_filenames'] = 'properties.cfg'
driver_wrapper.configure_properties()
assert driver_wrapper.config.get('Driver', 'type') == 'firefox' # get last value
assert driver_wrapper.config.get_optional('Driver', 'implicitly_wait') == '5' # only in properties
assert driver_wrapper.config.get_optional('AppiumCapabilities', 'app') is None # only in android


def test_configure_properties(driver_wrapper):
environment_properties.append('TOOLIUM_CONFIG_PROPERTIES_FILENAMES')
os.environ['TOOLIUM_CONFIG_PROPERTIES_FILENAMES'] = 'properties.cfg'
Expand Down
38 changes: 0 additions & 38 deletions toolium/test/utils/test_dataset_map_param.py
Expand Up @@ -157,22 +157,6 @@ class Obj(object):
assert expected_att == result_att


def test_a_context_param_deprecated():
"""
Verification of a mapped parameter as CONTEXT and check that deprecated message is logged
"""
context = mock.MagicMock()
context.attribute = "attribute value"
dataset.logger = mock.MagicMock()

result_att = map_param("[CONTEXT:attribute]", context)
expected_att = "attribute value"
assert expected_att == result_att
dataset.logger.warning.assert_called_with("Deprecated context parameter has been sent to map_param method. Please, "
"configure dataset global variables instead of passing context to "
"map_param.")


def test_a_poe_param_single_result():
"""
Verification of a POE mapped parameter with a single result for a reference
Expand All @@ -189,28 +173,6 @@ def test_a_poe_param_single_result():
assert result == expected


def test_a_poe_param_single_result_deprecated():
"""
Verification of a POE mapped parameter with a single result for a reference
"""
context = mock.MagicMock()
context.poeditor_export = [
{
"term": "Poniendo mute",
"definition": "Ahora la tele está silenciada",
"reference": "home:home.tv.mute",
}
]
dataset.logger = mock.MagicMock()

result = map_param('[POE:home.tv.mute]', context)
expected = "Ahora la tele está silenciada"
assert result == expected
dataset.logger.warning.assert_called_with("Deprecated context parameter has been sent to map_param method. Please, "
"configure dataset global variables instead of passing context to "
"map_param.")


def test_a_poe_param_no_result_assertion():
"""
Verification of a POE mapped parameter without result
Expand Down
14 changes: 0 additions & 14 deletions toolium/test/utils/test_poeditor.py
Expand Up @@ -69,17 +69,3 @@ def test_load_poeditor_texts_without_api_token():

load_poeditor_texts()
poeditor.logger.info.assert_called_with("POEditor is not configured")


def test_load_poeditor_texts_without_api_token_deprecated():
"""
Verification of POEditor texts load abortion when api_token is not configured and deprecated message is logged
"""
context = mock.MagicMock()
poeditor.logger = mock.MagicMock()

load_poeditor_texts(context)
poeditor.logger.info.assert_called_with("POEditor is not configured")
poeditor.logger.warning.assert_called_with("Deprecated context parameter has been sent to load_poeditor_texts "
"method. Please, configure POEditor global variables instead of passing "
"context to load_poeditor_texts.")

0 comments on commit 590e568

Please sign in to comment.