Skip to content

Commit b2a1490

Browse files
author
smkc
committed
test: fix lint issues in coverage tests
1 parent 28a9db2 commit b2a1490

4 files changed

Lines changed: 74 additions & 27 deletions

File tree

tests/cli/unit/test_auth_manager.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ def test_resolve_base_url_falls_back_when_profile_base_url_empty(monkeypatch) ->
244244

245245

246246
def test_resolve_lighthouse_base_url_prefers_explicit_value() -> None:
247-
assert manager.resolve_lighthouse_base_url(" https://api-latarnia-test.ksef.mf.gov.pl/ ") == (
248-
"https://api-latarnia-test.ksef.mf.gov.pl/"
249-
).strip()
247+
assert (
248+
manager.resolve_lighthouse_base_url(" https://api-latarnia-test.ksef.mf.gov.pl/ ")
249+
== ("https://api-latarnia-test.ksef.mf.gov.pl/").strip()
250+
)
250251

251252

252253
def test_resolve_lighthouse_base_url_uses_profile_mapping(monkeypatch) -> None:
@@ -548,11 +549,19 @@ def test_login_with_xades_loader_errors_are_mapped(monkeypatch) -> None:
548549
def test_login_with_token_without_save(monkeypatch) -> None:
549550
monkeypatch.setattr(manager, "create_client", lambda base_url: _FakeClient())
550551
monkeypatch.setattr(manager, "AuthCoordinator", _FakeAuthCoordinator)
551-
monkeypatch.setattr(manager, "save_tokens", lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("save_tokens should not be called")))
552+
monkeypatch.setattr(
553+
manager,
554+
"save_tokens",
555+
lambda *args, **kwargs: (_ for _ in ()).throw(
556+
AssertionError("save_tokens should not be called")
557+
),
558+
)
552559
monkeypatch.setattr(
553560
manager,
554561
"set_cached_metadata",
555-
lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("set_cached_metadata should not be called")),
562+
lambda *args, **kwargs: (_ for _ in ()).throw(
563+
AssertionError("set_cached_metadata should not be called")
564+
),
556565
)
557566

558567
result = manager.login_with_token(
@@ -574,12 +583,16 @@ def test_refresh_access_token_success_without_save(monkeypatch) -> None:
574583
monkeypatch.setattr(
575584
manager,
576585
"save_tokens",
577-
lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("save_tokens should not be called")),
586+
lambda *args, **kwargs: (_ for _ in ()).throw(
587+
AssertionError("save_tokens should not be called")
588+
),
578589
)
579590
monkeypatch.setattr(
580591
manager,
581592
"set_cached_metadata",
582-
lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("set_cached_metadata should not be called")),
593+
lambda *args, **kwargs: (_ for _ in ()).throw(
594+
AssertionError("set_cached_metadata should not be called")
595+
),
583596
)
584597

