From e4d175ef9393a747073aa4c0fa943180b56c77e9 Mon Sep 17 00:00:00 2001 From: Serhy Date: Wed, 13 Jan 2021 12:14:32 +0200 Subject: [PATCH] Revert 11624 Signed-off-by: Serhy --- test/appium/requirements.txt | 2 +- test/appium/support/testrail_report.py | 3 +- test/appium/tests/base_test_case.py | 3 +- test/appium/tests/cloudbase_test_api.py | 48 ------------------------- test/appium/tests/conftest.py | 26 +++++++++----- 5 files changed, 23 insertions(+), 59 deletions(-) delete mode 100644 test/appium/tests/cloudbase_test_api.py diff --git a/test/appium/requirements.txt b/test/appium/requirements.txt index 47317fbfba..3a811a2b27 100644 --- a/test/appium/requirements.txt +++ b/test/appium/requirements.txt @@ -39,8 +39,8 @@ PyYAML==5.3.1 repoze.lru==0.7 requests==2.25.0 rlp==1.2.0 -scrypt==0.8.17 sauceclient==1.0.0 +scrypt==0.8.17 selenium==3.14.1 six==1.10.0 urllib3==1.25.9 diff --git a/test/appium/support/testrail_report.py b/test/appium/support/testrail_report.py index f1c802ec1c..30d9fadaf4 100644 --- a/test/appium/support/testrail_report.py +++ b/test/appium/support/testrail_report.py @@ -121,6 +121,7 @@ class TestrailReport(BaseTestReport): tests = self.get_all_tests() passed_tests = self.get_passed_tests() failed_tests = self.get_failed_tests() + final_description = "Nothing to report this time..." if len(tests) > 0: description_title = "# %.0f%% of end-end tests have passed\n" % (len(passed_tests) / len(tests) * 100) description_title += "\n" @@ -129,7 +130,7 @@ class TestrailReport(BaseTestReport): description_title += "Passed tests: %d\n" % len(passed_tests) description_title += "\n" ids_failed_test = [] - description = '' + description, case_info = '', '' if failed_tests: for i, test in enumerate(failed_tests): last_testrun = test.testruns[-1] diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 0f4581e861..fc5f1a1a4e 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -30,7 +30,7 @@ class AbstractTestCase: @property def executor_sauce_lab(self): - return 'https://%s:%s@ondemand.eu-central-1.saucelabs.com:443/wd/hub' % (self.sauce_username, self.sauce_access_key) + return 'http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (self.sauce_username, self.sauce_access_key) @property def executor_local(self): @@ -59,6 +59,7 @@ class AbstractTestCase: def capabilities_sauce_lab(self): desired_caps = dict() desired_caps['app'] = 'sauce-storage:' + test_suite_data.apk_name + desired_caps['build'] = pytest_config_global['build'] desired_caps['name'] = test_suite_data.current_test.name desired_caps['platformName'] = 'Android' diff --git a/test/appium/tests/cloudbase_test_api.py b/test/appium/tests/cloudbase_test_api.py deleted file mode 100644 index 23bef31ab4..0000000000 --- a/test/appium/tests/cloudbase_test_api.py +++ /dev/null @@ -1,48 +0,0 @@ -from os import environ -import json -import requests -from io import BytesIO - -from sauceclient import SauceClient, SauceException - -try: - import http.client as http_client - from urllib.parse import urlencode -except ImportError: - import httplib as http_client - from urllib import urlencode - - -sauce_username = environ.get('SAUCE_USERNAME') -sauce_access_key = environ.get('SAUCE_ACCESS_KEY') - -sauce = SauceClient(sauce_username, sauce_access_key) -apibase = 'eu-central-1.saucelabs.com' - - -def request(method, url, body=None, content_type='application/json'): - """This is to monkey patch further this method in order to use apibase""" - headers = sauce.make_auth_headers(content_type) - connection = http_client.HTTPSConnection(apibase) - connection.request(method, url, body, headers=headers) - response = connection.getresponse() - data = response.read() - connection.close() - if response.status not in [200, 201]: - raise SauceException('{}: {}.\nSauce Status NOT OK'.format( - response.status, response.reason), response=response) - return json.loads(data.decode('utf-8')) - -sauce.request = request - -def upload_from_url(apk_path = str()): - response = requests.get(apk_path, stream=True) - response.raise_for_status() - apk_name = apk_path.split("/")[-1] - file = BytesIO(response.content) - del response - requests.post('https://eu-central-1.saucelabs.com/rest/v1/storage/' - + sauce_username + '/' + apk_name + '?overwrite=true', - auth=(sauce_username, sauce_access_key), - data=file, - headers={'Content-Type': 'application/octet-stream'}) diff --git a/test/appium/tests/conftest.py b/test/appium/tests/conftest.py index fc97aa342b..6d3a60681c 100644 --- a/test/appium/tests/conftest.py +++ b/test/appium/tests/conftest.py @@ -8,16 +8,19 @@ from support.test_rerun import should_rerun_test from tests import test_suite_data, appium_container from datetime import datetime from os import environ -from sauceclient import SauceException -import tests.cloudbase_test_api +from io import BytesIO +from sauceclient import SauceClient, SauceException from support.api.network_api import NetworkApi from support.github_report import GithubHtmlReport from support.testrail_report import TestrailReport from tests.users import transaction_senders import tests +sauce_username = environ.get('SAUCE_USERNAME') +sauce_access_key = environ.get('SAUCE_ACCESS_KEY') github_token = environ.get('GIT_HUB_TOKEN') +sauce = SauceClient(sauce_username, sauce_access_key) github_report = GithubHtmlReport() testrail_report = TestrailReport() @@ -138,7 +141,7 @@ def is_master(config): def is_uploaded(): - stored_files = tests.cloudbase_test_api.sauce.storage.get_stored_files() + stored_files = sauce.storage.get_stored_files() for i in range(len(stored_files['files'])): if stored_files['files'][i]['name'] == test_suite_data.apk_name: return True @@ -170,11 +173,18 @@ def pytest_configure(config): description='e2e tests are running') if config.getoption('env') == 'sauce': if not is_uploaded(): - apk = config.getoption('apk') - if 'http' in apk: - tests.cloudbase_test_api.upload_from_url(apk) + if 'http' in config.getoption('apk'): + response = requests.get(config.getoption('apk'), stream=True) + response.raise_for_status() + file = BytesIO(response.content) + del response + requests.post('http://saucelabs.com/rest/v1/storage/' + + sauce_username + '/' + test_suite_data.apk_name + '?overwrite=true', + auth=(sauce_username, sauce_access_key), + data=file, + headers={'Content-Type': 'application/octet-stream'}) else: - tests.cloudbase_test_api.sauce.storage.upload_file(apk) + sauce.storage.upload_file(config.getoption('apk')) def pytest_unconfigure(config): @@ -243,7 +253,7 @@ def pytest_runtest_makereport(item, call): def update_sauce_jobs(test_name, job_ids, passed): for job_id in job_ids.keys(): try: - tests.cloudbase_test_api.sauce.jobs.update_job(job_id, name=test_name, passed=passed) + sauce.jobs.update_job(job_id, name=test_name, passed=passed) except (RemoteDisconnected, SauceException): pass