Beispiel #1
0
 def setup_method(self):
     os.environ['BOOKLIB_DB_PATH'] = ':memory:'
     session = database.Session()
     database.init(session)
     self.connection = session.engine.connect()
     self.tx = self.connection.begin()
     self.session = session.value
Beispiel #2
0
def test_account_focus_on_first_name(qtbot):
    os.environ['BOOKLIB_DB_PATH'] = ':memory:'
    database.init(database.Session())

    window = admin.AdminWindow(config.MenuConfig())
    qtbot.addWidget(window)
    qtbot.mouseClick(window.account_btn, QtCore.Qt.LeftButton)

    dialog = window.account_window
    assert dialog.isVisible()
    if not os.getenv('TRAVIS'):
        assert dialog.account.first_name_qt.hasFocus()
Beispiel #3
0
def test_account_no_first_name(qtbot):
    os.environ['BOOKLIB_DB_PATH'] = ':memory:'
    database.init(database.Session())

    window = admin.AdminWindow(config.MenuConfig())
    qtbot.addWidget(window)
    qtbot.mouseClick(window.account_btn, QtCore.Qt.LeftButton)

    dialog = window.account_window
    insert_test_data(dialog.account)
    dialog.account.first_name_qt.setText('')
    qtbot.mouseClick(dialog.button_box.buttons()[0], QtCore.Qt.LeftButton)
    assert dialog.error_dialog.isVisible()
Beispiel #4
0
    def insert_account(self) -> None:
        try:
            self.account.validate()
        except errors.InputDataError as e:
            self.error_dialog = QtWidgets.QErrorMessage(self)
            self.error_dialog.setWindowModality(QtCore.Qt.WindowModal)
            self.error_dialog.showMessage(str(e))
            return

        with database.Session() as session:
            session.add(self.account.data)

        self.clear_account_data()
        self.show_admin_window()
Beispiel #5
0
def main(argv: typing.Iterable[typing.Text] = None) -> None:
    if not argv:
        argv = sys.argv[1:]

    # Create database if it doesn't exist yet
    if not os.path.exists(config.get_db_path()):
        session = database.Session()
        database.init(session)

    # Get config
    cfg = config.MenuConfig()

    # Start the main window
    app = ui.main.create_app(argv)
    _ = booklib.ui.window.admin.AdminWindow(cfg)
    app.exec_()
Beispiel #6
0
    def search_entry(self) -> None:
        # Clear the items from previous search.
        self.search_output_table.setRowCount(0)

        # Perform new search.
        category = str(self.search_category_combo.currentText())
        value = str(self.search_textbox.text())
        session = database.Session()
        if category == 'First Name':
            users = session.value.query(
                models.User).filter_by(first_name=value).all()

            # Initialize table.
            count = len(users) + 1
            self.search_output_table.setRowCount(count)
            self.search_output_table.setColumnCount(2)

            if not users:
                self.search_output_table.setColumnCount(1)
                self.search_output_table.horizontalHeader(
                ).setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
                # FIXME - error message to be in the config as well
                self.search_output_table.setItem(
                    0, 0,
                    QtWidgets.QTableWidgetItem(
                        'no users found with first name: {}'.format(value)))
                return

            self.search_output_table.horizontalHeader().setSectionResizeMode(
                1,
                QtWidgets.QHeaderView.Stretch,
            )
            for i, header in enumerate(['First Name', 'Family Name']):
                self.search_output_table.setItem(
                    0,
                    i,
                    QtWidgets.QTableWidgetItem(header),
                )
            for i, user in enumerate(users, start=1):
                self.search_output_table.setItem(
                    i, 0, QtWidgets.QTableWidgetItem(user.first_name))
                self.search_output_table.setItem(
                    i, 1, QtWidgets.QTableWidgetItem(user.family_name))
