mirror of
https://github.com/borgbase/vorta
synced 2024-12-22 07:43:09 +00:00
Repo test improvements. By @bigtedde (#1771)
This commit is contained in:
parent
e85ec38c65
commit
81920ea3f0
4 changed files with 66 additions and 44 deletions
|
@ -138,7 +138,7 @@ def validate(self) -> bool:
|
|||
self.passwordLineEdit.error_state = True
|
||||
self.confirmLineEdit.error_state = True
|
||||
self.set_error_label(
|
||||
translate('PasswordInput', "Passwords must be identical and atleast {0} characters long.").format(
|
||||
translate('PasswordInput', "Passwords must be identical and at least {0} characters long.").format(
|
||||
self._minimum_length
|
||||
)
|
||||
)
|
||||
|
@ -148,7 +148,7 @@ def validate(self) -> bool:
|
|||
elif not pass_long:
|
||||
self.passwordLineEdit.error_state = True
|
||||
self.set_error_label(
|
||||
translate('PasswordInput', "Passwords must be atleast {0} characters long.").format(
|
||||
translate('PasswordInput', "Passwords must be at least {0} characters long.").format(
|
||||
self._minimum_length
|
||||
)
|
||||
)
|
||||
|
|
|
@ -107,7 +107,7 @@ def validate(self):
|
|||
return False
|
||||
|
||||
if len(self.values['repo_name']) > 64:
|
||||
self._set_status(self.tr('Repository name must be less than 64 characters.'))
|
||||
self._set_status(self.tr('Repository name must be less than 65 characters.'))
|
||||
return False
|
||||
|
||||
if RepoModel.get_or_none(RepoModel.url == self.values['repo_url']) is not None:
|
||||
|
|
|
@ -86,7 +86,7 @@ def test_password_input_validation(qapp, qtbot):
|
|||
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."
|
||||
assert password_input.validation_label.text() == "Passwords must be at least 10 characters long."
|
||||
|
||||
password_input.clear()
|
||||
qtbot.keyClicks(password_input.passwordLineEdit, "123456789")
|
||||
|
@ -94,7 +94,7 @@ def test_password_input_validation(qapp, qtbot):
|
|||
|
||||
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."
|
||||
assert password_input.validation_label.text() == "Passwords must be identical and at least 10 characters long."
|
||||
|
||||
password_input.clear()
|
||||
qtbot.keyClicks(password_input.passwordLineEdit, "1234567890")
|
||||
|
@ -130,7 +130,7 @@ def test_password_input_validation_disabled(qapp, qtbot):
|
|||
|
||||
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."
|
||||
assert password_input.validation_label.text() == "Passwords must be identical and at least 9 characters long."
|
||||
|
||||
password_input.set_validation_enabled(False)
|
||||
assert not password_input.passwordLineEdit.error_state
|
||||
|
|
|
@ -12,43 +12,49 @@
|
|||
SHORT_PASSWORD = 'hunter2'
|
||||
|
||||
|
||||
def test_repo_add_failures(qapp, qtbot, mocker, borg_json_output):
|
||||
@pytest.mark.parametrize(
|
||||
"first_password, second_password, validation_error",
|
||||
[
|
||||
(SHORT_PASSWORD, SHORT_PASSWORD, 'Passwords must be at least 9 characters long.'),
|
||||
(LONG_PASSWORD, SHORT_PASSWORD, 'Passwords must be identical.'),
|
||||
(SHORT_PASSWORD + "1", SHORT_PASSWORD, 'Passwords must be identical and at least 9 characters long.'),
|
||||
(LONG_PASSWORD, LONG_PASSWORD, ''), # no error, password meets requirements.
|
||||
],
|
||||
)
|
||||
def test_new_repo_password_validation(qapp, qtbot, borg_json_output, first_password, second_password, validation_error):
|
||||
# Add new repo window
|
||||
main = qapp.main_window
|
||||
main.repoTab.new_repo()
|
||||
add_repo_window = main.repoTab._window
|
||||
tab = main.repoTab
|
||||
tab.new_repo()
|
||||
add_repo_window = tab._window
|
||||
qtbot.addWidget(add_repo_window)
|
||||
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, LONG_PASSWORD)
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.confirmLineEdit, LONG_PASSWORD)
|
||||
qtbot.keyClicks(add_repo_window.repoURL, 'aaa')
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, first_password)
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.confirmLineEdit, second_password)
|
||||
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
|
||||
assert add_repo_window.errorText.text().startswith('Please enter a valid')
|
||||
assert add_repo_window.passwordInput.validation_label.text() == validation_error
|
||||
|
||||
add_repo_window.passwordInput.passwordLineEdit.clear()
|
||||
add_repo_window.passwordInput.confirmLineEdit.clear()
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, SHORT_PASSWORD)
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.confirmLineEdit, SHORT_PASSWORD)
|
||||
qtbot.keyClicks(add_repo_window.repoURL, 'bbb.com:repo')
|
||||
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
|
||||
assert add_repo_window.passwordInput.validation_label.text() == 'Passwords must be atleast 9 characters long.'
|
||||
|
||||
add_repo_window.passwordInput.passwordLineEdit.clear()
|
||||
add_repo_window.passwordInput.confirmLineEdit.clear()
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, SHORT_PASSWORD + "1")
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.confirmLineEdit, SHORT_PASSWORD)
|
||||
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
|
||||
assert (
|
||||
add_repo_window.passwordInput.validation_label.text()
|
||||
== 'Passwords must be identical and atleast 9 characters long.'
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"repo_name, error_text",
|
||||
[
|
||||
('test_repo_name', ''), # valid repo name
|
||||
('a' * 64, ''), # also valid (<=64 characters)
|
||||
('a' * 65, 'Repository name must be less than 65 characters.'), # not valid (>64 characters)
|
||||
],
|
||||
)
|
||||
def test_repo_add_name_validation(qapp, qtbot, borg_json_output, repo_name, error_text):
|
||||
main = qapp.main_window
|
||||
tab = main.repoTab
|
||||
tab.new_repo()
|
||||
add_repo_window = tab._window
|
||||
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
|
||||
qtbot.addWidget(add_repo_window)
|
||||
|
||||
add_repo_window.passwordInput.passwordLineEdit.clear()
|
||||
add_repo_window.passwordInput.confirmLineEdit.clear()
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, LONG_PASSWORD)
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.confirmLineEdit, SHORT_PASSWORD)
|
||||
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
|
||||
qtbot.keyClicks(add_repo_window.repoName, repo_name)
|
||||
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
|
||||
assert add_repo_window.passwordInput.validation_label.text() == 'Passwords must be identical.'
|
||||
assert add_repo_window.errorText.text() == error_text
|
||||
|
||||
|
||||
def test_repo_unlink(qapp, qtbot, monkeypatch):
|
||||
|
@ -56,7 +62,6 @@ def test_repo_unlink(qapp, qtbot, monkeypatch):
|
|||
tab = main.repoTab
|
||||
monkeypatch.setattr(QMessageBox, "show", lambda *args: True)
|
||||
|
||||
main.tabWidget.setCurrentIndex(0)
|
||||
qtbot.mouseClick(tab.repoRemoveToolbutton, QtCore.Qt.MouseButton.LeftButton)
|
||||
qtbot.waitUntil(lambda: tab.repoSelector.count() == 1, **pytest._wait_defaults)
|
||||
assert RepoModel.select().count() == 0
|
||||
|
@ -69,8 +74,9 @@ def test_repo_unlink(qapp, qtbot, monkeypatch):
|
|||
|
||||
def test_password_autofill(qapp, qtbot):
|
||||
main = qapp.main_window
|
||||
main.repoTab.new_repo() # couldn't click menu
|
||||
add_repo_window = main.repoTab._window
|
||||
tab = main.repoTab
|
||||
tab.new_repo()
|
||||
add_repo_window = tab._window
|
||||
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
|
||||
|
||||
keyring = VortaKeyring.get_keyring()
|
||||
|
@ -82,14 +88,28 @@ def test_password_autofill(qapp, qtbot):
|
|||
assert add_repo_window.passwordInput.passwordLineEdit.text() == password
|
||||
|
||||
|
||||
def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
|
||||
# Add new repo window
|
||||
def test_repo_add_failure(qapp, qtbot, borg_json_output):
|
||||
main = qapp.main_window
|
||||
main.repoTab.new_repo() # couldn't click menu
|
||||
add_repo_window = main.repoTab._window
|
||||
tab = main.repoTab
|
||||
tab.new_repo()
|
||||
add_repo_window = tab._window
|
||||
qtbot.addWidget(add_repo_window)
|
||||
|
||||
# Add repo with invalid URL
|
||||
qtbot.keyClicks(add_repo_window.repoURL, 'aaa')
|
||||
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
|
||||
assert add_repo_window.errorText.text().startswith('Please enter a valid repo URL')
|
||||
|
||||
|
||||
def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
|
||||
main = qapp.main_window
|
||||
tab = main.repoTab
|
||||
tab.new_repo()
|
||||
add_repo_window = tab._window
|
||||
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
|
||||
test_repo_name = 'Test Repo'
|
||||
|
||||
# Enter valid repo URL, name, and password
|
||||
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
|
||||
qtbot.keyClicks(add_repo_window.repoName, test_repo_name)
|
||||
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, LONG_PASSWORD)
|
||||
|
@ -108,13 +128,15 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
|
|||
|
||||
keyring = VortaKeyring.get_keyring()
|
||||
assert keyring.get_password("vorta-repo", RepoModel.get(id=2).url) == LONG_PASSWORD
|
||||
assert main.repoTab.repoSelector.currentText() == f"{test_repo_name} - {test_repo_url}"
|
||||
assert tab.repoSelector.currentText() == f"{test_repo_name} - {test_repo_url}"
|
||||
|
||||
|
||||
def test_ssh_dialog(qapp, qtbot, tmpdir):
|
||||
main = qapp.main_window
|
||||
qtbot.mouseClick(main.repoTab.bAddSSHKey, QtCore.Qt.MouseButton.LeftButton)
|
||||
ssh_dialog = main.repoTab._window
|
||||
tab = main.repoTab
|
||||
|
||||
qtbot.mouseClick(tab.bAddSSHKey, QtCore.Qt.MouseButton.LeftButton)
|
||||
ssh_dialog = tab._window
|
||||
|
||||
ssh_dir = tmpdir
|
||||
key_tmpfile = ssh_dir.join("id_rsa-test")
|
||||
|
|
Loading…
Reference in a new issue