|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
7 | | -from openadr3_client.base import BaseClient |
| 7 | +from openadr3_client.base import DEFAULT_USER_AGENT, BaseClient |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class TestBaseClientLifecycle: |
@@ -121,3 +121,33 @@ def test_raises_attribute_error_unknown(self, mock_create): |
121 | 121 | c.start() |
122 | 122 | with pytest.raises(AttributeError): |
123 | 123 | c.totally_fake_method() |
| 124 | + |
| 125 | + |
| 126 | +class TestBaseClientUserAgent: |
| 127 | + def test_default_user_agent(self): |
| 128 | + c = BaseClient(url="http://test", token="tok") |
| 129 | + assert c.user_agent == DEFAULT_USER_AGENT |
| 130 | + assert "python-oa3-client/" in c.user_agent |
| 131 | + assert "openadr3/" in c.user_agent |
| 132 | + |
| 133 | + def test_custom_user_agent_appended(self): |
| 134 | + c = BaseClient(url="http://test", token="tok", user_agent="my-app/1.0") |
| 135 | + assert c.user_agent.startswith("python-oa3-client/") |
| 136 | + assert c.user_agent.endswith("my-app/1.0") |
| 137 | + assert "openadr3/" in c.user_agent |
| 138 | + |
| 139 | + @patch("openadr3_client.base.create_ven_client") |
| 140 | + def test_user_agent_passed_to_factory(self, mock_create): |
| 141 | + mock_create.return_value = MagicMock() |
| 142 | + c = BaseClient(url="http://test", token="tok", user_agent="my-app/2.0") |
| 143 | + c.start() |
| 144 | + call_kwargs = mock_create.call_args[1] |
| 145 | + assert call_kwargs["user_agent"] == c.user_agent |
| 146 | + |
| 147 | + @patch("openadr3_client.base.create_ven_client") |
| 148 | + def test_default_user_agent_passed_to_factory(self, mock_create): |
| 149 | + mock_create.return_value = MagicMock() |
| 150 | + c = BaseClient(url="http://test", token="tok") |
| 151 | + c.start() |
| 152 | + call_kwargs = mock_create.call_args[1] |
| 153 | + assert call_kwargs["user_agent"] == DEFAULT_USER_AGENT |
0 commit comments