|
1 | | -import platform |
| 1 | +import pytest |
2 | 2 | from unittest import TestCase |
3 | 3 |
|
4 | | -import pytest |
5 | | -from unittest import mock |
6 | 4 | from alma import ApiModes, Client |
7 | 5 | from alma.credentials import ApiKeyCredentials, MerchantIdCredentials, AlmaSessionCredentials |
8 | | -from alma.request import Request |
9 | | -from alma.version import __version__ as alma_version |
10 | 6 |
|
11 | 7 |
|
12 | 8 | class ClientTest(TestCase): |
@@ -94,102 +90,3 @@ def test_client_expose_endpoints(self): |
94 | 90 |
|
95 | 91 | # Exposed but empty |
96 | 92 | assert alma_client.merchants |
97 | | - |
98 | | - |
99 | | -class ContextTest(TestCase): |
100 | | - def setUp(self): |
101 | | - client = Client.with_api_key("sk_live_3geNR4OVI0gQGCAKgcYqQs2I") |
102 | | - self.context = client.context |
103 | | - |
104 | | - def test_context_expose_logger(self): |
105 | | - assert self.context.logger.name == "alma-python-client" |
106 | | - assert self.context.logger.level == 0 |
107 | | - |
108 | | - def test_context_expose_api_root_and_mode(self): |
109 | | - assert self.context.api_root == self.context.options["api_root"] |
110 | | - assert self.context.mode == self.context.options["mode"] |
111 | | - |
112 | | - def test_context_expose_url_for(self): |
113 | | - assert self.context.url_for("/path/test") == "https://api.getalma.eu/path/test" |
114 | | - |
115 | | - def test_context_expose_user_agent_string(self): |
116 | | - assert self.context.user_agent_string().startswith( |
117 | | - "alma-client/{alma_version}; Python/{python_version}".format( |
118 | | - alma_version=alma_version, python_version=platform.python_version() |
119 | | - ) |
120 | | - ) |
121 | | - |
122 | | - def test_context_exposes_credentials(self): |
123 | | - assert self.context.credentials |
124 | | - |
125 | | - |
126 | | -class RequestTest(TestCase): |
127 | | - def setUp(self) -> None: |
128 | | - client = Client.with_api_key("sk_test_3geNR4OVI0gQGCAKgcYqQs2I") |
129 | | - self.credentials = client.context.credentials |
130 | | - self.request = Request(client.context, "https://url.com") |
131 | | - |
132 | | - def assert_method_calls_configure(self, method): |
133 | | - with mock.patch( |
134 | | - "alma.credentials.ApiKeyCredentials.configure" |
135 | | - ) as mocked_configure, mock.patch("alma.request.requests"): |
136 | | - getattr(self.request, method)() |
137 | | - mocked_configure.assert_called_once_with(self.request) |
138 | | - |
139 | | - def test_credentials_configure_is_called_on_get(self): |
140 | | - self.assert_method_calls_configure("get") |
141 | | - |
142 | | - def test_credentials_configure_is_called_on_post(self): |
143 | | - self.assert_method_calls_configure("post") |
144 | | - |
145 | | - def test_credentials_configure_is_called_on_put(self): |
146 | | - self.assert_method_calls_configure("put") |
147 | | - |
148 | | - |
149 | | -class ApiKeyCredentialsTest(TestCase): |
150 | | - def setUp(self) -> None: |
151 | | - self.api_key = "sk_test_3geNR4OVI0gQGCAKgcYqQs2I" |
152 | | - client = Client.with_api_key(self.api_key) |
153 | | - |
154 | | - self.credentials = client.context.credentials |
155 | | - self.request = Request(client.context, "https://url.com") |
156 | | - |
157 | | - def test_it_adds_authentication_header(self): |
158 | | - self.credentials.configure(self.request) |
159 | | - assert "Authorization" in self.request.headers |
160 | | - assert self.request.headers["Authorization"] == "Alma-Auth {api_key}".format( |
161 | | - api_key=self.api_key |
162 | | - ) |
163 | | - |
164 | | - |
165 | | -class MerchantIdCredentialsTest(TestCase): |
166 | | - def setUp(self) -> None: |
167 | | - self.merchant_id = "merchant" |
168 | | - client = Client.with_merchant_id(self.merchant_id) |
169 | | - |
170 | | - self.credentials = client.context.credentials |
171 | | - self.request = Request(client.context, "https://url.com") |
172 | | - |
173 | | - def test_it_adds_authentication_header(self): |
174 | | - self.credentials.configure(self.request) |
175 | | - |
176 | | - assert "Authorization" in self.request.headers |
177 | | - assert self.request.headers["Authorization"] == "Alma-Merchant-Auth {merchant_id}".format( |
178 | | - merchant_id=self.merchant_id |
179 | | - ) |
180 | | - |
181 | | - |
182 | | -class AlmaSessionCredentialsTest(TestCase): |
183 | | - def setUp(self) -> None: |
184 | | - self.session_id = "1234567890" |
185 | | - self.cookie_name = "alma_session" |
186 | | - client = Client.with_alma_session(self.session_id, self.cookie_name) |
187 | | - |
188 | | - self.credentials = client.context.credentials |
189 | | - self.request = Request(client.context, "https://url.com") |
190 | | - |
191 | | - def test_it_adds_authentication_header(self): |
192 | | - self.credentials.configure(self.request) |
193 | | - |
194 | | - assert self.cookie_name in self.request.cookies |
195 | | - assert self.request.cookies[self.cookie_name] == self.session_id |
0 commit comments