Skip to content

Commit

Permalink
Fix lint warnings and remove deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed Mar 13, 2021
1 parent d558138 commit 1bb82b4
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 198 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -7,6 +7,8 @@ v2.0.0
*Release date: In development*

- Update deprecated methods to fix warnings in python3 execution
- Move *get_valid_filename* and *makedirs_safe* methods from *toolium.path_utils* to *toolium.utils.path_utils*
- Move *Utils* class from *toolium.utils* to *toolium.utils.driver_utils*

v1.9.1
------
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Expand Up @@ -30,6 +30,7 @@
# serve to show the default.

import os
import subprocess
import sys

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -79,8 +80,6 @@
# The short X.Y version.
version = open('../VERSION').read().strip()
# The full version, including alpha/beta/rc tags.
import subprocess

git_log = subprocess.check_output(["git", "log", "--pretty=oneline"])
commits = git_log.split(b'\n')
release = '{}-{}'.format(version, len(commits) - 1)
Expand Down
20 changes: 13 additions & 7 deletions toolium/behave/env_utils.py
Expand Up @@ -16,8 +16,8 @@
limitations under the License.
"""

import warnings
import sys
import warnings
from pkg_resources import parse_version

# constants
Expand Down Expand Up @@ -87,7 +87,8 @@ def by_console(self, text_to_print):

class DynamicEnvironment:
"""
This class is useful when we would like execute generic steps: before the feature, before each scenario, after the feature or/and after each scenario.
This class is useful when we would like execute generic steps: before the feature, before each scenario,
after the feature or/and after each scenario.
It is necessary to append certain lines in the environment.py:
from common.utils.env_utils import DynamicEnvironment
Expand Down Expand Up @@ -196,7 +197,8 @@ def __print_step_by_console(self, step):
def __execute_steps_by_action(self, context, action):
"""
execute a steps set by action
:param context: It’s a clever place where you and behave can store information to share around, automatically managed by behave.
:param context: It’s a clever place where you and behave can store information to share around,
automatically managed by behave.
:param action: action executed: see labels allowed above.
"""
if len(self.actions[action]) > 0:
Expand Down Expand Up @@ -236,7 +238,8 @@ def reset_error_status(self):
def execute_before_feature_steps(self, context):
"""
actions before the feature
:param context: It’s a clever place where you and behave can store information to share around, automatically managed by behave.
:param context: It’s a clever place where you and behave can store information to share around,
automatically managed by behave.
"""
self.__execute_steps_by_action(context, ACTIONS_BEFORE_FEATURE)

Expand All @@ -247,7 +250,8 @@ def execute_before_feature_steps(self, context):
def execute_before_scenario_steps(self, context):
"""
actions before each scenario
:param context: It’s a clever place where you and behave can store information to share around, automatically managed by behave.
:param context: It’s a clever place where you and behave can store information to share around,
automatically managed by behave.
"""
if not self.feature_error:
self.__execute_steps_by_action(context, ACTIONS_BEFORE_SCENARIO)
Expand All @@ -259,7 +263,8 @@ def execute_before_scenario_steps(self, context):
def execute_after_scenario_steps(self, context):
"""
actions after each scenario
:param context: It’s a clever place where you and behave can store information to share around, automatically managed by behave.
:param context: It’s a clever place where you and behave can store information to share around,
automatically managed by behave.
"""
if not self.feature_error:
self.__execute_steps_by_action(context, ACTIONS_AFTER_SCENARIO)
Expand All @@ -272,7 +277,8 @@ def execute_after_scenario_steps(self, context):
def execute_after_feature_steps(self, context):
"""
actions after the feature
:param context: It’s a clever place where you and behave can store information to share around, automatically managed by behave.
:param context: It’s a clever place where you and behave can store information to share around,
automatically managed by behave.
"""
self.__execute_steps_by_action(context, ACTIONS_AFTER_FEATURE)

Expand Down
21 changes: 0 additions & 21 deletions toolium/path_utils.py

This file was deleted.

