Extract get_ui_download_url

This commit is contained in:
Matthias 2021-01-10 14:46:59 +01:00
parent 87ed2d7502
commit a1a35115ad
2 changed files with 18 additions and 9 deletions

View File

@ -170,12 +170,7 @@ def download_and_install_ui(dest_folder: Path, dl_url: str):
destfile.write_bytes(x.read())
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.
clean_ui_subdir(dest_folder)
def get_ui_download_url() -> str:
base_url = 'https://api.github.com/repos/freqtrade/frequi/'
# Get base UI Repo path
@ -188,6 +183,16 @@ def start_install_ui(args: Dict[str, Any]) -> None:
r = resp.json()
dl_url = r[0]['browser_download_url']
return dl_url
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.
clean_ui_subdir(dest_folder)
dl_url = get_ui_download_url()
# Download a new version
download_and_install_ui(dest_folder, dl_url)

View File

@ -560,13 +560,14 @@ def test_start_new_hyperopt_no_arg(mocker):
def test_start_install_ui(mocker):
clean_mock = mocker.patch('freqtrade.commands.deploy_commands.clean_ui_subdir')
get_url_mock = mocker.patch('freqtrade.commands.deploy_commands.get_ui_download_url')
download_mock = mocker.patch('freqtrade.commands.deploy_commands.download_and_install_ui')
args = [
"install-ui",
]
start_install_ui(args)
assert clean_mock.call_count == 1
assert get_url_mock.call_count == 1
assert download_mock.call_count == 1
@ -588,7 +589,7 @@ def test_clean_ui_subdir(mocker, tmpdir, caplog):
def test_download_and_install_ui(mocker, tmpdir, caplog):
# Should be something "zip-like"
# Create zipfile
requests_mock = MagicMock()
file_like_object = BytesIO()
with ZipFile(file_like_object, mode='w') as zipfile:
@ -596,13 +597,16 @@ def test_download_and_install_ui(mocker, tmpdir, caplog):
zipfile.writestr(file, file)
file_like_object.seek(0)
requests_mock.content = file_like_object.read()
mocker.patch("freqtrade.commands.deploy_commands.requests.get", return_value=requests_mock)
mocker.patch("freqtrade.commands.deploy_commands.Path.is_dir",
side_effect=[True, False])
mkdir_mock = mocker.patch("freqtrade.commands.deploy_commands.Path.mkdir")
wb_mock = mocker.patch("freqtrade.commands.deploy_commands.Path.write_bytes")
folder = Path(tmpdir) / "uitests_dl"
download_and_install_ui(folder, 'http://whatever.xxx')
download_and_install_ui(folder, 'http://whatever.xxx/download/file.zip')
assert mkdir_mock.call_count == 1
assert wb_mock.call_count == 2