Repository navigation
Expand file tree
/
Copy pathtest_dingo_updates.py
More file actions
66 lines (59 loc) · 3.28 KB
/
Copy pathtest_dingo_updates.py
File metadata and controls
66 lines (59 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from io import BytesIO
import json
from pathlib import Path
from tempfile import TemporaryDirectory
import time
import unittest
from unittest.mock import patch
from PyQt6 import QtCore, QtWidgets
from desktop_wallet import Wallet
from dingo_qt import MainWindow
from dingo_updates import API_URL, available_release, check_latest
from dingo_wallet import create_phrase
def release(tag, **fields):
return {"tag_name": tag, "draft": False, "prerelease": False, **fields}
class UpdateTests(unittest.TestCase):
def test_stable_versions_only(self):
for tag in ("v0.1.0", "v0.1.1", "v0.1.2-beta", "v0.1.2/../../elsewhere", None):
self.assertIsNone(available_release(release(tag), "0.1.1"))
for flag in ("draft", "prerelease"):
self.assertIsNone(available_release(release("v1.0.0", **{flag: True}), "0.1.1"))
self.assertEqual(available_release(release("v0.10.0"), "0.9.9"), "v0.10.0")
def test_metadata_request(self):
with patch("dingo_updates.urlopen", return_value=BytesIO(json.dumps(release("v10.0.0")).encode())) as get:
self.assertEqual(check_latest(), "v10.0.0")
self.assertEqual(get.call_args.args[0].full_url, API_URL)
self.assertIsNone(get.call_args.args[0].data)
with patch("dingo_updates.urlopen", return_value=BytesIO(b'{"tag')):
with self.assertRaises(ValueError):
check_latest()
def test_notice_after_open_click_and_retry(self):
app = QtWidgets.QApplication.instance() or QtWidgets.QApplication([])
with TemporaryDirectory() as tmp, patch.object(MainWindow, "refresh"), patch("dingo_qt.external") as open_link:
folder = Path(tmp)
wallet = Wallet.create(folder / "test_wallet", create_phrase(), "temporary")
settings = QtCore.QSettings(str(folder / "test.ini"), QtCore.QSettings.Format.IniFormat)
with patch("dingo_updates.check_latest", side_effect=[OSError("offline"), "v0.1.2", None]):
window = MainWindow(wallet, folder, settings)
try:
window.setAttribute(QtCore.Qt.WidgetAttribute.WA_DontShowOnScreen)
window.show()
for index, interval in enumerate([1, 6, 6]):
if index:
window.update_timer.start(0)
deadline = time.monotonic() + 4
while time.monotonic() < deadline:
app.processEvents()
if window.update_timer.isActive() and window.update_timer.interval() == interval * 3600000:
break
time.sleep(0.01)
else:
self.fail("Release check did not finish")
self.assertEqual(window.update_banner.isVisible(), index == 1)
self.assertFalse(window.busy)
if index == 1:
self.assertIn("Electrum-DINGO 0.1.2", window.update_banner.text())
window.update_banner.click()
open_link.assert_called_once_with("https://github.com/AltForger/Electrum-DINGO/releases/tag/v0.1.2")
finally:
window.close()