Example #1
0
def test_pending_updates_are_cleared():
    """
    If there are any previous pending changes, they are cleared before
    updates are calculated
    """

    # Given
    tree_model = TreeModel()
    tree_model.set_project(ResearchProject(""))

    individuals_model = IndividualsModel([])
    sources_model = SourcesModel([])

    context = DataContext(
        data_model=tree_model,
        individuals_model=individuals_model,
        sources_model=sources_model,
    )
    updater = LinkUpdater(context)
    updater.source_updates = ["Foo", "Bar"]
    updater.ancestor_fixes = ["Baz", "Fiz"]

    # When
    updater.calculate_updates()

    # Then
    assert updater.has_pending_updates() is False
Example #2
0
def test_data_model_is_not_none_by_default():
    """ Check that the data_model is set by default """
    # Given
    context = DataContext()

    # Then
    assert context.data_model is not None
Example #3
0
def test_load_link_filename_cannot_be_empty():
    """ When loading a file, the filename cannot be None """
    # Given
    manager = GedcomManager(DataContext())

    # When
    manager.load_link("")
Example #4
0
def fixture_link_updater():
    """ Fixture to create an updater with uncommitted updates """
    tree_model = TreeModel()
    individuals_model = IndividualsModel([])
    sources_model = SourcesModel([])

    old_value = "Altered Ancestor"
    new_value = "Foo"

    project = ResearchProject("")
    plan_altered = ResearchPlan()
    plan_altered.ancestor = old_value
    plan_altered.ancestor_link = "I001"
    project.plans.append(plan_altered)
    tree_model.set_project(project)

    context = DataContext(
        data_model=tree_model,
        individuals_model=individuals_model,
        sources_model=sources_model,
    )

    updater = LinkUpdater(context)
    plan_index = tree_model.index(0, TreeModelCols.TEXT, QModelIndex())
    updater.ancestor_updates = [{"index": plan_index, "value": new_value}]

    return (updater, old_value, new_value, tree_model, plan_index)
Example #5
0
def test_show_classmethod(monkeypatch):
    """ Check the function does what it says """
    # Given

    monkeypatch.setattr(ProjectOverviewDialog, "exec_", lambda _: None)

    # When
    ProjectOverviewDialog.show(DataContext(), ResearchProject("Foobar"), None)
Example #6
0
def test_task_links_are_checked():
    """
    Check the following:
    * Unchanged links are respected
    * Broken links are identified
    * Updated links are identified
    """

    # Given
    project = ResearchProject("")
    individuals = []
    sources = []

    plan = ResearchPlan()

    source_linked = Source("S123", "Linked", "Author", "Pub", "abbr")
    sources.append(source_linked)
    task_linked = ResearchTask()
    task_linked.source = source_linked.autocomplete_name()
    task_linked.source_link = source_linked.pointer
    plan.tasks.append(task_linked)

    task_broken = ResearchTask()
    task_broken.source = "Broken Source"
    task_broken.source_link = "FooBar"
    plan.tasks.append(task_broken)

    source_altered = Source("S987", "Altered", "Author", "Pub", "abbr")
    sources.append(source_altered)
    task_altered = ResearchTask()
    task_altered.source = "Altered Source"
    task_altered.source_link = source_altered.pointer
    plan.tasks.append(task_altered)

    project.plans.append(plan)

    tree_model = TreeModel()
    tree_model.set_project(project)

    individuals_model = IndividualsModel(individuals)
    sources_model = SourcesModel(sources)

    context = DataContext(
        data_model=tree_model,
        individuals_model=individuals_model,
        sources_model=sources_model,
    )
    updater = LinkUpdater(context)

    # When
    updater.calculate_updates()

    # Then
    assert updater.has_pending_updates() is True
    assert len(updater.ancestor_updates) == 0
    assert len(updater.source_updates) == 1
Example #7
0
def test_dialog_builds(qtbot):
    """ a """
    # Given
    dialog = ProjectOverviewDialog(DataContext(), ResearchProject("Foobar"), None)
    qtbot.add_widget(dialog)

    # When

    # Then
    assert dialog.filename_label.text() == "Foobar"
