1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-22 15:57:34 +00:00
vorta/tests/unit/test_password_input.py
jetchirag b015368fee
Integration Tests for Borg (#1716)
Move existing tests into subfolder `tests/unit`. Write integration tests that actually run the installed borg executable. Those tests can be found in `tests/integration`.  Those pytest fixtures that are the same for both kinds of tests remain in `tests/conftest.py`. The others can be found in `tests/integration/conftest.py` or `tests/unit/conftest.py`. This adds nox to the project and configures it to run the tests with different borg versions. This also updates the ci workflow to run the integration tests using nox.

* noxfile.py : Run pytest with a matrix of borg versions OR a specific borg version

* Makefile : Run using nox. Add phonies `test-unit` and `test-integration`.

* tests/conftest.py : Move some fixtures/functions to `tests/unit/conftest.py`.

* tests/test_*.py --> tests/unit/ : Move unittests and assets into subfolder

* tests/integration/ : Write integration tests.

* requirements.d/dev.txt: Add `nox` and `pkgconfig`. The latter is needed for installing new borg versions.

* .github/actions/setup/action.yml : Update to install pre-commit and nox when needed. The action now no longer installs Vorta.

* .github/actions/install-dependencies/action.yml : Install system deps of borg with this new composite action.

* .github/workflows/test.yml : Rename `test` ci to `test-unit` and update it for the new test setup.
                                              Implement `test-integration` ci.

Signed-off-by: Chirag Aggarwal <thechiragaggarwal@gmail.com>
2023-08-05 13:49:45 +00:00

165 lines
6.2 KiB
Python

import pytest
from PyQt6.QtWidgets import QFormLayout, QWidget
from vorta.views.partials.password_input import PasswordInput, PasswordLineEdit
def test_create_password_line_edit(qtbot):
password_line_edit = PasswordLineEdit()
qtbot.addWidget(password_line_edit)
assert password_line_edit is not None
def test_password_line_get_password(qtbot):
password_line_edit = PasswordLineEdit()
qtbot.addWidget(password_line_edit)
assert password_line_edit.get_password() == ""
qtbot.keyClicks(password_line_edit, "test")
assert password_line_edit.get_password() == "test"
def test_password_line_visible(qtbot):
password_line_edit = PasswordLineEdit()
qtbot.addWidget(password_line_edit)
assert not password_line_edit.visible
password_line_edit.toggle_visibility()
assert password_line_edit.visible
with pytest.raises(TypeError):
password_line_edit.visible = "OK"
def test_password_line_error_state(qtbot):
password_line_edit = PasswordLineEdit()
qtbot.addWidget(password_line_edit)
assert not password_line_edit.error_state
assert password_line_edit.styleSheet() == ""
password_line_edit.error_state = True
assert password_line_edit.error_state
assert password_line_edit.styleSheet() == "QLineEdit { border: 2px solid red; }"
def test_password_line_visibility_button(qtbot):
password_line_edit = PasswordLineEdit(show_visibility_button=False)
qtbot.addWidget(password_line_edit)
assert not password_line_edit._show_visibility_button
password_line_edit = PasswordLineEdit()
qtbot.addWidget(password_line_edit)
assert password_line_edit._show_visibility_button
# test visibility button
password_line_edit.showHideAction.trigger()
assert password_line_edit.visible
password_line_edit.showHideAction.trigger()
assert not password_line_edit.visible
# PasswordInput
def test_create_password_input(qapp, qtbot):
password_input = PasswordInput()
qtbot.addWidget(password_input.create_form_widget(parent=qapp.main_window))
assert password_input is not None
assert not password_input.passwordLineEdit.error_state
assert not password_input.confirmLineEdit.error_state
def test_password_input_get_password(qapp, qtbot):
password_input = PasswordInput()
qtbot.addWidget(password_input.create_form_widget(parent=qapp.main_window))
assert password_input.get_password() == ""
password_input.passwordLineEdit.setText("test")
assert password_input.get_password() == "test"
def test_password_input_validation(qapp, qtbot):
password_input = PasswordInput(minimum_length=10)
qtbot.addWidget(password_input.create_form_widget(parent=qapp.main_window))
qtbot.keyClicks(password_input.passwordLineEdit, "123456789")
qtbot.keyClicks(password_input.confirmLineEdit, "123456789")
assert password_input.passwordLineEdit.error_state
assert password_input.validation_label.text() == "Passwords must be atleast 10 characters long."
password_input.clear()
qtbot.keyClicks(password_input.passwordLineEdit, "123456789")
qtbot.keyClicks(password_input.confirmLineEdit, "test")
assert password_input.passwordLineEdit.error_state
assert password_input.confirmLineEdit.error_state
assert password_input.validation_label.text() == "Passwords must be identical and atleast 10 characters long."
password_input.clear()
qtbot.keyClicks(password_input.passwordLineEdit, "1234567890")
qtbot.keyClicks(password_input.confirmLineEdit, "test")
assert not password_input.passwordLineEdit.error_state
assert password_input.confirmLineEdit.error_state
assert password_input.validation_label.text() == "Passwords must be identical."
password_input.clear()
qtbot.keyClicks(password_input.passwordLineEdit, "1234567890")
qtbot.keyClicks(password_input.confirmLineEdit, "1234567890")
assert not password_input.passwordLineEdit.error_state
assert not password_input.confirmLineEdit.error_state
assert password_input.validation_label.text() == ""
def test_password_input_validation_disabled(qapp, qtbot):
password_input = PasswordInput(show_error=False)
qtbot.addWidget(password_input.create_form_widget(parent=qapp.main_window))
qtbot.keyClicks(password_input.passwordLineEdit, "test")
qtbot.keyClicks(password_input.confirmLineEdit, "test")
assert not password_input.passwordLineEdit.error_state
assert not password_input.confirmLineEdit.error_state
assert password_input.validation_label.text() == ""
password_input.set_validation_enabled(True)
qtbot.keyClicks(password_input.passwordLineEdit, "s")
qtbot.keyClicks(password_input.confirmLineEdit, "a")
assert password_input.passwordLineEdit.error_state
assert password_input.confirmLineEdit.error_state
assert password_input.validation_label.text() == "Passwords must be identical and atleast 9 characters long."
password_input.set_validation_enabled(False)
assert not password_input.passwordLineEdit.error_state
assert not password_input.confirmLineEdit.error_state
assert password_input.validation_label.text() == ""
def test_password_input_set_label(qapp, qtbot):
password_input = PasswordInput(label=["test", "test2"])
qtbot.addWidget(password_input.create_form_widget(parent=qapp.main_window))
assert password_input._label_password.text() == "test"
assert password_input._label_confirm.text() == "test2"
password_input.set_labels("test3", "test4")
assert password_input._label_password.text() == "test3"
assert password_input._label_confirm.text() == "test4"
def test_password_input_add_form_to_layout(qapp, qtbot):
password_input = PasswordInput()
widget = QWidget()
form_layout = QFormLayout(widget)
qtbot.addWidget(widget)
password_input.add_form_to_layout(form_layout)
assert form_layout.itemAt(0, QFormLayout.ItemRole.LabelRole).widget() == password_input._label_password
assert form_layout.itemAt(0, QFormLayout.ItemRole.FieldRole).widget() == password_input.passwordLineEdit
assert form_layout.itemAt(1, QFormLayout.ItemRole.LabelRole).widget() == password_input._label_confirm
assert form_layout.itemAt(1, QFormLayout.ItemRole.FieldRole).widget() == password_input.confirmLineEdit