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
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)
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