Update saucelabs endpoint

Signed-off-by: Serhy <sergii@status.im>
This commit is contained in:
Serhy 2021-01-11 19:17:40 +02:00
parent 346ff25843
commit d68f7679df
No known key found for this signature in database
GPG Key ID: 5D7C4B9E2B6F500B
4 changed files with 58 additions and 21 deletions

View File

@ -39,8 +39,8 @@ PyYAML==5.3.1
repoze.lru==0.7
requests==2.25.0
rlp==1.2.0
sauceclient==1.0.0
scrypt==0.8.17
sauceclient==1.0.0
selenium==3.14.1
six==1.10.0
urllib3==1.25.9

View File

@ -30,7 +30,7 @@ class AbstractTestCase:
@property
def executor_sauce_lab(self):
return 'http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (self.sauce_username, self.sauce_access_key)
return 'https://%s:%s@ondemand.eu-central-1.saucelabs.com:443/wd/hub' % (self.sauce_username, self.sauce_access_key)
@property
def executor_local(self):
@ -59,7 +59,6 @@ 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'

View File

@ -0,0 +1,48 @@
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'})

View File

@ -8,19 +8,16 @@ 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 io import BytesIO
from sauceclient import SauceClient, SauceException
from sauceclient import SauceException
import tests.cloudbase_test_api
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()
@ -141,7 +138,7 @@ def is_master(config):
def is_uploaded():
stored_files = sauce.storage.get_stored_files()
stored_files = tests.cloudbase_test_api.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
@ -173,18 +170,11 @@ def pytest_configure(config):
description='e2e tests are running')
if config.getoption('env') == 'sauce':
if not is_uploaded():
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'})
apk = config.getoption('apk')
if 'http' in apk:
tests.cloudbase_test_api.upload_from_url(apk)
else:
sauce.storage.upload_file(config.getoption('apk'))
tests.cloudbase_test_api.sauce.storage.upload_file(apk)
def pytest_unconfigure(config):
@ -253,7 +243,7 @@ def pytest_runtest_makereport(item, call):
def update_sauce_jobs(test_name, job_ids, passed):
for job_id in job_ids.keys():
try:
sauce.jobs.update_job(job_id, name=test_name, passed=passed)
tests.cloudbase_test_api.sauce.jobs.update_job(job_id, name=test_name, passed=passed)
except (RemoteDisconnected, SauceException):
pass