Improve jsonification
This commit is contained in:
parent
557f849519
commit
a146c5bf78
@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
from datetime import datetime, date
|
||||||
from ipaddress import IPv4Address
|
from ipaddress import IPv4Address
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
@ -18,6 +19,10 @@ class ArrowJSONEncoder(JSONEncoder):
|
|||||||
try:
|
try:
|
||||||
if isinstance(obj, Arrow):
|
if isinstance(obj, Arrow):
|
||||||
return obj.for_json()
|
return obj.for_json()
|
||||||
|
elif isinstance(obj, date):
|
||||||
|
return obj.strftime("%Y-%m-%d")
|
||||||
|
elif isinstance(obj, datetime):
|
||||||
|
return obj.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
iterable = iter(obj)
|
iterable = iter(obj)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
Unit test file for rpc/api_server.py
|
Unit test file for rpc/api_server.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from unittest.mock import MagicMock, PropertyMock
|
from unittest.mock import MagicMock, PropertyMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -9,12 +10,13 @@ import pytest
|
|||||||
from freqtrade.__init__ import __version__
|
from freqtrade.__init__ import __version__
|
||||||
from freqtrade.rpc.api_server import ApiServer
|
from freqtrade.rpc.api_server import ApiServer
|
||||||
from freqtrade.state import State
|
from freqtrade.state import State
|
||||||
from freqtrade.tests.conftest import get_patched_freqtradebot, patch_apiserver, patch_get_signal
|
from freqtrade.tests.conftest import (get_patched_freqtradebot,
|
||||||
|
patch_apiserver, patch_get_signal)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def botclient(default_conf, mocker):
|
def botclient(default_conf, mocker):
|
||||||
default_conf.update({"api_server":{"enabled": True,
|
default_conf.update({"api_server": {"enabled": True,
|
||||||
"listen_ip_address": "127.0.0.1",
|
"listen_ip_address": "127.0.0.1",
|
||||||
"listen_port": "8080"}})
|
"listen_port": "8080"}})
|
||||||
ftbot = get_patched_freqtradebot(mocker, default_conf)
|
ftbot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
@ -163,3 +165,19 @@ def test_api_count(botclient, mocker, ticker, fee, markets):
|
|||||||
response_success_assert(rc)
|
response_success_assert(rc)
|
||||||
assert rc.json["current"] == 1.0
|
assert rc.json["current"] == 1.0
|
||||||
assert rc.json["max"] == 1.0
|
assert rc.json["max"] == 1.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_daily(botclient, mocker, ticker, fee, markets):
|
||||||
|
ftbot, client = botclient
|
||||||
|
patch_get_signal(ftbot, (True, False))
|
||||||
|
mocker.patch.multiple(
|
||||||
|
'freqtrade.exchange.Exchange',
|
||||||
|
get_balances=MagicMock(return_value=ticker),
|
||||||
|
get_ticker=ticker,
|
||||||
|
get_fee=fee,
|
||||||
|
markets=PropertyMock(return_value=markets)
|
||||||
|
)
|
||||||
|
rc = client.get("/daily")
|
||||||
|
response_success_assert(rc)
|
||||||
|
assert len(rc.json) == 7
|
||||||
|
assert rc.json[0][0] == str(datetime.utcnow().date())
|
||||||
|
Loading…
Reference in New Issue
Block a user