From 970b839d26a9b1e813fa40bcefbfbdc4dce47454 Mon Sep 17 00:00:00 2001 From: izzyjosh Date: Fri, 6 Sep 2024 17:36:01 +0100 Subject: [PATCH] feat: added test for repost endpoint --- api/v1/tests/post/conftest.py | 33 +++++++++++++++++++++ api/v1/tests/post/test_repost.py | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 api/v1/tests/post/test_repost.py diff --git a/api/v1/tests/post/conftest.py b/api/v1/tests/post/conftest.py index 9d5a72b..b164f73 100644 --- a/api/v1/tests/post/conftest.py +++ b/api/v1/tests/post/conftest.py @@ -93,3 +93,36 @@ def mock_get_post_likes(): } yield post_likes + + +@pytest.fixture +def mock_repost(): + with patch("api.v1.services.post.post_service.repost") as repost: + + repost.return_value = { + "user_id": "zzz", + "post_id": "hhh", + "content": "Test repost", + "created_at": "2024-08-22T23:59:25.816336+01:00", + "updated_at": "2024-08-22T23:59:25.816336+01:00", + "repost_owner": { + "id": "jjj", + "image": "/picture", + "username": "joshua" + }, + "original_post": { + "id": "kkk", + "created_at": "2024-08-22T23:59:25.816336+01:00", + "updated_at": "2024-08-22T23:59:25.816336+01:00", + "content": "Tgis is the original post", + "video": "null", + "images": "null", + "original_post_owner": { + "id": "iii", + "image": "/picture", + "username": "joseph" + } + } + } + + yield repost diff --git a/api/v1/tests/post/test_repost.py b/api/v1/tests/post/test_repost.py new file mode 100644 index 0000000..e12b7d0 --- /dev/null +++ b/api/v1/tests/post/test_repost.py @@ -0,0 +1,50 @@ +import os +import sys + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../"))) + +import pytest +from main import app +from fastapi.testclient import TestClient +from sqlalchemy.orm import Session + + +client = TestClient(app) +endpoint = "api/v1/posts/ggg/repost" + +def test_repost( + mock_db_session: Session, + access_token, + current_user, + mock_repost,): + + response = client.post(endpoint, headers={"Authorization": f"Bearer {access_token}"}, json={"content": "Test repost"}) + + assert response.status_code == 201 + assert response.json()["status_code"] == 201 + assert response.json()["message"] == "Reposted successfully" + assert response.json()["data"] == { + "user_id": "zzz", + "post_id": "hhh", + "content": "Test repost", + "created_at": "2024-08-22T23:59:25.816336+01:00", + "updated_at": "2024-08-22T23:59:25.816336+01:00", + "repost_owner": { + "id": "jjj", + "image": "/picture", + "username": "joshua" + }, + "original_post": { + "id": "kkk", + "created_at": "2024-08-22T23:59:25.816336+01:00", + "updated_at": "2024-08-22T23:59:25.816336+01:00", + "content": "Tgis is the original post", + "video": "null", + "images": "null", + "original_post_owner": { + "id": "iii", + "image": "/picture", + "username": "joseph" + } + } + }