|
| 1 | +"""Unit tests for Client initialization""" |
| 2 | +import pytest |
| 3 | +from terminusdb_client.client import Client |
| 4 | +from terminusdb_client.errors import InterfaceError |
| 5 | + |
| 6 | + |
| 7 | +class TestClientInitialization: |
| 8 | + """Test Client initialization and basic properties""" |
| 9 | + |
| 10 | + def test_client_init_basic(self): |
| 11 | + """Test basic Client initialization""" |
| 12 | + client = Client("http://localhost:6363") |
| 13 | + assert client.server_url == "http://localhost:6363" |
| 14 | + assert client._connected is False |
| 15 | + |
| 16 | + def test_client_init_with_user_agent(self): |
| 17 | + """Test Client initialization with custom user agent""" |
| 18 | + client = Client("http://localhost:6363", user_agent="test-agent/1.0") |
| 19 | + assert "test-agent/1.0" in client._default_headers.get("user-agent", "") |
| 20 | + |
| 21 | + def test_client_init_with_trailing_slash(self): |
| 22 | + """Test Client handles URLs with trailing slashes""" |
| 23 | + client = Client("http://localhost:6363/") |
| 24 | + # Should work without errors |
| 25 | + assert client.server_url in ["http://localhost:6363", "http://localhost:6363/"] |
| 26 | + |
| 27 | + def test_client_copy(self): |
| 28 | + """Test Client copy method creates independent instance""" |
| 29 | + client1 = Client("http://localhost:6363") |
| 30 | + client1.team = "test_team" |
| 31 | + client1.db = "test_db" |
| 32 | + |
| 33 | + client2 = client1.copy() |
| 34 | + |
| 35 | + assert client2.server_url == client1.server_url |
| 36 | + assert client2.team == client1.team |
| 37 | + assert client2.db == client1.db |
| 38 | + # Ensure it's a different object |
| 39 | + assert client2 is not client1 |
| 40 | + |
| 41 | + def test_client_copy_modifications_independent(self): |
| 42 | + """Test modifications to copied client don't affect original""" |
| 43 | + client1 = Client("http://localhost:6363") |
| 44 | + client1.team = "team1" |
| 45 | + |
| 46 | + client2 = client1.copy() |
| 47 | + client2.team = "team2" |
| 48 | + |
| 49 | + assert client1.team == "team1" |
| 50 | + assert client2.team == "team2" |
0 commit comments