Exemplo n.º 1
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("")
Exemplo n.º 2
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
Exemplo n.º 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
Exemplo n.º 4
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()
Exemplo n.º 5
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
Exemplo n.º 6
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"
Exemplo n.º 7
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"
Exemplo n.º 8
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
Exemplo n.º 9
0
class MainWindow(QMainWindow):
    """ The Main Window where we start """
    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()

    def setup_window_title(self):
        """ Sets the window title from project name """
        title = "Grant - "
        if self.project_manager.project is not None:
            title += os.path.splitext(
                os.path.basename(self.project_manager.project.filename))[0]
            title += "*" if self.project_manager.needs_saving else ""
        else:
            title += " The Genealogical Research AssistaNT"
        self.setWindowTitle(title)

    def setup_window(self):
        """ Sets up all widgets and window stuff """
        self.setWindowIcon(QIcon(":/icons/grant.ico"))

        self.main_screen = MainScreen(self, self.data_context)
        self.setCentralWidget(self.main_screen)

        self.project_manager.project_changed.connect(
            self.project_changed_handler)
        self.project_manager.project_saved.connect(self.setup_window_title)

        def model_changed():
            self.project_manager.needs_saving = True
            self.setup_window_title()

        self.data_context.data_model.dataChanged.connect(model_changed)
        self.data_context.data_model.layoutChanged.connect(model_changed)
        self.data_context.data_model.rowsRemoved.connect(model_changed)

    def setup_menubar(self):
        """ Sets up the menu bar """
        self.menu_bar = MenuBar(self)
        self.setMenuBar(self.menu_bar)
        self.menu_bar.file_create_new_action.triggered.connect(
            self.project_manager.create_new_project)
        self.menu_bar.file_open_project_action.triggered.connect(
            self.project_manager.open_project)
        self.menu_bar.file_project_overview_action.triggered.connect(
            lambda: ProjectOverviewDialog.show(self.data_context, self.
                                               project_manager.project, self))
        self.menu_bar.file_save_project_action.triggered.connect(
            self.project_manager.save_project)
        self.menu_bar.file_save_project_as_action.triggered.connect(
            self.project_manager.save_project_as)
        self.menu_bar.gedcom_link_action.triggered.connect(
            self.project_manager.link_gedcom_file)
        self.menu_bar.gedcom_unlink_action.triggered.connect(
            self.project_manager.unlink_gedcom_file)
        self.menu_bar.gedcom_refresh_action.triggered.connect(
            lambda: self.gedcom_manager.refresh_link(self.project_manager.
                                                     project.gedcom))

        self.menu_bar.view_project_action.triggered.connect(
            lambda: self.main_screen.change_selection_screen("tree"))
        self.menu_bar.view_filter_action.triggered.connect(
            lambda: self.main_screen.change_selection_screen("filter"))

        def enable_on_project_load():
            self.menu_bar.file_project_overview_action.setDisabled(
                self.project_manager.project is None)
            self.menu_bar.file_save_project_action.setDisabled(
                self.project_manager.project is None)
            self.menu_bar.file_save_project_as_action.setDisabled(
                self.project_manager.project is None)
            self.menu_bar.gedcom_link_action.setDisabled(
                self.project_manager.project is None)
            self.menu_bar.gedcom_unlink_action.setDisabled(
                self.project_manager.project is None
                or not self.project_manager.project.has_gedcom())
            self.menu_bar.gedcom_refresh_action.setDisabled(
                self.project_manager.project is None
                or not self.project_manager.project.has_gedcom())

        self.project_manager.project_changed.connect(enable_on_project_load)

    def project_changed_handler(self):
        """ Updates all the screens with the new project information """
        if (self.project_manager.project is None
                or self.project_manager.project.gedcom == ""):
            self.gedcom_manager.clear_link()
        else:
            self.gedcom_manager.load_link(self.project_manager.project.gedcom)
        self.data_context.data_model.set_project(self.project_manager.project)
        self.main_screen.set_project(self.project_manager.project)
        updater = LinkUpdater(self.data_context)
        updater.calculate_updates()
        if updater.has_pending_updates():
            updater.commit_updates()
        self.setup_window_title()