Skip to content

Commit 7ad4080

Browse files
Address PR review feedback on unified dialog
1 parent 1f63ede commit 7ad4080

2 files changed

Lines changed: 40 additions & 19 deletions

File tree

src/vorta/views/repo_add_dialog.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def __init__(self, parent=None):
151151
self.display_backend_warning()
152152
self.init_encryption()
153153

154+
# start in "connect" mode: hide init only widgets
155+
self._set_init_widgets_visible(False)
156+
154157
def set_password(self, URL):
155158
'''Autofill password from keyring only if current entry is empty'''
156159
password = VortaKeyring.get_keyring().get_password('vorta-repo', URL)
@@ -211,11 +214,22 @@ def display_backend_warning(self):
211214
if self.encryptionComboBox.currentData() != 'none':
212215
self.passwordInput.set_error_label(VortaKeyring.get_keyring().get_backend_warning())
213216

217+
def _set_init_widgets_visible(self, visible):
218+
self.passwordInput.confirmLineEdit.setVisible(visible)
219+
self.passwordInput._label_confirm.setVisible(visible)
220+
self.encryptionLabel.setVisible(visible)
221+
self.encryptionComboBox.setVisible(visible)
222+
if not visible:
223+
self.passwordInput.set_validation_enabled(False)
224+
225+
def _validate_repo_fields(self):
226+
return super().validate()
227+
214228
def validate(self):
215-
return super().validate() and self.passwordInput.validate()
229+
return self._validate_repo_fields() and self.passwordInput.validate()
216230

217231
def run(self):
218-
if not RepoWindow.validate(self):
232+
if not self._validate_repo_fields():
219233
return
220234

221235
self.saveButton.setEnabled(False)
@@ -246,6 +260,9 @@ def _probe_result(self, result):
246260
QMessageBox.StandardButton.No,
247261
)
248262
if reply == QMessageBox.StandardButton.Yes:
263+
self._set_init_widgets_visible(True)
264+
self.passwordInput.set_validation_enabled(True)
265+
self._set_status(self.tr('Please confirm your password and choose encryption to initialize.'))
249266
if not self.passwordInput.validate():
250267
self.saveButton.setEnabled(True)
251268
return
@@ -255,7 +272,7 @@ def _probe_result(self, result):
255272
self._set_status(self.tr('Unable to add your repository.'))
256273
else:
257274
self.saveButton.setEnabled(True)
258-
self._set_status(self.tr('Unable to add your repository.'))
275+
self._set_status(error_msgs if error_msgs else self.tr('Unable to add your repository.'))
259276

260277
def _init_repo(self):
261278
self._set_status(self.tr('Initializing new repository…'))

tests/unit/test_repo.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,32 @@
2727
],
2828
)
2929
def test_new_repo_password_validation(qapp, qtbot, borg_json_output, first_password, second_password, validation_error):
30-
# Add new repo window
30+
# add new repo window
3131
main = qapp.main_window
3232
tab = main.repoTab
3333
tab.add_repo()
3434
add_repo_window = tab._window
3535
qtbot.addWidget(add_repo_window)
3636

37+
# reveal init only widgets so password validation is active
38+
add_repo_window._set_init_widgets_visible(True)
39+
add_repo_window.passwordInput.set_validation_enabled(True)
40+
3741
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, first_password)
3842
qtbot.keyClicks(add_repo_window.passwordInput.confirmLineEdit, second_password)
39-
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
43+
add_repo_window.passwordInput.validate()
4044
assert add_repo_window.passwordInput.validation_label.text() == validation_error
4145

4246