Example #8
0
def test_detail_change_sets_screen(qtbot):
    """ When changing the selection screen, the blank details screen should be loaded """
    # Given
    screen = MainScreen(None, DataContext())
    qtbot.add_widget(screen)

    # When
    screen.change_detail_screen("blank", QModelIndex())

    # Then
    assert screen.detail_stack.currentWidget() == screen.screens["blank"]
Example #9
0
def test_loading_file_creates_models():
    """ When loading a gedcom file, models should be populated """
    # Given
    manager = GedcomManager(DataContext())

    # When
    manager.load_link("tests/unit/test.ged")

    # Then
    assert manager.data_context.individuals_model.rowCount() != 0
    assert manager.data_context.sources_model.rowCount() != 0
Example #10
0
def test_selection_change_picks_selection_screen(qtbot):
    """ When changing the selection screen, the blank details screen should be loaded """
    # Given
    screen = MainScreen(None, DataContext())
    qtbot.add_widget(screen)

    # When
    screen.change_selection_screen("tree")

    # Then
    assert screen.selection_stack.currentWidget() == screen.screens["tree"]
Example #11
0
def test_ancestor_edit_has_completer(qtbot):
    """ Check that the ancestor edit has a completer """
    # Given
    data_context = DataContext()

    # When
    screen = PlanDetails(data_context)
    qtbot.add_widget(screen)

    # Then
    assert screen.ancestor.completer() is not None
    assert screen.ancestor.completer().model() is not None
Example #12
0
def test_has_pending_updates():
    """ If there are pending updates, this function should return true """
    # Given
    updater = LinkUpdater(DataContext())

    assert updater.has_pending_updates() is False

    # When
    updater.ancestor_updates = ["foo"]

    # Then
    assert updater.has_pending_updates() is True
Example #13
0
def test_source_edit_has_completer(qtbot):
    """ Check that the source edit has a completer """
    # Given
    data_context = DataContext()

    # When
    screen = TaskDetails(data_context)
    qtbot.add_widget(screen)

    # Then
    assert screen.source.completer() is not None
    assert screen.source.completer().model() is not None
Example #14
0
def test_plan_links_are_checked():
    """
    Check the following:
    * Unchanged links are respected
    * Broken links are identified
    * Updated links are identified
    """

    # Given
    project = ResearchProject("")
    individuals = []
    sources = []

    indi_linked = Individual("I1234", "Link", "Indi", 1000, 2000)
    individuals.append(indi_linked)
    plan_linked = ResearchPlan()
    plan_linked.ancestor = indi_linked.autocomplete_name()
    plan_linked.ancestor_link = indi_linked.pointer
    project.plans.append(plan_linked)

    plan_broken = ResearchPlan()
    plan_broken.ancestor = "Broken Ancestor 1234/5678"
    plan_broken.ancestor_link = "FooBar"
    project.plans.append(plan_broken)

    indi_altered = Individual("I9876", "Altered", "Indi", 1000, 2000)
    individuals.append(indi_altered)
    plan_altered = ResearchPlan()
    plan_altered.ancestor = "Altered Ancestor 1000/2000"
    plan_altered.ancestor_link = indi_altered.pointer
    project.plans.append(plan_altered)

    tree_model = TreeModel()
    tree_model.set_project(project)

    individuals_model = IndividualsModel(individuals)
    sources_model = SourcesModel(sources)

    context = DataContext(
        data_model=tree_model,
        individuals_model=individuals_model,
        sources_model=sources_model,
    )
    updater = LinkUpdater(context)

    # When
    updater.calculate_updates()

    # Then
    assert updater.has_pending_updates() is True
    assert len(updater.ancestor_updates) == 1
    assert len(updater.source_updates) == 0
Example #15
0
def test_update_project_updates_screens(qtbot):
    """ When caling update_project, this is passed to the screens """
    # Given
    screen = MainScreen(None, DataContext())
    qtbot.add_widget(screen)
    project = ResearchProject("")
    assert screen.screens["blank"].project is None

    # When
    screen.set_project(project)

    # Then
    assert screen.screens["blank"].project == project
