Improve server management.
This commit is contained in:
1 parent
47854c46ec
commit
7dc2a4e2d8
6 files changed
+174
-25
No files matched your search
@@ -15,6 +15,7 @@ from src.config.settings import Settings
|
||||
from src.widgets.server_dialog import ServerDialog
|
||||
from src.widgets.server_management_dialog import ServerManagementDialog
|
||||
import src.widgets.server_management_dialog as server_management_dialog_module
|
||||
import src.widgets.server_dialog as server_dialog_module
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -70,6 +71,41 @@ def test_edit_server_can_clear_default(qt_app):
|
||||
assert settings.getDefaultServer() is None
|
||||
|
||||
|
||||
def test_server_dialog_rejects_invalid_url(qt_app, monkeypatch):
|
||||
settings = Settings()
|
||||
dialog = ServerDialog(settings)
|
||||
monkeypatch.setattr(QMessageBox, "warning", lambda *args, **kwargs: None)
|
||||
|
||||
dialog.nameEdit.setText("Primary")
|
||||
dialog.urlEdit.setText("music.example.com")
|
||||
dialog.usernameEdit.setText("Username")
|
||||
dialog.passwordEdit.setText("password")
|
||||
dialog.saveServer()
|
||||
|
||||
assert dialog.result() != QDialog.Accepted
|
||||
assert settings.getServers() == {}
|
||||
assert dialog.focusWidget() is dialog.urlEdit
|
||||
|
||||
|
||||
def test_server_dialog_test_rejects_invalid_url_without_network(qt_app, monkeypatch):
|
||||
settings = Settings()
|
||||
dialog = ServerDialog(settings)
|
||||
|
||||
def unexpected_client(*args, **kwargs):
|
||||
raise AssertionError("Connection test should validate before creating a client")
|
||||
|
||||
monkeypatch.setattr(server_dialog_module, "SubsonicClient", unexpected_client)
|
||||
dialog.urlEdit.setText("ftp://music.example.com")
|
||||
dialog.usernameEdit.setText("Username")
|
||||
dialog.passwordEdit.setText("password")
|
||||
|
||||
dialog.testConnection()
|
||||
|
||||
assert dialog.testButton.isEnabled()
|
||||
assert dialog.statusLabel.text() == "Enter a valid server URL beginning with http:// or https://"
|
||||
assert dialog.focusWidget() is dialog.urlEdit
|
||||
|
||||
|
||||
def test_management_dialog_lists_default_and_selection_actions(qt_app):
|
||||
settings = make_settings()
|
||||
dialog = ServerManagementDialog(settings)
|
||||
@@ -106,6 +142,18 @@ def test_management_dialog_remove_confirmed_server(qt_app, monkeypatch):
|
||||
assert dialog.serverList.currentItem().data(Qt.UserRole) == "Backup"
|
||||
|
||||
|
||||
def test_management_dialog_remove_discards_edit_state(qt_app, monkeypatch):
|
||||
settings = make_settings()
|
||||
dialog = ServerManagementDialog(settings)
|
||||
dialog.editedServerNames.add("Primary")
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *args, **kwargs: QMessageBox.Yes)
|
||||
|
||||
dialog.removeSelected()
|
||||
|
||||
assert dialog.removedServerNames == {"Primary"}
|
||||
assert dialog.editedServerNames == set()
|
||||
|
||||
|
||||
def test_management_dialog_remove_canceled_server(qt_app, monkeypatch):
|
||||
settings = make_settings()
|
||||
dialog = ServerManagementDialog(settings)
|
||||
|
||||
Reference in new issue
Block a user