@@ -253,3 +253,78 @@ def test_search_failure_empty_query(self, mock_requests):
253253 self .assertEqual (response .get ("code" ), 400 )
254254 self .assertEqual (response .get ("message" ), "Validation error" )
255255 self .assertEqual (response , expected_response )
256+
257+ @patch ("loading_api_wrapper.api.requests" )
258+ def test_get_post_failure_empty_post_id (self , mock_requests ):
259+ expected_response = {
260+ "code" : 404 ,
261+ "message" : '"post_id" is not allowed to be empty' ,
262+ }
263+
264+ mock_response = MagicMock ()
265+ mock_response .json .return_value = expected_response
266+ mock_requests .get .return_value = mock_response
267+
268+ api = LoadingApiWrapper ()
269+ response = api .get_post ("" )
270+
271+ self .assertEqual (response .get ("code" ), 404 )
272+ self .assertEqual (
273+ response .get ("message" ), '"post_id" is not allowed to be empty'
274+ )
275+ self .assertEqual (response , expected_response )
276+
277+ @patch ("loading_api_wrapper.api.requests" )
278+ def test_get_post_failure_post_does_not_exist (self , mock_requests ):
279+ expected_response = {"code" : 404 , "message" : "Post does not exist" }
280+
281+ mock_response = MagicMock ()
282+ mock_response .status_code = 404
283+ mock_response .json .return_value = expected_response
284+ mock_requests .get .return_value = mock_response
285+
286+ api = LoadingApiWrapper ()
287+ response = api .get_post ("none_existing_post_id" )
288+
289+ self .assertEqual (response .get ("code" ), 404 )
290+ self .assertEqual (response .get ("message" ), "Post does not exist" )
291+ self .assertEqual (response , expected_response )
292+
293+ @patch ("loading_api_wrapper.api.requests" )
294+ def test_get_post_success (self , mock_requests ):
295+ status_code = 200
296+ expected_response = {
297+ "posts" : [
298+ {
299+ "id" : "609f78fe90c3d5001e889e33" ,
300+ "body" : "Fota! Fota! Fota allihop! POKEMON! " ,
301+ "postType" : "regular" ,
302+ "createdAt" : "2021-05-15T07:32:14.156Z" ,
303+ "updatedAt" : "2021-05-15T07:32:14.156Z" ,
304+ "parentId" : "609e2783b7a187001e0c0440" ,
305+ "userId" : "5d5948e1455110001e3f4d8b" ,
306+ "replies" : 0 ,
307+ }
308+ ],
309+ "users" : [
310+ {
311+ "id" : "5d5948e1455110001e3f4d8b" ,
312+ "name" : "Wirus" ,
313+ "picture" : "f0e49672-ae24-4a68-a714-0f1165b69775.jpg" ,
314+ "role" : "user" ,
315+ "createdAt" : "2019-08-18T12:47:29.578Z" ,
316+ "status" : "active" ,
317+ }
318+ ],
319+ }
320+
321+ mock_response = MagicMock ()
322+ mock_response .status_code = status_code
323+ mock_response .json .return_value = expected_response
324+ mock_requests .get .return_value = mock_response
325+
326+ api = LoadingApiWrapper ()
327+ response = api .get_post ("none_existing_post_id" )
328+
329+ self .assertEqual (response .get ("code" ), 200 )
330+ self .assertEqual (response .get ("post" ), expected_response )
0 commit comments