77 changes: 69 additions & 8 deletions toolium/selenoid.py
Expand Up @@ -25,7 +25,7 @@

# constants
STATUS_OK = 200
STATUS_PORT = "8888"
STATUS_PORT = '8888'
DOWNLOADS_PATH = u'downloads'
MP4_EXTENSION = u'mp4'
LOG_EXTENSION = u'log'
Expand Down Expand Up @@ -133,22 +133,83 @@ def is_the_session_still_active(self):
"""
Is the GGR session still active? Associated to a browser and the sessionId
Example of GGR status:
{"browsers":{"MicrosoftEdge":{"latest":{}},"android":{"8.1":{}},"chrome":{"70.0":{},"latest":{"test_tef":{"count":1,"sessions":[{"caps":{"browserName":"chrome","enableVNC":true,"enableVideo":true,"platform":"ANY","screenResolution":"1280x1024x24","version":"latest","videoName":"selenoide952e551bb9395e16d060f28c54e5d31.mp4","videoScreenSize":"1280x1024"},"container":"8489205e28c9781472e99c3921a6240de3894a3603ed9e187ad6360b6b013b8b","containerInfo":{"id":"8489205e28c9781472e99c3921a6240de3894a3603ed9e187ad6360b6b013b8b","ip":"172.17.0.4"},"id":"1345506093dfed8dbcef610da476911a228ca315978e5464ae49fb1142bbc49b","screen":"1280x1024x24","vnc":true}]}}},"firefox":{"59.0":{},"63.0":{},"64.0":{},"latest":{}},"internet explorer":{"11":{}},"opera":{"56.0":{},"latest":{}},"safari":{"latest":{}}},"pending":0,"queued":0,"total":30,"used":1}
{
"browsers": {
"MicrosoftEdge": {
"latest": {}
},
"android": {
"8.1": {}
},
"chrome": {
"70.0": {},
"latest": {
"test_tef": {
"count": 1,
"sessions": [
{
"caps": {
"browserName": "chrome",
"enableVNC": true,
"enableVideo": true,
"platform": "ANY",
"screenResolution": "1280x1024x24",
"version": "latest",
"videoName": "selenoide952e551bb9395e16d060f28c54e5d31.mp4",
"videoScreenSize": "1280x1024"
},
"container": "8489205e28c9781472e99c3921a6240de3894a3603ed9e187ad6360b6b013b8b",
"containerInfo": {
"id": "8489205e28c9781472e99c3921a6240de3894a3603ed9e187ad6360b6b013b8b",
"ip": "172.17.0.4"
},
"id": "1345506093dfed8dbcef610da476911a228ca315978e5464ae49fb1142bbc49b",
"screen": "1280x1024x24",
"vnc": true
}
]
}
}
},
"firefox": {
"59.0": {},
"63.0": {},
"64.0": {},
"latest": {}
},
"internet explorer": {
"11": {}
},
"opera": {
"56.0": {},
"latest": {}
},
"safari": {
"latest": {}
}
},
"pending": 0,
"queued": 0,
"total": 30,
"used": 1
}
:return boolean (although in case of error in the request will be returned None)
"""
server_url_splitted = self.server_url.split(":")
host_url = "{}:{}:{}:{}/status".format(server_url_splitted[0], server_url_splitted[1], server_url_splitted[2], STATUS_PORT)
server_url_splitted = self.server_url.split(':')
host_url = '{}:{}:{}:{}/status'.format(server_url_splitted[0], server_url_splitted[1], server_url_splitted[2],
STATUS_PORT)

try:
response = requests.get(host_url).json()["browsers"][self.browser]
response = requests.get(host_url).json()['browsers'][self.browser]
except Exception as e:
self.driver_wrapper.logger.warn("the GGR status request has failed: \nResponse: %s \nError message: %s\n" % (response.content, e))
self.driver_wrapper.logger.warn('the GGR status request has failed: \nResponse: %s \n'
'Error message: %s\n' % (response.content, e))
return None
for browser in response:
if response[browser] != {}:
sessions = response[browser][server_url_splitted[1].split("@")[0].replace("//", "")]["sessions"]
sessions = response[browser][server_url_splitted[1].split('@')[0].replace('//', '')]['sessions']
for session in sessions:
if session["id"] == self.session_id:
if session['id'] == self.session_id:
return True
return False

