Skip to content

Commit 65410b2

Browse files
committed
Add wrapper method edit_thread that works exactly the same as edit_post and update unit tests
1 parent 8cb2696 commit 65410b2

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

loading_api_wrapper/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,9 @@ def edit_post(self, post_id, message):
273273

274274
# Handle any other unknown status code.
275275
return response.json()
276+
277+
def create_thread(self, title, text, category, post_type):
278+
pass
279+
280+
def edit_thread(self, thread_id, message):
281+
return self.edit_post(thread_id, message)

tests/test_loading_api_wrapper.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,7 @@ def test_edit_post_success(self, mock_requests, mock_authenticate):
15741574
mock_requests.patch.return_value = mock_response
15751575
mock_authenticate.return_value = {"code": 200, "cookies": self.cookie_jar}
15761576

1577+
# Edit post.
15771578
api = LoadingApiWrapper("test@email.com", "password")
15781579
response = api.edit_post(
15791580
post_id="000000000000000000000000",
@@ -1585,6 +1586,18 @@ def test_edit_post_success(self, mock_requests, mock_authenticate):
15851586
self.assertEqual(response.get("code"), 200)
15861587
self.assertDictEqual(response.get("data"), expected_response)
15871588

1589+
# Edit thread.
1590+
api = LoadingApiWrapper("test@email.com", "password")
1591+
response = api.edit_thread(
1592+
thread_id="000000000000000000000000",
1593+
message="updated message",
1594+
)
1595+
1596+
self.assertIsNotNone(api._cookies)
1597+
self.assertEqual(api._cookies, self.cookie_jar)
1598+
self.assertEqual(response.get("code"), 200)
1599+
self.assertDictEqual(response.get("data"), expected_response)
1600+
15881601
@patch("loading_api_wrapper.api.requests")
15891602
def test_edit_post_failure_no_auth_token(self, mock_requests):
15901603
status_code = 401
@@ -1595,11 +1608,21 @@ def test_edit_post_failure_no_auth_token(self, mock_requests):
15951608
mock_response.json.return_value = expected_response
15961609
mock_requests.patch.return_value = mock_response
15971610

1611+
# Edit post.
15981612
api = LoadingApiWrapper()
15991613
response = api.edit_post(post_id="post_id_to_edit", message="updated message")
16001614

16011615
self.assertEqual(response, expected_response)
16021616

1617+
# Edit thread.
1618+
api = LoadingApiWrapper()
1619+
response = api.edit_thread(
1620+
thread_id="thread_id_to_edit",
1621+
message="updated message",
1622+
)
1623+
1624+
self.assertEqual(response, expected_response)
1625+
16031626
@patch("loading_api_wrapper.api.requests")
16041627
def test_edit_post_failure_post_does_not_exist(self, mock_requests):
16051628
status_code = 404
@@ -1610,9 +1633,20 @@ def test_edit_post_failure_post_does_not_exist(self, mock_requests):
16101633
mock_response.json.return_value = expected_response
16111634
mock_requests.patch.return_value = mock_response
16121635

1636+
# Edit post.
16131637
api = LoadingApiWrapper()
16141638
response = api.edit_post(
1615-
post_id="non_existing_post_id", message="new updated message"
1639+
post_id="non_existing_post_id",
1640+
message="new updated message",
1641+
)
1642+
1643+
self.assertEqual(response, expected_response)
1644+
1645+
# Edit thread.
1646+
api = LoadingApiWrapper()
1647+
response = api.edit_thread(
1648+
thread_id="non_existing_thread_id",
1649+
message="new updated message",
16161650
)
16171651

16181652
self.assertEqual(response, expected_response)
@@ -1626,13 +1660,22 @@ def test_edit_post_failure_empty_thread_id(self, mock_authenticate):
16261660

16271661
mock_authenticate.return_value = {"code": 200, "cookies": self.cookie_jar}
16281662

1663+
# Edit post.
16291664
api = LoadingApiWrapper("test@email.com", "password")
16301665
response = api.edit_post(post_id="existing_post_id", message="")
16311666

16321667
self.assertIsNotNone(api._cookies)
16331668
self.assertEqual(api._cookies, self.cookie_jar)
16341669
self.assertEqual(response, expected_response)
16351670

1671+
# Edit thread.
1672+
api = LoadingApiWrapper("test@email.com", "password")
1673+
response = api.edit_thread(thread_id="existing_thread_id", message="")
1674+
1675+
self.assertIsNotNone(api._cookies)
1676+
self.assertEqual(api._cookies, self.cookie_jar)
1677+
self.assertEqual(response, expected_response)
1678+
16361679
@patch("loading_api_wrapper.api.LoadingApiWrapper._authenticate")
16371680
def test_create_post_failure_empty_thread_id(self, mock_authenticate):
16381681
expected_response = {

0 commit comments

Comments
 (0)