Esempio n. 1
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
Esempio n. 2
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)
Esempio n. 3
0
def test_string_repr_includes_ancestor():
    """ The str() representation should include the ancestor """
    # Given
    plan = ResearchPlan()
    plan.ancestor = "ANCESTOR"

    # When
    string = str(plan)

    # Then
    assert plan.ancestor in string
Esempio n. 4
0
def test_ancestor_matches_plan(ancestor, value):
    """ When the plan is passed and ancestor filter set, it should be applied """
    # Given
    task = ResearchTask()
    plan = ResearchPlan()
    matcher = TaskMatcher()
    matcher.ancestor_filter("Henry")

    # When
    plan.ancestor = ancestor

    # Then
    assert matcher.match(task, plan) is value
Esempio n. 5
0
def test_to_py_sets_fields():
    """ The to_py() function should create a python data structure of the class fields """
    # Given
    plan = ResearchPlan()
    plan.ancestor = "ANCESTOR"
    plan.ancestor_link = 11

    # When
    data = plan.to_py()

    # Then
    assert data["ancestor"] == plan.ancestor
    assert data["ancestor_link"] == plan.ancestor_link
    assert data["goal"] == plan.goal
    assert data["tasks"] == plan.tasks
    assert len(data.keys()) == 4  # To verify nothing else was added
Esempio n. 6
0
def test_data_returns_none_for_invalid_role():
    """ When getting data, invalid role returns None """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    plan.ancestor = "Foo"
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0, 0, model.plans_index)

    # When
    retval = model.data(plan_index, Qt.UserRole)

    # Then
    assert retval is None
Esempio n. 7
0
def test_data_returns_qicon_for_decoration_role():
    """ When getting data, decoration role returns an icon """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    plan.ancestor = "Foo"
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0, 0, model.plans_index)

    # When
    retval = model.data(plan_index, Qt.DecorationRole)

    # Then
    assert isinstance(retval, QIcon)
Esempio n. 8
0
def test_data_returns_string_for_valid_index():
    """ When getting data, ancestor is returned for valid index """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    plan.ancestor = "Foo"
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0, 0, model.plans_index)

    # When
    retval = model.data(plan_index, Qt.DisplayRole)

    # Then
    assert retval is plan.ancestor
Esempio n. 9
0
def test_data_returns_none_for_invalid_column():
    """ When getting data, invalid column returns None """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    plan.ancestor = "Foo"
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0,
                             len(list(TreeModelCols)) + 1, model.plans_index)

    # When
    retval = model.data(plan_index, Qt.DisplayRole)

    # Then
    assert retval is None