Skip to content

Commit 8c657ca

Browse files
committed
Refactor tests
1 parent e436230 commit 8c657ca

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

tests/test_api.py

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def setUpClass(cls):
1212
cls.cookie_jar.set("jwt", "placeholder_token_1")
1313
cls.cookie_jar.set("refreshToken", "placeholder_token_2")
1414

15-
@patch("loading_sdk.api.requests")
15+
@patch("loading_sdk.sync_api.client.requests")
1616
def test_authenticate_success(self, mock_requests):
1717
mock_response = MagicMock()
1818
mock_response.status_code = 200
@@ -30,7 +30,7 @@ def test_authenticate_success(self, mock_requests):
3030
self.assertEqual(response.get("code"), 200)
3131
self.assertEqual(response.get("cookies"), self.cookie_jar)
3232

33-
@patch("loading_sdk.api.requests")
33+
@patch("loading_sdk.sync_api.client.requests")
3434
def test_authenticate_failure_incorrect_email_or_password(self, mock_requests):
3535
status_code = 401
3636
expected_response = {
@@ -54,7 +54,7 @@ def test_authenticate_failure_incorrect_email_or_password(self, mock_requests):
5454
self.assertEqual(response.get("code"), 401)
5555
self.assertEqual(response.get("message"), "Incorrect email or password")
5656

57-
@patch("loading_sdk.api.requests")
57+
@patch("loading_sdk.sync_api.client.requests")
5858
def test_authenticate_failure_invalid_email(self, mock_requests):
5959
status_code = 400
6060
expected_response = {
@@ -86,7 +86,7 @@ def test_authenticate_failure_invalid_email(self, mock_requests):
8686
self.assertEqual(response.get("code"), 400)
8787
self.assertEqual(response.get("message"), "Validation error")
8888

89-
@patch("loading_sdk.api.requests")
89+
@patch("loading_sdk.sync_api.client.requests")
9090
def test_authenticate_failure_empty_values(self, mock_requests):
9191
status_code = 400
9292
expected_response = {
@@ -127,8 +127,8 @@ def test_authenticate_failure_empty_values(self, mock_requests):
127127
self.assertEqual(response.get("code"), 400)
128128
self.assertEqual(response.get("message"), "Validation error")
129129

130-
@patch("loading_sdk.api.LoadingApiClient._authenticate")
131-
@patch("loading_sdk.api.requests")
130+
@patch("loading_sdk.sync_api.LoadingApiClient._authenticate")
131+
@patch("loading_sdk.sync_api.client.requests")
132132
def test_get_profile_success(self, mock_requests, mock_authenticate):
133133
status_code = 200
134134
expected_response = {
@@ -154,7 +154,7 @@ def test_get_profile_success(self, mock_requests, mock_authenticate):
154154
self.assertEqual(response.get("message"), "OK")
155155
self.assertDictEqual(response.get("data"), expected_response)
156156

157-
@patch("loading_sdk.api.requests")
157+
@patch("loading_sdk.sync_api.client.requests")
158158
def test_get_profile_failure(self, mock_requests):
159159
status_code = 401
160160
expected_response = {"code": status_code, "message": "No auth token"}
@@ -172,7 +172,7 @@ def test_get_profile_failure(self, mock_requests):
172172
self.assertEqual(response.get("code"), 401)
173173
self.assertEqual(response.get("message"), "No auth token")
174174

175-
@patch("loading_sdk.api.requests")
175+
@patch("loading_sdk.sync_api.client.requests")
176176
def test_search_success(self, mock_requests):
177177
expected_response = {
178178
"posts": [
@@ -213,7 +213,7 @@ def test_search_success(self, mock_requests):
213213
self.assertEqual(response.get("message"), "OK")
214214
self.assertEqual(response.get("data"), expected_response)
215215

216-
@patch("loading_sdk.api.requests")
216+
@patch("loading_sdk.sync_api.client.requests")
217217
def test_search_success_no_results(self, mock_requests):
218218
expected_response = {"posts": [], "users": []}
219219

@@ -229,7 +229,7 @@ def test_search_success_no_results(self, mock_requests):
229229
self.assertEqual(response.get("message"), "No results")
230230
self.assertEqual(response.get("data"), expected_response)
231231

232-
@patch("loading_sdk.api.requests")
232+
@patch("loading_sdk.sync_api.client.requests")
233233
def test_search_failure_empty_query(self, mock_requests):
234234
status_code = 400
235235
expected_response = {
@@ -257,7 +257,7 @@ def test_search_failure_empty_query(self, mock_requests):
257257
self.assertEqual(response.get("message"), "Validation error")
258258
self.assertEqual(response, expected_response)
259259

260-
@patch("loading_sdk.api.requests")
260+
@patch("loading_sdk.sync_api.client.requests")
261261
def test_get_post_failure_empty_post_id(self, mock_requests):
262262
expected_response = {
263263
"code": 404,
@@ -277,7 +277,7 @@ def test_get_post_failure_empty_post_id(self, mock_requests):
277277
)
278278
self.assertEqual(response, expected_response)
279279

280-
@patch("loading_sdk.api.requests")
280+
@patch("loading_sdk.sync_api.client.requests")
281281
def test_get_post_failure_post_does_not_exist(self, mock_requests):
282282
expected_response = {"code": 404, "message": "Post does not exist"}
283283

@@ -293,7 +293,7 @@ def test_get_post_failure_post_does_not_exist(self, mock_requests):
293293
self.assertEqual(response.get("message"), "Post does not exist")
294294
self.assertEqual(response, expected_response)
295295

296-
@patch("loading_sdk.api.requests")
296+
@patch("loading_sdk.sync_api.client.requests")
297297
def test_get_post_success(self, mock_requests):
298298
status_code = 200
299299
expected_response = {
@@ -333,7 +333,7 @@ def test_get_post_success(self, mock_requests):
333333
self.assertEqual(response.get("message"), "OK")
334334
self.assertEqual(response.get("data"), expected_response)
335335

336-
@patch("loading_sdk.api.requests")
336+
@patch("loading_sdk.sync_api.client.requests")
337337
def test_get_thread_success(self, mock_requests):
338338
status_code = 200
339339
expected_response = {
@@ -390,7 +390,7 @@ def test_get_thread_success(self, mock_requests):
390390
self.assertEqual(response.get("message"), "OK")
391391
self.assertEqual(response.get("data"), expected_response)
392392

393-
@patch("loading_sdk.api.requests")
393+
@patch("loading_sdk.sync_api.client.requests")
394394
def test_get_thread_failure_empty_thread_id(self, mock_requests):
395395
status_code = 404
396396
expected_response = {
@@ -409,7 +409,7 @@ def test_get_thread_failure_empty_thread_id(self, mock_requests):
409409
self.assertEqual(response.get("code"), 404)
410410
self.assertEqual(response, expected_response)
411411

412-
@patch("loading_sdk.api.requests")
412+
@patch("loading_sdk.sync_api.client.requests")
413413
def test_get_thread_failure_not_a_thread_id(self, mock_requests):
414414
status_code = 200
415415
expected_response = {
@@ -452,7 +452,7 @@ def test_get_thread_failure_not_a_thread_id(self, mock_requests):
452452
self.assertEqual(response.get("code"), 200)
453453
self.assertEqual(response, expected_response)
454454

455-
@patch("loading_sdk.api.requests")
455+
@patch("loading_sdk.sync_api.client.requests")
456456
def test_get_thread_failure_does_not_exist(self, mock_requests):
457457
status_code = 404
458458
expected_response = {"code": status_code, "message": "Post does not exist"}
@@ -468,7 +468,7 @@ def test_get_thread_failure_does_not_exist(self, mock_requests):
468468
self.assertEqual(response.get("code"), 404)
469469
self.assertEqual(response, expected_response)
470470

471-
@patch("loading_sdk.api.requests")
471+
@patch("loading_sdk.sync_api.client.requests")
472472
def test_get_thread_failure_page_too_low(self, mock_requests):
473473
status_code = 200
474474
expected_response = {
@@ -514,7 +514,7 @@ def test_get_thread_failure_page_too_low(self, mock_requests):
514514
self.assertEqual(response.get("code"), 200)
515515
self.assertEqual(response, expected_response)
516516

517-
@patch("loading_sdk.api.requests")
517+
@patch("loading_sdk.sync_api.client.requests")
518518
def test_get_thread_failure_page_too_high(self, mock_requests):
519519
status_code = 200
520520
expected_response = {
@@ -561,7 +561,7 @@ def test_get_thread_failure_page_too_high(self, mock_requests):
561561
self.assertEqual(response.get("message"), "Page number too high")
562562
self.assertEqual(response, expected_response)
563563

564-
@patch("loading_sdk.api.requests")
564+
@patch("loading_sdk.sync_api.client.requests")
565565
def test_get_games_success(self, mock_requests):
566566
status_code = 200
567567
expected_response = {
@@ -945,7 +945,7 @@ def test_get_games_success(self, mock_requests):
945945

946946
self.assertDictEqual(response.get("data"), expected_response)
947947

948-
@patch("loading_sdk.api.requests")
948+
@patch("loading_sdk.sync_api.client.requests")
949949
def test_get_games_failure_page_too_low(self, mock_requests):
950950
status_code = 404
951951
expected_response = {
@@ -964,7 +964,7 @@ def test_get_games_failure_page_too_low(self, mock_requests):
964964

965965
self.assertDictEqual(response, expected_response)
966966

967-
@patch("loading_sdk.api.requests")
967+
@patch("loading_sdk.sync_api.client.requests")
968968
def test_get_games_failure_page_too_high(self, mock_requests):
969969
status_code = 404
970970
expected_response = {
@@ -983,7 +983,7 @@ def test_get_games_failure_page_too_high(self, mock_requests):
983983

984984
self.assertDictEqual(response, expected_response)
985985

986-
@patch("loading_sdk.api.requests")
986+
@patch("loading_sdk.sync_api.client.requests")
987987
def test_get_other_success(self, mock_requests):
988988
status_code = 200
989989
expected_response = {
@@ -1201,7 +1201,7 @@ def test_get_other_success(self, mock_requests):
12011201
for thread in threads:
12021202
self.assertEqual(thread.get("category"), "other")
12031203

1204-
@patch("loading_sdk.api.requests")
1204+
@patch("loading_sdk.sync_api.client.requests")
12051205
def test_get_other_failure_page_too_low(self, mock_requests):
12061206
status_code = 404
12071207
expected_response = {
@@ -1220,7 +1220,7 @@ def test_get_other_failure_page_too_low(self, mock_requests):
12201220

12211221
self.assertDictEqual(response, expected_response)
12221222

1223-
@patch("loading_sdk.api.requests")
1223+
@patch("loading_sdk.sync_api.client.requests")
12241224
def test_get_other_failure_page_too_high(self, mock_requests):
12251225
status_code = 404
12261226
expected_response = {
@@ -1239,7 +1239,7 @@ def test_get_other_failure_page_too_high(self, mock_requests):
12391239

12401240
self.assertDictEqual(response, expected_response)
12411241

1242-
@patch("loading_sdk.api.requests")
1242+
@patch("loading_sdk.sync_api.client.requests")
12431243
def test_get_editorials_success(self, mock_requests):
12441244
status_code = 200
12451245
expected_response = {
@@ -1546,7 +1546,7 @@ def test_get_editorials_success(self, mock_requests):
15461546
for thread in threads:
15471547
self.assertEqual(thread.get("postType"), "update")
15481548

1549-
@patch("loading_sdk.api.requests")
1549+
@patch("loading_sdk.sync_api.client.requests")
15501550
def test_get_editorials_failure_page_too_low(self, mock_requests):
15511551
status_code = 404
15521552
expected_response = {
@@ -1569,7 +1569,7 @@ def test_get_editorials_failure_page_too_low(self, mock_requests):
15691569

15701570
self.assertDictEqual(response, expected_response)
15711571

1572-
@patch("loading_sdk.api.requests")
1572+
@patch("loading_sdk.sync_api.client.requests")
15731573
def test_get_editorials_failure_page_too_high(self, mock_requests):
15741574
status_code = 404
15751575
expected_response = {
@@ -1592,8 +1592,8 @@ def test_get_editorials_failure_page_too_high(self, mock_requests):
15921592

15931593
self.assertDictEqual(response, expected_response)
15941594

1595-
@patch("loading_sdk.api.LoadingApiClient._authenticate")
1596-
@patch("loading_sdk.api.requests")
1595+
@patch("loading_sdk.sync_api.LoadingApiClient._authenticate")
1596+
@patch("loading_sdk.sync_api.client.requests")
15971597
def test_edit_post_success(self, mock_requests, mock_authenticate):
15981598
status_code = 200
15991599
expected_response = {
@@ -1639,7 +1639,7 @@ def test_edit_post_success(self, mock_requests, mock_authenticate):
16391639
self.assertEqual(response.get("code"), 200)
16401640
self.assertDictEqual(response.get("data"), expected_response)
16411641

1642-
@patch("loading_sdk.api.requests")
1642+
@patch("loading_sdk.sync_api.client.requests")
16431643
def test_edit_post_failure_no_auth_token(self, mock_requests):
16441644
status_code = 401
16451645
expected_response = {"code": status_code, "message": "No auth token"}
@@ -1664,7 +1664,7 @@ def test_edit_post_failure_no_auth_token(self, mock_requests):
16641664

16651665
self.assertEqual(response, expected_response)
16661666

1667-
@patch("loading_sdk.api.requests")
1667+
@patch("loading_sdk.sync_api.client.requests")
16681668
def test_edit_post_failure_post_does_not_exist(self, mock_requests):
16691669
status_code = 404
16701670
expected_response = {"code": status_code, "message": "Post does not exist"}
@@ -1692,7 +1692,7 @@ def test_edit_post_failure_post_does_not_exist(self, mock_requests):
16921692

16931693
self.assertEqual(response, expected_response)
16941694

1695-
@patch("loading_sdk.api.LoadingApiClient._authenticate")
1695+
@patch("loading_sdk.sync_api.LoadingApiClient._authenticate")
16961696
def test_edit_post_failure_empty_message(self, mock_authenticate):
16971697
expected_response = {
16981698
"code": 400,
@@ -1717,7 +1717,7 @@ def test_edit_post_failure_empty_message(self, mock_authenticate):
17171717
self.assertEqual(api._cookies, self.cookie_jar)
17181718
self.assertEqual(response, expected_response)
17191719

1720-
@patch("loading_sdk.api.LoadingApiClient._authenticate")
1720+
@patch("loading_sdk.sync_api.LoadingApiClient._authenticate")
17211721
def test_create_post_failure_empty_thread_id(self, mock_authenticate):
17221722
expected_response = {
17231723
"code": 400,
@@ -1733,8 +1733,8 @@ def test_create_post_failure_empty_thread_id(self, mock_authenticate):
17331733
self.assertEqual(api._cookies, self.cookie_jar)
17341734
self.assertEqual(response, expected_response)
17351735

1736-
@patch("loading_sdk.api.LoadingApiClient._authenticate")
1737-
@patch("loading_sdk.api.requests")
1736+
@patch("loading_sdk.sync_api.LoadingApiClient._authenticate")
1737+
@patch("loading_sdk.sync_api.client.requests")
17381738
def test_create_post_failure_thread_id_does_not_exist(
17391739
self, mock_requests, mock_authenticate
17401740
):
@@ -1757,7 +1757,7 @@ def test_create_post_failure_thread_id_does_not_exist(
17571757
self.assertEqual(api._cookies, self.cookie_jar)
17581758
self.assertEqual(response, expected_response)
17591759

1760-
@patch("loading_sdk.api.requests")
1760+
@patch("loading_sdk.sync_api.client.requests")
17611761
def test_create_post_failure_no_auth_token(self, mock_requests):
17621762
status_code = 401
17631763
expected_response = {"code": status_code, "message": "No auth token"}
@@ -1774,8 +1774,8 @@ def test_create_post_failure_no_auth_token(self, mock_requests):
17741774

17751775
self.assertEqual(response, expected_response)
17761776

1777-
@patch("loading_sdk.api.LoadingApiClient._authenticate")
1778-
@patch("loading_sdk.api.requests")
1777+
@patch("loading_sdk.sync_api.LoadingApiClient._authenticate")
1778+
@patch("loading_sdk.sync_api.client.requests")
17791779
def test_create_post_success(self, mock_requests, mock_authenticate):
17801780
status_code = 201
17811781
expected_response = {
@@ -1806,8 +1806,8 @@ def test_create_post_success(self, mock_requests, mock_authenticate):
18061806
self.assertEqual(response.get("code"), 201)
18071807
self.assertEqual(response.get("data"), expected_response)
18081808

1809-
@patch("loading_sdk.api.LoadingApiClient._authenticate")
1810-
@patch("loading_sdk.api.requests")
1809+
@patch("loading_sdk.sync_api.LoadingApiClient._authenticate")
1810+
@patch("loading_sdk.sync_api.client.requests")
18111811
def test_create_thread_success(self, mock_requests, mock_authenticate):
18121812
status_code = 201
18131813
expected_response = {
@@ -1864,8 +1864,8 @@ def test_create_thread_failure_invalid_post_type(self):
18641864

18651865
self.assertEqual(response, expected_response)
18661866

1867-
@patch("loading_sdk.api.LoadingApiClient._authenticate")
1868-
@patch("loading_sdk.api.requests")
1867+
@patch("loading_sdk.sync_api.LoadingApiClient._authenticate")
1868+
@patch("loading_sdk.sync_api.client.requests")
18691869
def test_create_thread_failure_empty_title_or_message(
18701870
self, mock_requests, mock_authenticate
18711871
):
@@ -1904,7 +1904,7 @@ def test_create_thread_failure_empty_title_or_message(
19041904

19051905
self.assertEqual(response, expected_response)
19061906

1907-
@patch("loading_sdk.api.requests")
1907+
@patch("loading_sdk.sync_api.client.requests")
19081908
def test_create_thread_failure_no_auth_token(self, mock_requests):
19091909
status_code = 401
19101910
expected_response = {"code": status_code, "message": "No auth token"}

0 commit comments

Comments
 (0)