585598
result = manager.refresh_access_token(

tests/cli/unit/test_sdk_adapters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,10 @@ def close_session(self, reference_number, access_token):
24712471
monkeypatch.setattr(
24722472
adapters,
24732473
"_wait_for_invoice_status",
2474-
lambda **kwargs: {"status": {"code": 200, "description": "Accepted"}, "ksefNumber": "KSEF-X"},
2474+
lambda **kwargs: {
2475+
"status": {"code": 200, "description": "Accepted"},
2476+
"ksefNumber": "KSEF-X",
2477+
},
24752478
)
24762479

24772480
invoice_path = tmp_path / "invoice.xml"

tests/test_clients.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def test_auth_client(self):
7979

8080
def test_auth_client_get_active_sessions_without_optional_filters(self):
8181
client = AuthClient(self.http)
82-
with patch.object(client, "_request_json", Mock(return_value={"ok": True})) as request_json_mock:
82+
with patch.object(
83+
client, "_request_json", Mock(return_value={"ok": True})
84+
) as request_json_mock:
8385
client.get_active_sessions(continuation_token="", access_token="token")
8486
self.assertIsNone(request_json_mock.call_args.kwargs["headers"])
8587
self.assertIsNone(request_json_mock.call_args.kwargs["params"])
@@ -123,7 +125,9 @@ def test_sessions_client(self):
123125

124126
def test_sessions_client_without_optional_filters(self):
125127
client = SessionsClient(self.http)
126-
with patch.object(client, "_request_json", Mock(return_value={"ok": True})) as request_json_mock:
128+
with patch.object(
129+
client, "_request_json", Mock(return_value={"ok": True})
130+
) as request_json_mock:
127131
client.get_sessions(
128132
session_type="online",
129133
continuation_token="",
@@ -137,12 +141,16 @@ def test_sessions_client_without_optional_filters(self):
137141
statuses=[],
138142
access_token="token",
139143
)
140-
self.assertEqual(request_json_mock.call_args.kwargs["params"], {"sessionType": "online"})
144+
self.assertEqual(
145+
request_json_mock.call_args.kwargs["params"], {"sessionType": "online"}
146+
)
141147
self.assertIsNone(request_json_mock.call_args.kwargs["headers"])
142148

143149
def test_sessions_client_without_upo_feature_and_pagination(self):
144150
client = SessionsClient(self.http)
145-
with patch.object(client, "_request_json", Mock(return_value={"ok": True})) as request_json_mock:
151+
with patch.object(
152+
client, "_request_json", Mock(return_value={"ok": True})
153+
) as request_json_mock:
146154
client.open_online_session({"a": 1}, access_token="token")
147155
client.open_batch_session({"a": 1}, access_token="token")
148156
client.get_session_invoices("ref", continuation_token="", access_token="token")
@@ -219,7 +227,9 @@ def test_invoices_client(self):
219227

220228
def test_invoices_client_query_metadata_without_optional_params(self):
221229
client = InvoicesClient(self.http)
222-
with patch.object(client, "_request_json", Mock(return_value={"ok": True})) as request_json_mock:
230+
with patch.object(
231+
client, "_request_json", Mock(return_value={"ok": True})
232+
) as request_json_mock:
223233
client.query_invoice_metadata({"subjectType": "Subject1"}, access_token="token")
224234
self.assertIsNone(request_json_mock.call_args.kwargs["params"])
225235

@@ -294,7 +304,9 @@ def test_certificates_client(self):
294304

295305
def test_certificates_client_query_without_pagination(self):
296306
client = CertificatesClient(self.http)
297-
with patch.object(client, "_request_json", Mock(return_value={"ok": True})) as request_json_mock:
307+
with patch.object(
308+
client, "_request_json", Mock(return_value={"ok": True})
309+
) as request_json_mock:
298310
client.query_certificates({"a": 1}, access_token="token")
299311
self.assertIsNone(request_json_mock.call_args.kwargs["params"])
300312

@@ -316,7 +328,9 @@ def test_tokens_client(self):
316328

317329
def test_tokens_client_list_tokens_without_optional_filters(self):
318330
client = TokensClient(self.http)
319-
with patch.object(client, "_request_json", Mock(return_value={"ok": True})) as request_json_mock:
331+
with patch.object(
332+
client, "_request_json", Mock(return_value={"ok": True})
333+
) as request_json_mock:
320334
client.list_tokens(
321335
access_token="token",
322336
statuses=[],
@@ -371,7 +385,9 @@ def test_peppol_client(self):
371385

372386
def test_peppol_client_without_pagination(self):
373387
client = PeppolClient(self.http)
374-
with patch.object(client, "_request_json", Mock(return_value={"ok": True})) as request_json_mock:
388+
with patch.object(
389+
client, "_request_json", Mock(return_value={"ok": True})
390+
) as request_json_mock:
375391
client.list_providers()
376392
self.assertIsNone(request_json_mock.call_args.kwargs["params"])
377393

@@ -652,7 +668,9 @@ async def test_async_tokens_client_list_tokens_without_optional_filters(self):
652668
http = DummyAsyncHttp(response)
653669
payload = {"a": 1}
654670
tokens = AsyncTokensClient(http)
655-
with patch.object(tokens, "_request_json", AsyncMock(return_value={"ok": True})) as request_json_mock:
671+
with patch.object(
672+
tokens, "_request_json", AsyncMock(return_value={"ok": True})
673+
) as request_json_mock:
656674
await tokens.list_tokens(
657675
access_token="token",
658676
statuses=[],
@@ -705,15 +723,19 @@ async def test_async_peppol_client_without_pagination(self):
705723
response = HttpResponse(200, httpx.Headers({}), b"{}")
706724
http = DummyAsyncHttp(response)
707725
peppol = AsyncPeppolClient(http)
708-
with patch.object(peppol, "_request_json", AsyncMock(return_value={"ok": True})) as request_json_mock:
726+
with patch.object(
727+
peppol, "_request_json", AsyncMock(return_value={"ok": True})
728+
) as request_json_mock:
709729
await peppol.list_providers()
710730
self.assertIsNone(request_json_mock.call_args.kwargs["params"])
711731

712732
async def test_async_auth_client_get_active_sessions_without_optional_filters(self):
713733
response = HttpResponse(200, httpx.Headers({}), b"{}")
714734
http = DummyAsyncHttp(response)
715735
auth = AsyncAuthClient(http)
716-
with patch.object(auth, "_request_json", AsyncMock(return_value={"ok": True})) as request_json_mock:
736+
with patch.object(
737+
auth, "_request_json", AsyncMock(return_value={"ok": True})
738+
) as request_json_mock:
717739
await auth.get_active_sessions(continuation_token="", access_token="token")
718740
self.assertIsNone(request_json_mock.call_args.kwargs["headers"])
719741
self.assertIsNone(request_json_mock.call_args.kwargs["params"])
@@ -732,15 +754,19 @@ async def test_async_invoices_client_query_metadata_without_optional_params(self
732754
response = HttpResponse(200, httpx.Headers({}), b"{}")
733755
http = DummyAsyncHttp(response)
734756
invoices = AsyncInvoicesClient(http)
735-
with patch.object(invoices, "_request_json", AsyncMock(return_value={"ok": True})) as request_json_mock:
757+
with patch.object(
758+
invoices, "_request_json", AsyncMock(return_value={"ok": True})
759+
) as request_json_mock:
736760
await invoices.query_invoice_metadata({"subjectType": "Subject1"}, access_token="token")
737761
self.assertIsNone(request_json_mock.call_args.kwargs["params"])
738762

739763
async def test_async_sessions_client_without_optional_filters(self):
740764
response = HttpResponse(200, httpx.Headers({}), b"{}")
741765
http = DummyAsyncHttp(response)
742766
sessions = AsyncSessionsClient(http)
743-
with patch.object(sessions, "_request_json", AsyncMock(return_value={"ok": True})) as request_json_mock:
767+
with patch.object(
768+
sessions, "_request_json", AsyncMock(return_value={"ok": True})
769+
) as request_json_mock:
744770
await sessions.get_sessions(
745771
session_type="online",
746772
continuation_token="",
@@ -754,18 +780,24 @@ async def test_async_sessions_client_without_optional_filters(self):
754780
statuses=[],
755781
access_token="token",
756782
)
757-
self.assertEqual(request_json_mock.call_args.kwargs["params"], {"sessionType": "online"})
783+
self.assertEqual(
784+
request_json_mock.call_args.kwargs["params"], {"sessionType": "online"}
785+
)
758786
self.assertIsNone(request_json_mock.call_args.kwargs["headers"])
759787

760788
async def test_async_sessions_client_without_upo_feature_and_pagination(self):
761789
response = HttpResponse(200, httpx.Headers({}), b"{}")
762790
http = DummyAsyncHttp(response)
763791
sessions = AsyncSessionsClient(http)
764-
with patch.object(sessions, "_request_json", AsyncMock(return_value={"ok": True})) as request_json_mock:
792+
with patch.object(
793+
sessions, "_request_json", AsyncMock(return_value={"ok": True})
794+
) as request_json_mock:
765795
await sessions.open_online_session({"a": 1}, access_token="token")
766796
await sessions.open_batch_session({"a": 1}, access_token="token")
767797
await sessions.get_session_invoices("ref", continuation_token="", access_token="token")
768-
await sessions.get_session_failed_invoices("ref", continuation_token="", access_token="token")
798+
await sessions.get_session_failed_invoices(
799+
"ref", continuation_token="", access_token="token"
800+
)
769801

770802
self.assertIsNone(request_json_mock.call_args_list[0].kwargs["headers"])
771803
self.assertIsNone(request_json_mock.call_args_list[1].kwargs["headers"])

tests/test_openapi_models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import json
2-
from typing import List
32
import unittest
4-
from unittest.mock import patch
53
from pathlib import Path
4+
from unittest.mock import patch
65

76
from ksef_client import openapi_models as m
87

@@ -119,7 +118,7 @@ def test_part_upload_request_headers_keep_non_string_values(self):
119118
self.assertEqual(parsed.to_dict()["headers"], payload["headers"])
120119

121120
def test_convert_value_handles_unsubscripted_list_hint(self):
122-
self.assertEqual(m._convert_value(List, ["a", "b"]), ["a", "b"])
121+
self.assertEqual(m._convert_value(list, ["a", "b"]), ["a", "b"])
123122

124123
def test_convert_value_openapi_model_non_dict_returns_raw_value(self):
125124
self.assertEqual(m._convert_value(m.AuthenticationListItem, "raw"), "raw")

0 commit comments

Comments
 (0)