Adapt tests and rest_client to basic_auth

This commit is contained in:
Matthias 2019-05-25 14:25:36 +02:00
parent 2da7145132
commit febcc3dddc
2 changed files with 5 additions and 19 deletions

View File

@ -7,6 +7,7 @@ from unittest.mock import ANY, MagicMock, PropertyMock
import pytest import pytest
from flask import Flask from flask import Flask
from requests.auth import _basic_auth_str
from freqtrade.__init__ import __version__ from freqtrade.__init__ import __version__
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
@ -37,18 +38,14 @@ def botclient(default_conf, mocker):
def client_post(client, url, data={}): def client_post(client, url, data={}):
headers = {"username": _TEST_USER,
"password": _TEST_PASS}
return client.post(url, return client.post(url,
content_type="application/json", content_type="application/json",
data=data, data=data,
headers=headers) headers={'Authorization': _basic_auth_str(_TEST_USER, _TEST_PASS)})
def client_get(client, url): def client_get(client, url):
headers = {"username": _TEST_USER, return client.get(url, headers={'Authorization': _basic_auth_str(_TEST_USER, _TEST_PASS)})
"password": _TEST_PASS}
return client.get(url, headers=headers)
def assert_response(response, expected_code=200): def assert_response(response, expected_code=200):
@ -95,8 +92,6 @@ def test_api_unauthorized(botclient):
assert rc.json == {'error': 'Unauthorized'} assert rc.json == {'error': 'Unauthorized'}
def test_api_stop_workflow(botclient): def test_api_stop_workflow(botclient):
ftbot, client = botclient ftbot, client = botclient
assert ftbot.state == State.RUNNING assert ftbot.state == State.RUNNING

View File

@ -30,8 +30,7 @@ class FtRestClient():
self._serverurl = serverurl self._serverurl = serverurl
self._session = requests.Session() self._session = requests.Session()
self._username = username self._session.auth = (username, password)
self._password = password
def _call(self, method, apipath, params: dict = None, data=None, files=None): def _call(self, method, apipath, params: dict = None, data=None, files=None):
@ -43,12 +42,6 @@ class FtRestClient():
"Content-Type": "application/json" "Content-Type": "application/json"
} }
if self._username:
hd.update({"username": self._username})
if self._password:
hd.update({"password": self._password})
# Split url # Split url
schema, netloc, path, par, query, fragment = urlparse(basepath) schema, netloc, path, par, query, fragment = urlparse(basepath)
# URLEncode query string # URLEncode query string
@ -57,9 +50,7 @@ class FtRestClient():
url = urlunparse((schema, netloc, path, par, query, fragment)) url = urlunparse((schema, netloc, path, par, query, fragment))
try: try:
resp = self._session.request(method, url, headers=hd, data=json.dumps(data), resp = self._session.request(method, url, headers=hd, data=json.dumps(data))
# auth=self.session.auth
)
# return resp.text # return resp.text
return resp.json() return resp.json()
except ConnectionError: except ConnectionError: