def api_wrapper(*args, **kwargs): post_id = kwargs["post_id"] post_storage = PostStorageImpl() json_presenter = JsonPresenterImpl() interactor = GetPostInteractor(post_storage, json_presenter) response = interactor.get_post(post_id) from django.http.response import HttpResponse import json return HttpResponse(json.dumps(response), status=201)
def test_get_comment_response_with_replies(self): user_dto = UserDTO(user_id=1, name='user_1', profile_pic_url='https://user_1.png') comment_reactions_dto = ReactionStatsDTO(count=2, type=["SAD", "LIKE"]) reply_reactions_dto = ReactionStatsDTO(count=3, type=["LOVE", "LIKE"]) reply_dto = CommentDetailsDTO(comment_id=2, user=user_dto, commented_at=datetime.datetime.now(), comment_content="This is a reply", comment_reactions=reply_reactions_dto) comment_dto = CommentDetailsWithRepliesDTO( comment_id=1, user=user_dto, commented_at=datetime.datetime.now(), comment_content="This is a comment", comment_reactions=comment_reactions_dto, replies=[reply_dto], replies_count=1) json_presenter = JsonPresenterImpl() response = json_presenter\ .convert_comment_with_replies_dto_to_dict(comment_dto) assert response['comment_id'] == comment_dto.comment_id assert response['commenter']['user_id'] == user_dto.user_id assert response['commenter']['name'] == user_dto.name assert response['commenter']['profile_pic_url'] == user_dto\ .profile_pic_url assert response['commented_at'] == comment_dto.commented_at\ .strftime('%y-%m-%d %H:%M:%S.%f') assert response['comment_content'] == comment_dto.comment_content assert response['reactions']['count'] == comment_reactions_dto.count assert response['reactions']['type'] == comment_reactions_dto.type assert response['replies_count'] == 1 reply_data = None for reply in response["replies"]: if reply["comment_id"] == reply_dto.comment_id: reply_data = reply assert reply_data['comment_id'] == reply_dto.comment_id assert reply_data['commenter']['user_id'] == user_dto.user_id assert reply_data['commenter']['name'] == user_dto.name assert reply_data['commenter'][ 'profile_pic_url'] == user_dto.profile_pic_url assert reply_data['commented_at'] == reply_dto\ .commented_at.strftime('%y-%m-%d %H:%M:%S.%f') assert reply_data['comment_content'] == reply_dto.comment_content assert reply_data['reactions']['count'] == reply_reactions_dto.count assert reply_data['reactions']['type'] == reply_reactions_dto.type
def test_get_post_response(self): get_post_dto = self.setup_get_post_dto() json_presenter = JsonPresenterImpl() response = json_presenter.get_post_response(get_post_dto) assert response['post_id'] == get_post_dto.post_details.post_id assert response['posted_by']['user_id'] == get_post_dto\ .posted_by.user_id assert response['posted_by']['name'] == get_post_dto.posted_by.name assert response['posted_by']['profile_pic_url'] == get_post_dto\ .posted_by.profile_pic_url assert response['posted_at'] == get_post_dto.post_details\ .created_time.strftime('%y-%m-%d %H:%M:%S.%f') assert response['post_content'] == get_post_dto\ .post_details.post_content assert response['reactions']['count'] == get_post_dto\ .post_reaction_data.count assert response['reactions']['type'] == get_post_dto\ .post_reaction_data.type assert response['comments'] == get_post_dto.comments assert response['comments_count'] == get_post_dto.comments_count
def api_wrapper(*args, **kwargs): request_data = kwargs["request_data"] user = kwargs["user"] post_storage = PostStorageImpl() json_presenter = JsonPresenterImpl() interactor = CreatePostInteractor(post_storage, json_presenter) response = interactor.create_post(request_data["post_content"], user.id) from django.http.response import HttpResponse import json return HttpResponse(json.dumps(response), status=201)
def test_get_reactions_to_post_response(self): reactions_dto_one = UserReactionDTO( user_id=1, name='user_1', profile_pic_url='https://user_1.png', reaction_type="LOVE") reactions_dto_two = UserReactionDTO( user_id=2, name='user_2', profile_pic_url='https://user_2.png', reaction_type="LIKE") reaction_dto_list = [reactions_dto_one, reactions_dto_two] json_presenter = JsonPresenterImpl() response = json_presenter.get_post_reactions_response( reaction_dto_list) reaction_one_data = None for reaction in response: if reaction['user_id'] == reactions_dto_one.user_id: reaction_one_data = reaction assert reaction_one_data['name'] == reactions_dto_one.name assert reaction_one_data['profile_pic'] == reactions_dto_one\ .profile_pic_url assert reaction_one_data['reaction'] == reactions_dto_one.reaction_type reaction_two_data = None for reaction in response: if reaction['user_id'] == reactions_dto_two.user_id: reaction_two_data = reaction assert reaction_two_data['name'] == reactions_dto_two.name assert reaction_two_data['profile_pic'] == reactions_dto_two\ .profile_pic_url assert reaction_two_data['reaction'] == reactions_dto_two.reaction_type
def api_wrapper(*args, **kwargs): comment_id = kwargs["comment_id"] request_query_params = kwargs["request_query_params"] offset = request_query_params.offset limit = request_query_params.limit post_storage = PostStorageImpl() json_presenter = JsonPresenterImpl() interactor = GetCommentRepliesInteractor(post_storage, json_presenter) response = interactor.get_comment_replies(comment_id, offset, limit) from django.http.response import HttpResponse import json return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs): user = kwargs["user"] request_query_params = kwargs["request_query_params"] offset = request_query_params.offset limit = request_query_params.limit post_storage = PostStorageImpl() json_presenter = JsonPresenterImpl() interactor = GetUserPostsInteractor(post_storage, json_presenter) response = interactor.get_user_posts(user.id, offset, limit) from django.http.response import HttpResponse import json return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs): user = kwargs["user"] comment_id = kwargs["comment_id"] request_data = kwargs["request_data"] post_storage = PostStorageImpl() json_presenter = JsonPresenterImpl() interactor = ReactionInteractor(post_storage, json_presenter) response = interactor.react_to_comment(user.id, comment_id, request_data["reaction_type"]) from django.http.response import HttpResponse import json return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs): comment_id = kwargs["comment_id"] user = kwargs["user"] request_data = kwargs["request_data"] post_storage = PostStorageImpl() json_presenter = JsonPresenterImpl() interactor = AddCommentInteractor(post_storage, json_presenter) response = interactor.add_reply_to_comment(comment_id, user.id, request_data["comment_text"]) from django.http.response import HttpResponse import json return HttpResponse(json.dumps(response), status=201)