def test_cannot_delete_foreign_reaction_in_connected_user_public_post( self): """ should not be able to delete foreign reaction in a connected user public post and return 400 """ user = make_user() user_to_connect = make_user() user.connect_with_user_with_id(user_to_connect.pk) user_to_connect.confirm_connection_with_user_with_id(user.pk) foreign_user = make_user() post = user_to_connect.create_public_post(text=make_fake_post_text()) emoji_group = make_reactions_emoji_group() post_reaction_emoji_id = make_emoji(group=emoji_group).pk post_reaction = foreign_user.react_to_post_with_id( post.pk, emoji_id=post_reaction_emoji_id, ) url = self._get_url(post_reaction=post_reaction, post=post) headers = make_authentication_headers_for_user(user) response = self.client.delete(url, **headers) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue( PostReaction.objects.filter(id=post_reaction.pk).count() == 1)
def test_can_delete_own_post_comment_reaction_in_foreign_public_post_comment( self): """ should be able to delete own post comment reaction in foreign public post and return 200 """ user = make_user() foreign_user = make_user() post = foreign_user.create_public_post(text=make_fake_post_text()) post_comment = foreign_user.comment_post_with_id( post_id=post.pk, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk post_comment_reaction = user.react_to_post_comment_with_id( post.pk, emoji_id=post_comment_reaction_emoji_id, ) url = self._get_url(post_comment_reaction=post_comment_reaction, post=post, post_comment=post_comment) headers = make_authentication_headers_for_user(user) response = self.client.delete(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue( PostCommentReaction.objects.filter( id=post_comment_reaction.pk).count() == 0)
def test_cannot_react_to_connected_user_encircled_post_comment_not_part_of(self): """ should NOT be able to react in the encircled post comment of a connected user which the user is NOT part of and return 400 """ user = make_user() headers = make_authentication_headers_for_user(user) user_to_connect = make_user() circle = make_circle(creator=user_to_connect) user.connect_with_user_with_id(user_to_connect.pk) # Note there is no confirmation of the connection on the other side connected_user_post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk]) connected_user_post_comment = user_to_connect.comment_post(post=connected_user_post, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=connected_user_post, post_comment=connected_user_post_comment) response = self.client.put(url, data, **headers) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=connected_user_post.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=user.pk).count() == 0)
def test_cannot_react_to_foreign_encircled_post_comment(self): """ should not be able to react in a foreign encircled post comment and return 400 """ user = make_user() headers = make_authentication_headers_for_user(user) foreign_user = make_user() circle = make_circle(creator=foreign_user) post = foreign_user.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk]) post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment) response = self.client.put(url, data, **headers) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=user.pk).count() == 0)
def test_cannot_retrieve_post_comment_reactions_from_blocking_user_in_a_community(self): """ should not be able to retrieve the post comment reactions from a blocking user in a community """ user = make_user() post_creator = make_user() community = make_community(creator=post_creator) blocking_user = make_user() post = post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name) post_comment = post_creator.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() emoji = make_emoji(group=emoji_group) blocking_user.react_to_post_comment_with_id(post_comment_id=post_comment.pk, emoji_id=emoji.pk, ) blocking_user.block_user_with_id(user_id=user.pk) url = self._get_url(post=post, post_comment=post_comment) headers = make_authentication_headers_for_user(user) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_reactions = json.loads(response.content) self.assertEqual(len(response_reactions), 0)
def test_can_react_to_post_comment_reply(self): """ should be able to react to post comment reply and return 201 """ user = make_user() headers = make_authentication_headers_for_user(user) post = user.create_public_post(text=make_fake_post_text()) post_comment = user.comment_post(post=post, text=make_fake_post_comment_text()) post_comment_reply = user.reply_to_comment_for_post(post=post, post_comment=post_comment, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment_reply) response = self.client.put(url, data, **headers) self.assertEqual(status.HTTP_201_CREATED, response.status_code) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=post_comment_reply.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=user.pk).count() == 1)
def test_reacting_on_foreign_post_comment_sends_push_notification(self, send_post_comment_reaction_push_notification_call): """ should send a push notification when when reacting on a foreign post comment """ user = make_user() reactor = make_user() headers = make_authentication_headers_for_user(reactor) post = user.create_public_post(text=make_fake_post_text()) post_comment = user.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment) self.client.put(url, data, **headers) post_comment_reaction = PostCommentReaction.objects.get( reactor_id=reactor.pk, post_comment_id=post_comment.id) send_post_comment_reaction_push_notification_call.assert_called_with( post_comment_reaction=post_comment_reaction)
def test_cannot_react_to_blocking_user_community_post_comment(self): """ should not be able to react to a blocking user community post comment and return 400 """ user = make_user() headers = make_authentication_headers_for_user(user) community_owner = make_user() community = make_community(creator=community_owner) blocking_user = make_user() blocking_user.join_community_with_name(community_name=community.name) post = blocking_user.create_community_post(community_name=community.name, text=make_fake_post_text()) post_comment = blocking_user.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text()) blocking_user.block_user_with_id(user_id=user.pk) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment) response = self.client.put(url, data, **headers) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=user.pk).count() == 0)
def test_can_react_to_blocking_community_staff_member_post_comment(self): """ should be able to react to a blocking community staff member post comment and return 201 """ user = make_user() headers = make_authentication_headers_for_user(user) community_owner = make_user() community = make_community(creator=community_owner) post = community_owner.create_community_post(community_name=community.name, text=make_fake_post_text()) post_comment = user.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text()) community_owner.block_user_with_id(user_id=user.pk) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment) response = self.client.put(url, data, **headers) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=user.pk).count() == 1)
def test_cannot_react_to_blocked_user_post_comment(self): """ should not be able to react to a blocked user post comment and return 400 """ user = make_user() headers = make_authentication_headers_for_user(user) user_to_block = make_user() user.follow_user_with_id(user_to_block.pk) post = user_to_block.create_public_post(text=make_fake_post_text()) post_comment = user_to_block.comment_post(post=post, text=make_fake_post_comment_text()) user.block_user_with_id(user_id=user_to_block.pk) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment) response = self.client.put(url, data, **headers) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=user.pk).count() == 0)
def test_cannot_react_to_closed_community_post_comment_if_creator(self): """ should NOT be able to react in a closed community post comment if creator """ user = make_user() admin = make_user() community = make_community(admin) post_creator = make_user() post_creator.join_community_with_name(community_name=community.name) user.join_community_with_name(community_name=community.name) community_post = post_creator.create_community_post(community_name=community.name, text=make_fake_post_comment_text()) community_post_comment = post_creator.comment_post(post=community_post, text=make_fake_post_comment_text()) community_post.is_closed = True community_post.save() emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) headers = make_authentication_headers_for_user(post_creator) url = self._get_url(post=community_post, post_comment=community_post_comment) response = self.client.put(url, data, **headers) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=community_post_comment.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=post_creator.pk).count() == 0)
def test_cannot_react_in_post_comment_from_community_banned_from(self): """ should not be able to react in the post comment of a community banned from and return 400 """ user = make_user() headers = make_authentication_headers_for_user(user) community_owner = make_user() community = make_community(creator=community_owner) user.join_community_with_name(community_name=community.name) post = community_owner.create_community_post(community_name=community.name, text=make_fake_post_text()) post_comment = community_owner.comment_post(post=post, text=make_fake_post_comment_text()) community_owner.ban_user_with_username_from_community_with_name(username=user.username, community_name=community.name) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment) response = self.client.put(url, data, **headers) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=user.pk).count() == 0)
def test_can_delete_own_reaction_in_connected_user_encircled_post_part_of( self): """ should be able to delete own reaction in a connected user encircled post it's part of and return 200 """ user = make_user() user_to_connect = make_user() circle = make_circle(creator=user_to_connect) user.connect_with_user_with_id(user_to_connect.pk) user_to_connect.confirm_connection_with_user_with_id( user.pk, circles_ids=[circle.pk]) post = user_to_connect.create_encircled_post( text=make_fake_post_text(), circles_ids=[circle.pk]) emoji_group = make_reactions_emoji_group() post_reaction_emoji_id = make_emoji(group=emoji_group).pk post_reaction = user.react_to_post_with_id( post.pk, emoji_id=post_reaction_emoji_id, ) url = self._get_url(post_reaction=post_reaction, post=post) headers = make_authentication_headers_for_user(user) response = self.client.delete(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue( PostReaction.objects.filter(id=post_reaction.pk).count() == 0)
def test_can_delete_reaction_in_closed_community_post_if_creator(self): """ should be able to delete reaction in closed community post if creator """ user = make_user() admin = make_user() community = make_community(admin) post_creator = make_user() post_creator.join_community_with_name(community_name=community.name) user.join_community_with_name(community_name=community.name) community_post = post_creator.create_community_post( community_name=community.name, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_reaction_emoji_id = make_emoji(group=emoji_group).pk post_reaction = user.react_to_post_with_id( community_post.pk, emoji_id=post_reaction_emoji_id, ) # now close the post community_post.is_closed = True community_post.save() url = self._get_url(post_reaction=post_reaction, post=community_post) headers = make_authentication_headers_for_user(post_creator) response = self.client.delete(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue( PostReaction.objects.filter(id=post_reaction.pk).count() == 0)
def test_can_react_to_connected_user_public_post_comment(self): """ should be able to react in the public post comment of a connected user post and return 201 """ user = make_user() headers = make_authentication_headers_for_user(user) user_to_connect = make_user() user.connect_with_user_with_id(user_to_connect.pk) connected_user_post = user_to_connect.create_public_post(text=make_fake_post_text()) connected_user_post_comment = user_to_connect.comment_post(post=connected_user_post, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=connected_user_post, post_comment=connected_user_post_comment) response = self.client.put(url, data, **headers) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertTrue( PostCommentReaction.objects.filter(post_comment_id=connected_user_post_comment.pk, emoji_id=post_comment_reaction_emoji_id, reactor_id=user.pk).count() == 1)
def test_list_name_taken(self): """ should return status 400 if the listName is taken """ user = make_user() emoji = make_emoji() list = user.create_list(name=make_fake_list_name(), emoji_id=emoji.pk) request_data = {'name': list.name} url = self._get_url() headers = make_authentication_headers_for_user(user) response = self.client.post(url, request_data, format='json', **headers) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_post_comment_reaction_notification_is_deleted_when_deleting_reaction( self): """ should delete the post comment reaction notification when a post comment reaction is deleted """ user = make_user() reactor = make_user() post = user.create_public_post(text=make_fake_post_text()) post_comment = user.comment_post_with_id( post_id=post.pk, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk post_comment_reaction = reactor.react_to_post_comment_with_id( post.pk, emoji_id=post_comment_reaction_emoji_id, ) post_comment_reaction_notification = PostCommentReactionNotification.objects.get( post_comment_reaction=post_comment_reaction, notification__owner=user) notification = Notification.objects.get( notification_type=Notification.POST_COMMENT_REACTION, object_id=post_comment_reaction_notification.pk) url = self._get_url(post_comment_reaction=post_comment_reaction, post=post, post_comment=post_comment) headers = make_authentication_headers_for_user(reactor) response = self.client.delete(url, **headers) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertFalse( PostCommentReactionNotification.objects.filter( pk=post_comment_reaction_notification.pk).exists()) self.assertFalse( Notification.objects.filter(pk=notification.pk).exists())
def test_cannot_delete_foreign_reaction_in_followed_user_encircled_post_comment( self): """ should not be able to delete foreign reaction in a followed user encircled post comment and return 400 """ user = make_user() user_to_follow = make_user() circle = make_circle(creator=user_to_follow) user.follow_user_with_id(user_to_follow.pk) foreign_user = make_user() foreign_user.connect_with_user_with_id(user_to_follow.pk) user_to_follow.confirm_connection_with_user_with_id( foreign_user.pk, circles_ids=[circle.pk]) post = user_to_follow.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk]) post_comment = user_to_follow.comment_post_with_id( post_id=post.pk, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk post_comment_reaction = foreign_user.react_to_post_comment_with_id( post.pk, emoji_id=post_comment_reaction_emoji_id, ) url = self._get_url(post_comment_reaction=post_comment_reaction, post=post, post_comment=post_comment) headers = make_authentication_headers_for_user(user) response = self.client.delete(url, **headers) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue( PostCommentReaction.objects.filter( id=post_comment_reaction.pk).count() == 1)
def test_can_retrieve_reactions_from_blocking_user_in_a_community_if_staff( self): """ should be able to retrieve the reactions from a blocking user in a community if staff member """ user = make_user() community = make_community(creator=user) post_creator = make_user() blocking_user = make_user() post_creator.join_community_with_name(community_name=community.name) post = post_creator.create_community_post( text=make_fake_post_text(), community_name=community.name) emoji_group = make_reactions_emoji_group() emoji = make_emoji(group=emoji_group) blocking_user.react_to_post_with_id( post_id=post.pk, emoji_id=emoji.pk, ) blocking_user.block_user_with_id(user_id=user.pk) url = self._get_url(post) headers = make_authentication_headers_for_user(user) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_emoji_counts = json.loads(response.content) self.assertEqual(1, len(response_emoji_counts)) response_emoji_count = response_emoji_counts[0] response_emoji_id = response_emoji_count.get('emoji').get('id') response_emoji_count = response_emoji_count.get('count') self.assertEqual(response_emoji_id, emoji.pk) self.assertEqual(1, response_emoji_count)
def test_reacting_in_own_post_comment_does_not_create_notification(self): """ should not create a notification when reacting on an own post comment """ user = make_user() headers = make_authentication_headers_for_user(user) post = user.create_public_post(text=make_fake_post_text()) post_comment = user.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text()) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment) self.client.put(url, data, **headers) self.assertFalse(PostCommentReactionNotification.objects.filter( post_comment_reaction__emoji__id=post_comment_reaction_emoji_id, notification__owner=user).exists())
def test_reacting_on_foreign_post_comment_doesnt_send_push_notification_when_post_muted(self, send_post_comment_reaction_push_notification_call): """ should NOT send a push notification when reacting on a foreign post comment when post muted """ user = make_user() reactor = make_user() headers = make_authentication_headers_for_user(reactor) post = user.create_public_post(text=make_fake_post_text()) post_comment = user.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text()) user.mute_post_with_id(post_id=post.pk) emoji_group = make_reactions_emoji_group() post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id) url = self._get_url(post=post, post_comment=post_comment) self.client.put(url, data, **headers) send_post_comment_reaction_push_notification_call.assert_not_called()
def test_cannot_react_to_foreign_post_with_non_reaction_emoji(self): """ should not be able to reaction in a post with a non reaction emoji group and return 400 """ user = make_user() headers = make_authentication_headers_for_user(user) post = user.create_public_post(text=make_fake_post_text()) emoji_group = make_emoji_group() post_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_reaction_request_data( post_reaction_emoji_id, emoji_group.pk) url = self._get_url(post) response = self.client.put(url, data, **headers) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue( PostReaction.objects.filter(post_id=post.pk, emoji_id=post_reaction_emoji_id, reactor_id=user.pk).count() == 0)
def test_can_react_to_own_post(self): """ should be able to reaction in own post and return 201 """ user = make_user() headers = make_authentication_headers_for_user(user) post = user.create_public_post(text=make_fake_post_text()) emoji_group = make_reactions_emoji_group() post_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_reaction_request_data( post_reaction_emoji_id, emoji_group.pk) url = self._get_url(post) response = self.client.put(url, data, **headers) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertTrue( PostReaction.objects.filter(post_id=post.pk, emoji_id=post_reaction_emoji_id, reactor_id=user.pk).count() == 1)
def test_post_reaction_notification_is_deleted_when_deleting_reaction( self): """ should delete the post reaction notification when a post reaction is deleted """ user = make_user() reactioner = make_user() post = user.create_public_post(text=make_fake_post_text()) emoji_group = make_reactions_emoji_group() post_reaction_emoji_id = make_emoji(group=emoji_group).pk post_reaction = reactioner.react_to_post_with_id( post.pk, emoji_id=post_reaction_emoji_id, emoji_group_id=emoji_group.pk) post_reaction_notification = PostReactionNotification.objects.get( post_reaction=post_reaction, notification__owner=user) notification = Notification.objects.get( notification_type=Notification.POST_REACTION, object_id=post_reaction_notification.pk) url = self._get_url(post_reaction=post_reaction, post=post) headers = make_authentication_headers_for_user(user) self.client.delete(url, **headers) self.assertFalse( PostReactionNotification.objects.filter( pk=post_reaction_notification.pk).exists()) self.assertFalse( Notification.objects.filter(pk=notification.pk).exists())
def test_reacting_in_foreign_post_creates_notification(self): """ should create a notification when reacting on a foreign post """ user = make_user() reactor = make_user() headers = make_authentication_headers_for_user(reactor) post = user.create_public_post(text=make_fake_post_text()) emoji_group = make_reactions_emoji_group() post_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_reaction_request_data( post_reaction_emoji_id, emoji_group.pk) url = self._get_url(post) self.client.put(url, data, **headers) self.assertTrue( PostReactionNotification.objects.filter( post_reaction__emoji__id=post_reaction_emoji_id, notification__owner=user).exists())