maestral/tests/offline/test_main.py

49 lines
1.3 KiB
Python
Raw Normal View History

2022-02-18 01:23:04 +03:00
import pytest
2021-03-22 15:40:27 +03:00
import requests
import maestral.main
2022-03-11 20:35:41 +03:00
from maestral.main import Maestral
2021-03-22 15:40:27 +03:00
from maestral.constants import GITHUB_RELEASES_API
2022-02-18 01:23:04 +03:00
from maestral.exceptions import NotLinkedError
2021-03-22 15:40:27 +03:00
2022-03-11 20:35:41 +03:00
def test_check_for_updates(m: Maestral) -> None:
2021-03-22 15:40:27 +03:00
# get current releases from GitHub
resp = requests.get(GITHUB_RELEASES_API)
try:
resp.raise_for_status()
except Exception:
# rate limit etc, connection error, etc
return
data = resp.json()
previous_release = data[1]["tag_name"].lstrip("v")
latest_stable_release = data[0]["tag_name"].lstrip("v")
# check that no update is offered from current (newest) version
maestral.main.__version__ = latest_stable_release
update_res = m.check_for_updates()
2022-03-16 01:31:07 +03:00
assert update_res.latest_release == latest_stable_release
assert not update_res.update_available
assert update_res.release_notes == ""
2021-03-22 15:40:27 +03:00
# check that update is offered from previous release
maestral.main.__version__ = previous_release
update_res = m.check_for_updates()
2022-03-16 01:31:07 +03:00
assert update_res.latest_release == latest_stable_release
assert update_res.update_available
assert update_res.release_notes != ""
2022-02-18 01:23:04 +03:00
2022-03-11 20:35:41 +03:00
def test_not_linked_error(m: Maestral) -> None:
2022-02-18 01:23:04 +03:00
with pytest.raises(NotLinkedError):
m.get_metadata("/test")