Example #16
0
def test_clear_link_removes_caches():
    """ When the link is removed, the caches should be cleared too """
    # Given
    manager = GedcomManager(DataContext())
    manager.individuals.append(Individual("I000", "Test", "User", 1900, 1999))
    manager.sources.append(Source("S000", "Test", "User", "S/O", "ABB"))

    # When
    manager.clear_link()

    # Then
    assert len(manager.individuals) == 0
    assert len(manager.sources) == 0
Example #17
0
def test_load_link_invalid_filename_shows_message(monkeypatch):
    """
    When a file is specified that doesn't exist
    an error dialog is shown
    """
    # Given
    manager = GedcomManager(DataContext())
    monkeypatch.setattr(QMessageBox, "warning", mock.MagicMock())

    # When
    manager.load_link("foo")

    # Then
    QMessageBox.warning.assert_called()  # pylint: disable=no-member
Example #18
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.data_context = DataContext()
        self.main_screen = None
        self.project_manager = ProjectFileManager(self)
        self.gedcom_manager = GedcomManager(self.data_context, self)
        self.setup_window()
        self.setup_window_title()
        self.setup_menubar()

        if os.getenv("GRANT_TEST", "") != "":
            self.project_manager.project = ResearchProject("test_data")
            self.project_manager.project.from_py(yaml.safe_load(TEST_DATA))
            self.project_manager.project_changed.emit()
Example #19
0
def test_refresh_link_reloads_file():
    """ When the link is removed, the caches should be cleared too """
    # Given
    manager = GedcomManager(DataContext())
    manager.individuals.append(Individual("IND01", "Test", "User", 1900, 1999))
    manager.sources.append(Source("SOU01", "Test", "User", "S/O", "ABB"))

    # When
    manager.refresh_link("tests/unit/test.ged")

    # Then
    assert len(manager.individuals) == 2
    assert manager.individuals[0].pointer == "I0000"
    assert len(manager.sources) == 2
    assert manager.sources[0].pointer == "S0000"
Example #20
0
def test_loading_creates_individuals():
    """ Individuals should have their values set correctly """
    # Given
    manager = GedcomManager(DataContext())

    # When
    manager.load_link("tests/unit/test.ged")

    # Then
    assert len(manager.individuals) == 2
    assert manager.individuals[0].pointer == "I0000"
    assert manager.individuals[1].pointer == "I0001"
    assert manager.individuals[0].first_name == "Adam Brian Charles"
    assert manager.individuals[0].last_name == "Dawson"
    assert manager.individuals[0].birth_year == 1801
    assert manager.individuals[0].death_year == 1851
Example #21
0
def test_loading_creates_sources():
    """ Sources should have their values set correctly """
    # Given
    manager = GedcomManager(DataContext())

    # When
    manager.load_link("tests/unit/test.ged")

    # Then
    assert len(manager.sources) == 2
    assert manager.sources[0].pointer == "S0000"
    assert manager.sources[1].pointer == "S0001"
    assert manager.sources[0].title == "Grantham Church Books 1705-1767"
    assert manager.sources[0].author == "Grantham Diocese"
    assert manager.sources[0].publisher == "Ancestry.com"
    assert manager.sources[0].abbreviation == "GCB17"
Example #22
0
def test_selection_changed_handler_updates_detail_screen(
        qtbot, node_type, screen_name):
    """ Given a particular node type, what detail screen is being shown """
    # Given
    node = SimpleNamespace()
    node.type = node_type
    item = mock.MagicMock()
    item.internalPointer = mock.MagicMock(return_value=node)

    screen = MainScreen(None, DataContext())
    screen.change_detail_screen = mock.MagicMock()
    qtbot.add_widget(screen)

    # When
    screen.selection_changed(item)

    # Then
    screen.change_detail_screen.assert_called_with(screen_name, item)
Example #23
0
def test_link_updated_sets_link_edit(qtbot):
    """
    When the link_updated() function is triggered, it updates the _link_
    QLineEdit and calls the mapper to submit the changes
    """
    # Given
    data_context = DataContext()
    screen = TaskDetails(data_context)
    qtbot.add_widget(screen)

    screen.link.setText("Foo")
    screen.mapper = mock.MagicMock()

    # When
    screen.link_updated("Bar")

    # Then
    assert screen.link.text() == "Bar"
    screen.mapper.submit.assert_called()