Skip to content

Commit

Permalink
feat: added test for repost endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
izzyjosh committed Sep 6, 2024
1 parent 767a069 commit 970b839
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
33 changes: 33 additions & 0 deletions api/v1/tests/post/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 50 additions & 0 deletions api/v1/tests/post/test_repost.py
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit 970b839

Please sign in to comment.