Add a "Check for Updates" dialog (#863)
* Add basic dialog for Updates check * Add GitHub API call and processing * Finalise the update dialog * Improve test coverage
This commit is contained in:
committed by
GitHub
parent
80911af4d2
commit
b5e52b80a3
@@ -22,9 +22,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QItemSelectionModel
|
||||
from PyQt5.QtWidgets import QListWidgetItem, QDialog, QMessageBox
|
||||
from PyQt5.QtWidgets import QAction, QListWidgetItem, QDialog, QMessageBox
|
||||
|
||||
from nw.dialogs import GuiQuoteSelect
|
||||
from nw.dialogs import GuiQuoteSelect, GuiUpdates
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
@@ -32,7 +32,7 @@ stepDelay = 20
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testDlgOther_QuoteSelect(monkeypatch, nwGUI):
|
||||
def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
|
||||
"""Test the quote symbols dialog.
|
||||
"""
|
||||
# Block message box
|
||||
@@ -59,3 +59,45 @@ def testDlgOther_QuoteSelect(monkeypatch, nwGUI):
|
||||
nwQuot.close()
|
||||
|
||||
# END Test testDlgOther_QuoteSelect
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testDlgOther_Updates(qtbot, monkeypatch, nwGUI):
|
||||
"""Test the check for updates dialog.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
nwUpdate = GuiUpdates(nwGUI)
|
||||
nwUpdate.show()
|
||||
|
||||
class mockData:
|
||||
def decode(self):
|
||||
return '{"tag_name": "v1.0", "created_at": "2021-01-01T12:00:00Z"}'
|
||||
|
||||
class mockPayload:
|
||||
def read(self):
|
||||
return mockData()
|
||||
|
||||
def mockUrlopenA(*a, **k):
|
||||
return None
|
||||
|
||||
def mockUrlopenB(*a, **k):
|
||||
return mockPayload()
|
||||
|
||||
# Faulty Return
|
||||
monkeypatch.setattr("nw.dialogs.updates.urlopen", mockUrlopenA)
|
||||
nwUpdate.checkLatest()
|
||||
|
||||
# Valid Return
|
||||
monkeypatch.setattr("nw.dialogs.updates.urlopen", mockUrlopenB)
|
||||
nwUpdate.checkLatest()
|
||||
assert nwUpdate.latestValue.text().startswith("novelWriter v1.0")
|
||||
|
||||
# Trigger from Menu
|
||||
nwGUI.mainMenu.aUpdates.activate(QAction.Trigger)
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
nwUpdate._doClose()
|
||||
|
||||
# END Test testDlgOther_Updates
|
||||
|
||||
@@ -379,7 +379,7 @@ def testGuiMenu_ContextMenus(qtbot, monkeypatch, nwGUI, nwLipsum):
|
||||
"""Test the context menus.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
nwGUI.theProject.projTree.setSeed(42)
|
||||
assert nwGUI.openProject(nwLipsum)
|
||||
@@ -637,7 +637,7 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
# Faulty Keyword Inserts
|
||||
assert not nwGUI.docEditor.insertKeyWord("blabla")
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QTextBlock, "isValid", lambda *args, **kwards: False)
|
||||
mp.setattr(QTextBlock, "isValid", lambda *a, **k: False)
|
||||
assert not nwGUI.docEditor.insertKeyWord(nwKeyWords.TAG_KEY)
|
||||
|
||||
nwGUI.docEditor.clear()
|
||||
@@ -667,16 +667,16 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
nwGUI.closeDocument()
|
||||
|
||||
# First, with no path
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: ("", ""))
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *a, **k: ("", ""))
|
||||
assert not nwGUI.importDocument()
|
||||
|
||||
# Then with a path, but an invalid one
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: (" ", ""))
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *a, **k: (" ", ""))
|
||||
assert not nwGUI.importDocument()
|
||||
|
||||
# Then a valid path, but bot a file that exists
|
||||
theFile = os.path.join(fncDir, "import.txt")
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: (theFile, ""))
|
||||
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *a, **k: (theFile, ""))
|
||||
assert not nwGUI.importDocument()
|
||||
|
||||
# Create the file and try again, but with no target document open
|
||||
@@ -689,12 +689,12 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
assert nwGUI.docEditor.getText() == "Bar"
|
||||
|
||||
# The document isn't empty, so the message box should pop
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args, **kwargs: QMessageBox.No)
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a, **k: QMessageBox.No)
|
||||
assert not nwGUI.importDocument()
|
||||
assert nwGUI.docEditor.getText() == "Bar"
|
||||
|
||||
# Finally, accept the replaced text, this time we use the menu entry to trigger it
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args, **kwargs: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a, **k: QMessageBox.Yes)
|
||||
nwGUI.mainMenu.aImportFile.activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Foo"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user