|
| 1 | +"""Tests for client management (add, status, settings, authkey).""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +class TestAddClient: |
| 7 | + |
| 8 | + def test_add_client(self, server): |
| 9 | + ret = server.add_client("pytest-client-1") |
| 10 | + assert ret is not None |
| 11 | + assert ret["added_new_client"] is True |
| 12 | + assert "new_authkey" in ret |
| 13 | + assert ret["new_clientname"] == "pytest-client-1" |
| 14 | + |
| 15 | + def test_add_client_duplicate_returns_none(self, server): |
| 16 | + server.add_client("pytest-dup") |
| 17 | + ret = server.add_client("pytest-dup") |
| 18 | + assert ret is None |
| 19 | + |
| 20 | + def test_add_client_with_group(self, server): |
| 21 | + ret = server.add_client("pytest-grouped", groupname="testgroup") |
| 22 | + assert ret is not None |
| 23 | + assert ret["added_new_client"] is True |
| 24 | + |
| 25 | + |
| 26 | +class TestGetClientStatus: |
| 27 | + |
| 28 | + @pytest.fixture(autouse=True) |
| 29 | + def _create_client(self, server): |
| 30 | + server.add_client("pytest-status-client") |
| 31 | + |
| 32 | + def test_get_client_status(self, server): |
| 33 | + status = server.get_client_status("pytest-status-client") |
| 34 | + assert status is not None |
| 35 | + assert status["name"] == "pytest-status-client" |
| 36 | + assert "id" in status |
| 37 | + |
| 38 | + def test_get_client_status_nonexistent(self, server): |
| 39 | + status = server.get_client_status("nonexistent-client-xyz") |
| 40 | + assert status is None |
| 41 | + |
| 42 | + def test_client_appears_in_status_list(self, server): |
| 43 | + all_status = server.get_status() |
| 44 | + names = [c["name"] for c in all_status] |
| 45 | + assert "pytest-status-client" in names |
| 46 | + |
| 47 | + |
| 48 | +class TestClientSettings: |
| 49 | + |
| 50 | + @pytest.fixture(autouse=True) |
| 51 | + def _create_client(self, server): |
| 52 | + server.add_client("pytest-settings-client") |
| 53 | + |
| 54 | + def test_get_client_settings(self, server): |
| 55 | + settings = server.get_client_settings("pytest-settings-client") |
| 56 | + assert settings is not None |
| 57 | + assert isinstance(settings, dict) |
| 58 | + assert "internet_authkey" in settings |
| 59 | + |
| 60 | + def test_get_client_settings_nonexistent(self, server): |
| 61 | + settings = server.get_client_settings("nonexistent-client-xyz") |
| 62 | + assert settings is None |
| 63 | + |
| 64 | + def test_change_client_setting(self, server): |
| 65 | + result = server.change_client_setting( |
| 66 | + "pytest-settings-client", "internet_authkey", "my-custom-key" |
| 67 | + ) |
| 68 | + assert result is True |
| 69 | + |
| 70 | + authkey = server.get_client_authkey("pytest-settings-client") |
| 71 | + assert authkey is not None |
| 72 | + assert authkey["value"] == "my-custom-key" |
| 73 | + |
| 74 | + |
| 75 | +class TestClientAuthkey: |
| 76 | + |
| 77 | + @pytest.fixture(autouse=True) |
| 78 | + def _create_client(self, server): |
| 79 | + server.add_client("pytest-authkey-client") |
| 80 | + |
| 81 | + def test_get_client_authkey(self, server): |
| 82 | + authkey = server.get_client_authkey("pytest-authkey-client") |
| 83 | + assert authkey is not None |
| 84 | + |
| 85 | + def test_get_client_authkey_nonexistent(self, server): |
| 86 | + authkey = server.get_client_authkey("nonexistent-client-xyz") |
| 87 | + assert authkey is None |
0 commit comments