def test_link_gedcom_does_nothing_if_no_project_set(monkeypatch, qtbot): """ If the project is None, no gedcom link should be done """ # Given manager = ProjectFileManager() monkeypatch.delattr(QFileDialog, "getOpenFileName") # when with qtbot.assertNotEmitted(manager.project_changed): manager.link_gedcom_file() # Then assert manager.project is None
def test_link_gedcom_does_nothing_on_cancel(monkeypatch, qtbot): """ When the fileopen dialog is cancelled, the gedcom path is not changed """ # Given manager = ProjectFileManager() manager.project = ResearchProject("") monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda _, __, ___, ____: ("", False)) # When with qtbot.assertNotEmitted(manager.project_changed): manager.link_gedcom_file() # Then assert manager.project.gedcom == ""
def test_link_gedcom_sets_selected_link(monkeypatch, qtbot): """ When a new link is selected it should be set on the project """ # Given manager = ProjectFileManager() manager.project = ResearchProject("") file_name = "Foo" monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda _, __, ___, ____: (file_name, True)) # When with qtbot.waitSignals([manager.project_changed]): manager.link_gedcom_file() # Then assert manager.project.gedcom == file_name assert manager.needs_saving is True
def test_link_gedcom_discard_cancel_stops(monkeypatch, qtbot): """ When a link already exists, ask the user to overwrite it and stop on cancel """ # Given manager = ProjectFileManager() manager.project = ResearchProject("") manager.project.gedcom = "Foo" monkeypatch.delattr(QFileDialog, "getOpenFileName") monkeypatch.setattr(manager.gedcom_discard, "exec_", lambda: QMessageBox.Cancel) # when with qtbot.assertNotEmitted(manager.project_changed): manager.link_gedcom_file() # Then assert manager.project.gedcom == "Foo"
def test_link_gedcom_discard_ok_proceeds(monkeypatch, qtbot): """ When a link already exists, ask the user to overwrite it and continue on ok """ # Given manager = ProjectFileManager() manager.project = ResearchProject("") manager.project.gedcom = "Bar" file_name = "Foo" monkeypatch.setattr(manager.gedcom_discard, "exec_", lambda: QMessageBox.Ok) monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda _, __, ___, ____: (file_name, True)) # When with qtbot.waitSignals([manager.project_changed]): manager.link_gedcom_file() # Then assert manager.project.gedcom == file_name assert manager.needs_saving is True