Beispiel #1
0
def test_column_count_is_nonzero():
    """ Even for an empty model, there should be columns defined """
    # Given

    # When
    model = IndividualsModel()

    # Then
    assert model.columnCount() > 0
    assert model.rowCount() == 0
Beispiel #2
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
Beispiel #3
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)
Beispiel #4
0
def three_indi_model():
    """ Fixture to create a basic model """
    individuals = []
    individuals.append(Individual("I001", "Foo1", "Person", 1901, 1951))
    individuals.append(Individual("I002", "Foo2", "Person", 1902, 1952))
    individuals.append(Individual("I003", "Foo3", "Person", 1903, 1953))

    return IndividualsModel(individuals)
Beispiel #5
0
 def __init__(self,
              data_model=None,
              individuals_model=None,
              sources_model=None):
     self.data_model = TreeModel() if data_model is None else data_model
     self.individuals_model = (IndividualsModel(
         []) if individuals_model is None else individuals_model)
     self.sources_model = (SourcesModel([])
                           if sources_model is None else sources_model)
Beispiel #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
Beispiel #7
0
def test_autocomplete_name_includes_relevant_data():
    """ Check the first name """
    # Given
    individuals = []
    indi = Individual("I001", "Test", "Person", 1901, 1951)
    individuals.append(indi)

    model = IndividualsModel(individuals)
    index = model.index(0, IndividualsModelColumns.AUTOCOMPLETE)

    # When
    descriptive_name = model.data(index)

    # Then
    assert indi.pointer not in descriptive_name
    assert indi.first_name in descriptive_name
    assert indi.last_name in descriptive_name
    assert str(indi.birth_year) in descriptive_name
    assert str(indi.death_year) in descriptive_name
Beispiel #8
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
Beispiel #9
0
def test_update_list_changes_data(qtbot):
    """ Check the first name """
    # Given
    model = IndividualsModel()
    assert model.rowCount() == 0

    individuals = []
    indi = Individual("I001", "Test", "Person", 1901, 1951)
    individuals.append(indi)

    # When
    with qtbot.waitSignals([model.modelAboutToBeReset, model.modelReset]):
        model.update_list(individuals)

    # Then
    assert model.rowCount() == 1
Beispiel #10
0
def test_data_returns_values_in_individual_record():
    """ Check the first name """
    # Given
    individuals = []
    indi = Individual("I001", "Test", "Person", 1901, 1951)
    individuals.append(indi)

    model = IndividualsModel(individuals)

    # When
    pointer = model.data(model.index(0, IndividualsModelColumns.POINTER))
    first = model.data(model.index(0, IndividualsModelColumns.FIRST_NAME))
    last = model.data(model.index(0, IndividualsModelColumns.LAST_NAME))
    birth = model.data(model.index(0, IndividualsModelColumns.BIRTH_YEAR))
    death = model.data(model.index(0, IndividualsModelColumns.DEATH_YEAR))
    autocomplete = model.data(
        model.index(0, IndividualsModelColumns.AUTOCOMPLETE))
    # Then
    assert model.columnCount() == 6
    assert pointer == indi.pointer
    assert first == indi.first_name
    assert last == indi.last_name
    assert birth == indi.birth_year
    assert death == indi.death_year
    assert autocomplete != ""