restore и like постов
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
test.py
|
||||
venv/
|
||||
__pycache__/
|
||||
dist
|
||||
|
||||
@@ -9,7 +9,7 @@ from itd.routes.etc import get_top_clans, get_who_to_follow, get_platform_status
|
||||
from itd.routes.comments import get_comments, add_comment, delete_comment, like_comment, unlike_comment, add_reply_comment
|
||||
from itd.routes.hashtags import get_hastags, get_posts_by_hastag
|
||||
from itd.routes.notifications import get_notifications, mark_as_read, mark_all_as_read, get_unread_notifications_count
|
||||
from itd.routes.posts import create_post, get_posts, get_post, edit_post, delete_post, pin_post, repost, view_post, get_liked_posts
|
||||
from itd.routes.posts import create_post, get_posts, get_post, edit_post, delete_post, pin_post, repost, view_post, get_liked_posts, restore_post, like_post, delete_like_post
|
||||
from itd.routes.reports import report
|
||||
from itd.routes.search import search
|
||||
from itd.routes.files import upload_file
|
||||
@@ -18,7 +18,7 @@ from itd.routes.verification import verificate, get_verification_status
|
||||
|
||||
from itd.models.comment import Comment
|
||||
from itd.models.notification import Notification
|
||||
from itd.models.post import Post, NewPost
|
||||
from itd.models.post import Post, NewPost, LikePostResponse
|
||||
from itd.models.clan import Clan
|
||||
from itd.models.hashtag import Hashtag
|
||||
from itd.models.user import User, UserProfileUpdate, UserPrivacy, UserFollower, UserWhoToFollow
|
||||
@@ -663,3 +663,36 @@ class Client:
|
||||
def update_banner(self, name: str) -> UserProfileUpdate:
|
||||
id = self.upload_file(name, cast(BufferedReader, open(name, 'rb')))['id']
|
||||
return self.update_profile(banner_id=id)
|
||||
|
||||
@refresh_on_error
|
||||
def restore_post(self, post_id: UUID) -> None:
|
||||
"""Восстановить удалённый пост
|
||||
|
||||
Args:
|
||||
post_id: UUID поста
|
||||
"""
|
||||
restore_post(self.token, post_id)
|
||||
|
||||
@refresh_on_error
|
||||
def like_post(self, post_id: UUID) -> LikePostResponse:
|
||||
"""Поставить лайк на пост
|
||||
|
||||
Args:
|
||||
post_id: UUID поста
|
||||
"""
|
||||
res = like_post(self.token, post_id)
|
||||
if res.status_code == 404:
|
||||
raise NotFound("Post not found")
|
||||
return LikePostResponse.model_validate(res.json())
|
||||
|
||||
@refresh_on_error
|
||||
def delete_like_post(self, post_id: UUID) -> LikePostResponse:
|
||||
"""Убрать лайк с поста
|
||||
|
||||
Args:
|
||||
post_id: UUID поста
|
||||
"""
|
||||
res = delete_like_post(self.token, post_id)
|
||||
if res.status_code == 404:
|
||||
raise NotFound("Post not found")
|
||||
return LikePostResponse.model_validate(res.json())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic import Field, BaseModel
|
||||
|
||||
from itd.models.user import UserPost, UserNewPost
|
||||
from itd.models._text import TextObject
|
||||
@@ -45,3 +45,7 @@ class Post(_Post, PostShort):
|
||||
class NewPost(_Post):
|
||||
author: UserNewPost
|
||||
|
||||
|
||||
class LikePostResponse(BaseModel):
|
||||
liked: bool
|
||||
likes_count: int = Field(alias="likesCount")
|
||||
|
||||
@@ -46,5 +46,11 @@ def view_post(token: str, id: UUID):
|
||||
def get_liked_posts(token: str, username: str, limit: int = 20, cursor: int = 0):
|
||||
return fetch(token, 'get', f'posts/user/{username}/liked', {'limit': limit, 'cursor': cursor})
|
||||
|
||||
# todo post restore
|
||||
# todo post like
|
||||
def restore_post(token: str, post_id: UUID):
|
||||
return fetch(token, "post", f"posts/{post_id}/restore",)
|
||||
|
||||
def like_post(token: str, post_id: UUID):
|
||||
return fetch(token, "post", f"posts/{post_id}/like")
|
||||
|
||||
def delete_like_post(token: str, post_id: UUID):
|
||||
return fetch(token, "delete", f"posts/{post_id}/like")
|
||||
|
||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
1
tests/settings.py
Normal file
1
tests/settings.py
Normal file
@@ -0,0 +1 @@
|
||||
cookies = 'Сюда вставить куки'
|
||||
26
tests/test_like.py
Normal file
26
tests/test_like.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from itd import ITDClient
|
||||
from itd.models.post import LikePostResponse
|
||||
from itd.exceptions import NotFound
|
||||
import unittest
|
||||
from . import settings
|
||||
|
||||
class TestLike(unittest.TestCase):
|
||||
def test_like(self):
|
||||
c = ITDClient(None, settings.cookies)
|
||||
|
||||
post = c.create_post("post_for_test_like")
|
||||
|
||||
self.assertEqual(c.like_post(post.id), LikePostResponse(liked=True, likesCount=1)) # Лайк на пост без лайка
|
||||
self.assertEqual(c.like_post(post.id), LikePostResponse(liked=True, likesCount=1)) # Лайк на пост с уже поставленным лайком
|
||||
|
||||
self.assertEqual(c.delete_like_post(post.id), LikePostResponse(liked=False, likesCount=0)) # Убрать лайк с поста с уже поставленным лайком
|
||||
self.assertEqual(c.delete_like_post(post.id), LikePostResponse(liked=False, likesCount=0)) # Убрать лайк с поста без лайков
|
||||
|
||||
c.delete_post(str(post.id))
|
||||
|
||||
self.assertRaises(NotFound, c.like_post, post.id) # лайк на удалённый пост
|
||||
self.assertRaises(NotFound, c.delete_like_post, post.id) # Убрать лайк с удалённого поста
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user