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

View File

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