Expand Down
1 change: 0 additions & 1 deletion toolium/test/pageelements/test_derived_page_element.py
Expand Up @@ -77,7 +77,6 @@ def driver_wrapper():
driver_wrapper.driver = mock.MagicMock()
driver_wrapper.is_mobile_test = mock.MagicMock(return_value=False)


return driver_wrapper


Expand Down
4 changes: 2 additions & 2 deletions toolium/test/pageelements/test_page_element.py
Expand Up @@ -459,8 +459,8 @@ def test_android_automatic_context_selection_already_in_desired_webview_context_
driver_wrapper.driver.context = "WEBVIEW_test.package.fake"
driver_wrapper.driver.current_window_handle = "CWindow-1234567890"
driver_wrapper.driver.execute_script.return_value = [{'webviewName': 'WEBVIEW_test.package.fake',
'pages': [{'id': '1234567890',
'id': '0987654321'}]}]
'pages': [{'id': '1234567890'},
{'id': '0987654321'}]}]
RegisterPageObject(driver_wrapper).element_webview.web_element
driver_wrapper.driver.switch_to.context.assert_not_called
driver_wrapper.driver.switch_to.window.assert_not_called
Expand Down
16 changes: 10 additions & 6 deletions toolium/test/test_jira.py
Expand Up @@ -53,7 +53,7 @@ def logger():

def test_change_jira_status(logger):
# Test response
response = b"The Test Case Execution 'TOOLIUM-2' has been created\r\n"
response = b"The Test Case Execution 'TOOLIUM-11' has been created\r\n"

# Configure jira module
jira.enabled = True
Expand All @@ -80,12 +80,12 @@ def test_change_jira_status(logger):
assert partial_url in req_mock.request_history[0].text

# Check logging call
logger.debug.assert_called_once_with("%s", "The Test Case Execution 'TOOLIUM-2' has been created")
logger.debug.assert_called_once_with("%s", "The Test Case Execution 'TOOLIUM-11' has been created")


def test_change_jira_status_attachments(logger):
# Test response
response = b"The Test Case Execution 'TOOLIUM-2' has been created\r\n"
response = b"The Test Case Execution 'TOOLIUM-11' has been created\r\n"

# Configure jira module
jira.enabled = True
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_change_jira_status_attachments(logger):
assert partial_url in body

# Check logging call
logger.debug.assert_called_once_with("%s", "The Test Case Execution 'TOOLIUM-2' has been created")
logger.debug.assert_called_once_with("%s", "The Test Case Execution 'TOOLIUM-11' has been created")


@mock.patch('toolium.jira.requests.get')
Expand Down Expand Up @@ -207,12 +207,12 @@ def test_jira_annotation_multiple(logger):
MockTestClass().mock_test_pass()
with pytest.raises(AssertionError):
MockTestClass().mock_test_fail()
MockTestClass().mock_test_pass()
MockTestClass().mock_test_pass_2()

# Check jira status
expected_status = {'TOOLIUM-1': ('TOOLIUM-1', 'Pass', None, []),
'TOOLIUM-3': ('TOOLIUM-3', 'Fail', "The test 'test name' has failed: test error", []),
'TOOLIUM-1': ('TOOLIUM-1', 'Pass', None, [])}
'TOOLIUM-2': ('TOOLIUM-2', 'Pass', None, [])}
assert expected_status == jira.jira_tests_status


Expand Down Expand Up @@ -241,6 +241,10 @@ def get_method_name(self):
def mock_test_pass(self):
pass

@jira.jira(test_key='TOOLIUM-2')
def mock_test_pass_2(self):
pass

@jira.jira(test_key='TOOLIUM-3')
def mock_test_fail(self):
raise AssertionError('test error')

0 comments on commit 1bb82b4

Please sign in to comment.