Extract last FreqUI version from api response
This commit is contained in:
parent
1df0aa8751
commit
2af1d2d639
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
import requests
|
||||
|
||||
@ -170,7 +170,7 @@ def download_and_install_ui(dest_folder: Path, dl_url: str):
|
||||
destfile.write_bytes(x.read())
|
||||
|
||||
|
||||
def get_ui_download_url() -> str:
|
||||
def get_ui_download_url() -> Tuple[str, str]:
|
||||
base_url = 'https://api.github.com/repos/freqtrade/frequi/'
|
||||
# Get base UI Repo path
|
||||
|
||||
@ -178,23 +178,31 @@ def get_ui_download_url() -> str:
|
||||
resp.raise_for_status()
|
||||
r = resp.json()
|
||||
|
||||
assets = r[0]['assets_url']
|
||||
resp = requests.get(assets)
|
||||
r = resp.json()
|
||||
latest_version = r[0]['name']
|
||||
assets = r[0].get('assets', [])
|
||||
dl_url = ''
|
||||
if assets and len(assets) > 0:
|
||||
dl_url = assets[0]['browser_download_url']
|
||||
|
||||
dl_url = r[0]['browser_download_url']
|
||||
return dl_url
|
||||
# URL not found - try assets url
|
||||
if not dl_url:
|
||||
assets = r[0]['assets_url']
|
||||
resp = requests.get(assets)
|
||||
r = resp.json()
|
||||
dl_url = r[0]['browser_download_url']
|
||||
|
||||
return dl_url, latest_version
|
||||
|
||||
|
||||
def start_install_ui(args: Dict[str, Any]) -> None:
|
||||
|
||||
dest_folder = Path(__file__).parents[1] / 'rpc/api_server/ui'
|
||||
# First make sure the assets are removed.
|
||||
dl_url, latest_version = get_ui_download_url()
|
||||
clean_ui_subdir(dest_folder)
|
||||
if args.get('erase_ui_only'):
|
||||
logger.info("Erased UI directory content. Not downloading new version.")
|
||||
else:
|
||||
dl_url = get_ui_download_url()
|
||||
|
||||
# Download a new version
|
||||
download_and_install_ui(dest_folder, dl_url)
|
||||
|
@ -1,5 +1,5 @@
|
||||
from io import BytesIO
|
||||
import re
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, PropertyMock
|
||||
from zipfile import ZipFile
|
||||
@ -13,7 +13,8 @@ from freqtrade.commands import (start_convert_data, start_create_userdir, start_
|
||||
start_list_markets, start_list_strategies, start_list_timeframes,
|
||||
start_new_hyperopt, start_new_strategy, start_show_trades,
|
||||
start_test_pairlist, start_trading)
|
||||
from freqtrade.commands.deploy_commands import clean_ui_subdir, download_and_install_ui, get_ui_download_url
|
||||
from freqtrade.commands.deploy_commands import (clean_ui_subdir, download_and_install_ui,
|
||||
get_ui_download_url)
|
||||
from freqtrade.configuration import setup_utils_configuration
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.state import RunMode
|
||||
@ -628,15 +629,31 @@ def test_download_and_install_ui(mocker, tmpdir):
|
||||
def test_get_ui_download_url(mocker):
|
||||
response = MagicMock()
|
||||
response.json = MagicMock(
|
||||
side_effect=[[{'assets_url': 'http://whatever.json'}],
|
||||
side_effect=[[{'assets_url': 'http://whatever.json', 'name': '0.0.1'}],
|
||||
[{'browser_download_url': 'http://download.zip'}]])
|
||||
get_mock = mocker.patch("freqtrade.commands.deploy_commands.requests.get",
|
||||
return_value=response)
|
||||
x = get_ui_download_url()
|
||||
x, last_version = get_ui_download_url()
|
||||
assert get_mock.call_count == 2
|
||||
assert last_version == '0.0.1'
|
||||
assert x == 'http://download.zip'
|
||||
|
||||
|
||||
def test_get_ui_download_url_direct(mocker):
|
||||
response = MagicMock()
|
||||
response.json = MagicMock(
|
||||
side_effect=[[{
|
||||
'assets_url': 'http://whatever.json',
|
||||
'name': '0.0.1',
|
||||
'assets': [{'browser_download_url': 'http://download11.zip'}]}]])
|
||||
get_mock = mocker.patch("freqtrade.commands.deploy_commands.requests.get",
|
||||
return_value=response)
|
||||
x, last_version = get_ui_download_url()
|
||||
assert get_mock.call_count == 1
|
||||
assert last_version == '0.0.1'
|
||||
assert x == 'http://download11.zip'
|
||||
|
||||
|
||||
def test_download_data_keyboardInterrupt(mocker, caplog, markets):
|
||||
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
||||
MagicMock(side_effect=KeyboardInterrupt))
|
||||
|
Loading…
Reference in New Issue
Block a user