Skip to content

Commit be3e918

Browse files
Address PR review feedback on unified dialog
1 parent 3100427 commit be3e918

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):
@@ -132,7 +136,7 @@ def test_repo_add_failure(qapp, qtbot, borg_json_output):
132136
add_repo_window = tab._window
133137
qtbot.addWidget(add_repo_window)
134138

135-
# Add repo with invalid URL
139+
# add repo with invalid URL
136140
qtbot.keyClicks(add_repo_window.repoURL, 'aaa')
137141
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
138142
assert add_repo_window.errorText.text().startswith('Please enter a valid repo URL')
@@ -143,10 +147,10 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
143147
tab = main.repoTab
144148
tab.add_repo()
145149
add_repo_window = tab._window
146-
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
150+
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # random repo URL to avoid macOS keychain
147151
test_repo_name = 'Test Repo'
148152

149-
# Enter valid repo URL, name, and password
153+
# enter valid repo URL, name, and password
150154
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
151155
qtbot.keyClicks(add_repo_window.repoName, test_repo_name)
152156
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, LONG_PASSWORD)
@@ -182,16 +186,16 @@ def test_ssh_dialog_success(qapp, qtbot, mocker, tmpdir):
182186
ssh_dialog.outputFileTextBox.setText(key_tmpfile_full)
183187
ssh_dialog.generate_key()
184188

185-
# Ensure new key file was created
189+
# Ensures new key file was created
186190
qtbot.waitUntil(lambda: ssh_dialog_closed.called, **pytest._wait_defaults)
187191
assert len(ssh_dir.listdir()) == 2
188192

189-
# Ensure new key is populated in SSH combobox
193+
# Ensures new key is populated in SSH combobox
190194
mocker.patch('os.path.expanduser', return_value=str(tmpdir))
191195
tab.init_ssh()
192196
assert tab.sshComboBox.count() == 2
193197

194-
# Ensure valid keys were created
198+
# Ensures valid keys were created
195199
key_tmpfile_content = key_tmpfile.read()
196200
assert key_tmpfile_content.startswith('-----BEGIN OPENSSH PRIVATE KEY-----')
197201
pub_tmpfile_content = pub_tmpfile.read()
@@ -215,10 +219,10 @@ def test_ssh_dialog_failure(qapp, qtbot, mocker, monkeypatch, tmpdir):
215219
qtbot.waitUntil(lambda: failure_message.called, **pytest._wait_defaults)
216220
failure_message.assert_called_once()
217221

218-
# Ensure no new ney file was created
222+
# Ensures no new ney file was created
219223
assert len(ssh_dir.listdir()) == 0
220224

221-
# Ensure no new key file in combo box
225+
# Ensures no new key file in combo box
222226
mocker.patch('os.path.expanduser', return_value=str(tmpdir))
223227
tab.init_ssh()
224228
assert tab.sshComboBox.count() == 1
@@ -317,7 +321,7 @@ def test_create(qapp, borg_json_output, mocker, qtbot):
317321
"icon": QMessageBox.Icon.Critical,
318322
"info": "The process running the check job got a kill signal. Try again.",
319323
},
320-
{"return_code": 130, "error": "", "icon": None, "info": None}, # keyboard interrupt
324+
{"return_code": 130, "error": "", "icon": None, "info": None},
321325
],
322326
)
323327
def test_repo_check_failed_response(qapp, qtbot, mocker, response):
@@ -479,7 +483,7 @@ def test_add_repo_other_error_no_init_offer(qapp, qtbot, mocker):
479483
window._probe_result(result)
480484

481485
mock_question.assert_not_called()
482-
assert window.errorText.text() == 'Unable to add your repository.'
486+
assert window.errorText.text() == 'Connection refused'
483487

484488

485489
def test_add_repo_probe_succeeds_connects(qapp, qtbot):

0 commit comments

Comments
 (0)