Пример #1
0
def three_sour_model():
    """ Fixture to create a basic model """
    sources = []
    sources.append(Source("I001", "Foo1", "Person", "Pub", "Abbr"))
    sources.append(Source("I002", "Foo2", "Person", "Pub", "Abbr"))
    sources.append(Source("I003", "Foo3", "Person", "Pub", "Abbr"))

    return SourcesModel(sources)
Пример #2
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
Пример #3
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
Пример #4
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"
Пример #5
0
def test_update_list_changes_data(qtbot):
    """ Check the first name """
    # Given
    model = SourcesModel()
    assert model.rowCount() == 0

    sources = []
    source = Source("I001", "Test", "Person", "Pub", "Abbr")
    sources.append(source)

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

    # Then
    assert model.rowCount() == 1
Пример #6
0
def test_autocomplete_name_no_comma_if_no_author():
    """ Check the first name """
    # Given
    sources = []
    source = Source("I001", "Test", "", "Pub", "Abbr")
    sources.append(source)

    model = SourcesModel(sources)
    index = model.index(0, SourcesModelColumns.AUTOCOMPLETE)

    # When
    descriptive_name = model.data(index)

    # Then
    assert "," not in descriptive_name
    assert descriptive_name == source.title
Пример #7
0
def test_autocomplete_name_includes_relevant_data():
    """ Check the first name """
    # Given
    sources = []
    source = Source("I001", "Test", "Person", "Pub", "Abbr")
    sources.append(source)

    model = SourcesModel(sources)
    index = model.index(0, SourcesModelColumns.AUTOCOMPLETE)

    # When
    descriptive_name = model.data(index)

    # Then
    assert source.pointer not in descriptive_name
    assert source.title in descriptive_name
    assert source.author in descriptive_name
Пример #8
0
def test_data_returns_values_in_source_record():
    """ Check the first name """
    # Given
    sources = []
    source = Source("I001", "Test", "Person", "Pub", "Abbr")
    sources.append(source)

    model = SourcesModel(sources)

    # When
    pointer = model.data(model.index(0, SourcesModelColumns.POINTER))
    title = model.data(model.index(0, SourcesModelColumns.TITLE))
    author = model.data(model.index(0, SourcesModelColumns.AUTHOR))
    publisher = model.data(model.index(0, SourcesModelColumns.PUBLISHER))
    abbreviation = model.data(model.index(0, SourcesModelColumns.ABBREVIATION))
    autocomplete = model.data(model.index(0, SourcesModelColumns.AUTOCOMPLETE))
    # Then
    assert model.columnCount() == 6
    assert pointer == source.pointer
    assert title == source.title
    assert author == source.author
    assert publisher == source.publisher
    assert abbreviation == source.abbreviation
    assert autocomplete != ""