-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: tests/unit/test_repo
- Clean up, parametrize, and increase test coverage.
#1771
Changes from all commits
9f8b888
e366662
ac1150f
9a92d2b
09312a5
c46c6a5
a6544aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected wording, should say "less than 65 characters" or "no more than 64 characters". I chose the path of least change. |
||
return False | ||
|
||
if RepoModel.get_or_none(RepoModel.url == self.values['repo_url']) is not None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,51 +12,56 @@ | |
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.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton) | ||
assert add_repo_window.errorText.text().startswith('Please enter a valid') | ||
|
||
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.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.passwordInput.validation_label.text() | ||
== 'Passwords must be identical and atleast 9 characters long.' | ||
) | ||
assert add_repo_window.passwordInput.validation_label.text() == validation_error | ||
|
||
|
||
@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): | ||
main = qapp.main_window | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency across the tests, I defined |
||
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_failure(qapp, qtbot, borg_json_output): | ||
main = qapp.main_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): | ||
# Add new repo window | ||
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 | ||
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") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo corrected: 'atleast' -> 'at least'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!