Beispiel #7
0
def test_account_clear_button(qtbot):
    os.environ['BOOKLIB_DB_PATH'] = ':memory:'
    database.init(database.Session())

    window = admin.AdminWindow(config.MenuConfig())
    qtbot.addWidget(window)
    qtbot.mouseClick(window.account_btn, QtCore.Qt.LeftButton)

    dialog = window.account_window

    # Move focus to another line
    dialog.account.family_name_qt.setFocus()
    dialog.account.family_name_qt.setText('random')
    if not os.getenv('TRAVIS'):
        qtbot.waitUntil(lambda: dialog.account.family_name_qt.hasFocus())

    qtbot.mouseClick(dialog.button_box.buttons()[2], QtCore.Qt.LeftButton)
    assert dialog.isVisible()
    assert not str(dialog.account.family_name_qt.text())
    if not os.getenv('TRAVIS'):
        assert dialog.account.first_name_qt.hasFocus()
Beispiel #8
0
    def __init__(self, labels: typing.Mapping[typing.Text, typing.Any]):
        self.labels = labels

        self.isbn_no_qt = QtWidgets.QLineEdit()
        self.call_no_qt = QtWidgets.QLineEdit()

        categories = labels['categories_checkboxes']
        name = categories[models.BookCategoryEnum.children.name]
        self.categories_children_qt = QtWidgets.QCheckBox(name)

        name = categories[models.BookCategoryEnum.adult.name]
        self.categories_adult_qt = QtWidgets.QCheckBox(name)

        name = categories[models.BookCategoryEnum.young_adult.name]
        self.categories_young_adult_qt = QtWidgets.QCheckBox(name)

        name = categories[models.BookCategoryEnum.teen.name]
        self.categories_teen_qt = QtWidgets.QCheckBox(name)

        name = categories[models.BookCategoryEnum.animals.name]
        self.categories_animals_qt = QtWidgets.QCheckBox(name)

        name = categories[models.BookCategoryEnum.nature.name]
        self.categories_nature_qt = QtWidgets.QCheckBox(name)

        name = categories[models.BookCategoryEnum.religious.name]
        self.categories_religious_qt = QtWidgets.QCheckBox(name)

        name = categories[models.BookCategoryEnum.comic.name]
        self.categories_comic_qt = QtWidgets.QCheckBox(name)

        name = categories[models.BookCategoryEnum.others.name]
        self.categories_others_qt = QtWidgets.QCheckBox(name)

        self.categories_box_qt = QtWidgets.QGroupBox()
        categories_layout = QtWidgets.QGridLayout()
        categories_layout.addWidget(self.categories_children_qt, 1, 0)
        categories_layout.addWidget(self.categories_adult_qt, 1, 1)
        categories_layout.addWidget(self.categories_young_adult_qt, 2, 0)
        categories_layout.addWidget(self.categories_teen_qt, 2, 1)
        categories_layout.addWidget(self.categories_animals_qt, 3, 0)
        categories_layout.addWidget(self.categories_nature_qt, 3, 1)
        categories_layout.addWidget(self.categories_religious_qt, 4, 0)
        categories_layout.addWidget(self.categories_comic_qt, 4, 1)
        categories_layout.addWidget(self.categories_others_qt, 5, 0)
        self.categories_box_qt.setLayout(categories_layout)

        self.reading_level_qt = QtWidgets.QComboBox()
        # Add empty string as default.
        self.reading_level_qt.addItem('')

        levels = labels['reading_levels']
        for level in models.ReadingLevelEnum:
            self.reading_level_qt.addItem(levels[level.name])
        # self.reading_level_qt.activated[str].connect()

        self.title_qt = QtWidgets.QLineEdit()
        self.author_qt = QtWidgets.QLineEdit()

        self.publisher_qt = QtWidgets.QLineEdit()
        publisher_completer = QtWidgets.QCompleter()
        publisher_model = QtCore.QStringListModel()

        # Find all publishers that have been added.
        with database.Session() as session:
            publishers = session.query(models.Publisher).all()
            publisher_model.setStringList(publishers)
        self.publisher_qt.setCompleter(publisher_completer)