4347
@pytest.mark.parametrize(
44-
"repo_name, error_text",
48+
"repo_name, status_text",
4549
[
46-
('test_repo_name', 'Checking repository\u2026'), # valid repo name
50+
('test_repo_name', 'Checking repository\u2026'), # valid repo name, probe starts
4751
('a' * 64, 'Checking repository\u2026'), # also valid (<=64 characters)
4852
('a' * 65, 'Repository name must be less than 65 characters.'), # not valid (>64 characters)
4953
],
5054
)
51-
def test_repo_add_name_validation(qapp, qtbot, borg_json_output, repo_name, error_text):
55+
def test_repo_add_name_validation(qapp, qtbot, borg_json_output, repo_name, status_text):
5256
main = qapp.main_window
5357
tab = main.repoTab
5458
tab.add_repo()
@@ -59,7 +63,7 @@ def test_repo_add_name_validation(qapp, qtbot, borg_json_output, repo_name, erro
5963
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
6064
qtbot.keyClicks(add_repo_window.repoName, repo_name)
6165
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
62-
assert add_repo_window.errorText.text() == error_text
66+
assert add_repo_window.errorText.text() == status_text
6367

6468

6569
def test_repo_unlink(qapp, qtbot, monkeypatch):
@@ -103,7 +107,7 @@ def test_repo_add_failure(qapp, qtbot, borg_json_output):
103107
add_repo_window = tab._window
104108
qtbot.addWidget(add_repo_window)
105109

106-
# Add repo with invalid URL
110+
# add repo with invalid URL
107111
qtbot.keyClicks(add_repo_window.repoURL, 'aaa')
108112
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
109113
assert add_repo_window.errorText.text().startswith('Please enter a valid repo URL')
@@ -114,10 +118,10 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
114118
tab = main.repoTab
115119
tab.add_repo()
116120
add_repo_window = tab._window
117-
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
121+
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # random repo URL to avoid macOS keychain
118122
test_repo_name = 'Test Repo'
119123

120-
# Enter valid repo URL, name, and password
124+
# enter valid repo URL, name, and password
121125
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
122126
qtbot.keyClicks(add_repo_window.repoName, test_repo_name)
123127
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, LONG_PASSWORD)
@@ -153,16 +157,16 @@ def test_ssh_dialog_success(qapp, qtbot, mocker, tmpdir):
153157
ssh_dialog.outputFileTextBox.setText(key_tmpfile_full)
154158
ssh_dialog.generate_key()
155159

156-
# Ensure new key file was created
160+
# Ensures new key file was created
157161
qtbot.waitUntil(lambda: ssh_dialog_closed.called, **pytest._wait_defaults)
158162
assert len(ssh_dir.listdir()) == 2
159163

160-
# Ensure new key is populated in SSH combobox
164+
# Ensures new key is populated in SSH combobox
161165
mocker.patch('os.path.expanduser', return_value=str(tmpdir))
162166
tab.init_ssh()
163167
assert tab.sshComboBox.count() == 2
164168

165-
# Ensure valid keys were created
169+
# Ensures valid keys were created
166170
key_tmpfile_content = key_tmpfile.read()
167171
assert key_tmpfile_content.startswith('-----BEGIN OPENSSH PRIVATE KEY-----')
168172
pub_tmpfile_content = pub_tmpfile.read()
@@ -186,10 +190,10 @@ def test_ssh_dialog_failure(qapp, qtbot, mocker, monkeypatch, tmpdir):
186190
qtbot.waitUntil(lambda: failure_message.called, **pytest._wait_defaults)
187191
failure_message.assert_called_once()
188192

189-
# Ensure no new ney file was created
193+
# Ensures no new ney file was created
190194
assert len(ssh_dir.listdir()) == 0
191195

192-
# Ensure no new key file in combo box
196+
# Ensures no new key file in combo box
193197
mocker.patch('os.path.expanduser', return_value=str(tmpdir))
194198
tab.init_ssh()
195199
assert tab.sshComboBox.count() == 1
@@ -288,7 +292,7 @@ def test_create(qapp, borg_json_output, mocker, qtbot):
288292
"icon": QMessageBox.Icon.Critical,
289293
"info": "The process running the check job got a kill signal. Try again.",
290294
},
291-
{"return_code": 130, "error": "", "icon": None, "info": None}, # keyboard interrupt
295+
{"return_code": 130, "error": "", "icon": None, "info": None},
292296
],
293297
)
294298
def test_repo_check_failed_response(qapp, qtbot, mocker, response):
@@ -450,7 +454,7 @@ def test_add_repo_other_error_no_init_offer(qapp, qtbot, mocker):
450454
window._probe_result(result)
451455

452456
mock_question.assert_not_called()
453-
assert window.errorText.text() == 'Unable to add your repository.'
457+
assert window.errorText.text() == 'Connection refused'
454458

455459

456460
def test_add_repo_probe_succeeds_connects(qapp, qtbot):

0 commit comments

Comments
 (0)