def test_cannot_edit_own_community_post_which_is_closed(self): """ should NOT be able to edit own closed community post and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) community_creator = make_user() community = make_community(creator=community_creator) user.join_community_with_name(community_name=community.name) original_text = make_fake_post_text() community_post = user.create_community_post(text=original_text, community_name=community.name) community_post.is_closed = True community_post.save() url = self._get_url(community_post) edited_text = make_fake_post_text() data = { 'text': edited_text } response = self.client.patch(url, data, **headers) self.assertTrue(response.status_code, status.HTTP_400_BAD_REQUEST) community_post.refresh_from_db() self.assertEqual(community_post.text, original_text) self.assertFalse(community_post.is_edited)
def test_can_retrieve_posts_with_recent_unconfirmed_connection_encircled_post( self): """ should be able to retrieve the timeline posts with an unconfirmed connection recent posts https://github.com/OpenbookOrg/openbook-api/issues/301 """ user = make_user() user_timeline_posts_amount = 5 posts_ids = [] for i in range(0, user_timeline_posts_amount): foreign_user = make_user() foreign_post = foreign_user.create_encircled_post( text=make_fake_post_text(), circles_ids=[foreign_user.connections_circle_id]) posts_ids.append(foreign_post.pk) user.connect_with_user_with_id(user_id=foreign_user.pk) foreign_user.confirm_connection_with_user_with_id(user_id=user.pk) connection_requester_user = make_user() connection_requester_user.connect_with_user_with_id( user_id=user.pk, circles_ids=[connection_requester_user.connections_circle.pk]) user.confirm_connection_with_user_with_id( user_id=connection_requester_user.pk) connection_requester_user.disconnect_from_user_with_id(user_id=user.pk) connection_requester_user.connect_with_user_with_id( user_id=user.pk, circles_ids=[connection_requester_user.connections_circle.pk]) connection_requester_user_circle = make_circle( creator=connection_requester_user) connection_requester_user.update_connection_with_user_with_id( user_id=user.pk, circles_ids=[connection_requester_user_circle.pk]) connection_requester_user.create_encircled_post( text=make_fake_post_text(), circles_ids=[connection_requester_user_circle.pk]) url = self._get_url() headers = make_authentication_headers_for_user(user) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_posts = json.loads(response.content) self.assertEqual(len(posts_ids), len(response_posts)) response_posts_ids = [post['id'] for post in response_posts] for post_id in posts_ids: self.assertIn(post_id, response_posts_ids)
def test_can_edit_own_community_post(self): """ should be able to edit own community post and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) community_creator = make_user() community = make_community(creator=community_creator) user.join_community_with_name(community_name=community.name) community_post = user.create_community_post(text=make_fake_post_text(), community_name=community.name) url = self._get_url(community_post) edited_text = make_fake_post_text() data = { 'text': edited_text } response = self.client.patch(url, data, **headers) self.assertTrue(response.status_code, status.HTTP_200_OK) community_post.refresh_from_db() self.assertEqual(community_post.text, edited_text) self.assertTrue(community_post.is_edited)
def test_get_all_public_posts_for_connected_user(self): """ should be able to retrieve all the posts of a connected user and return 200 """ user = make_user() user_to_connect_with = make_user() user.connect_with_user_with_id(user_to_connect_with.pk) user_to_connect_with.confirm_connection_with_user_with_id(user.pk) amount_of_public_posts = random.randint(1, 5) amount_of_encircled_posts = random.randint(1, 5) created_posts_ids = [] for i in range(amount_of_public_posts): post = user_to_connect_with.create_public_post( make_fake_post_text()) created_posts_ids.append(post.pk) circle = make_circle(creator=user_to_connect_with) user_to_connect_with.update_connection_with_user_with_id( user_id=user.pk, circles_ids=[circle.pk]) for i in range(amount_of_encircled_posts): post = user_to_connect_with.create_encircled_post( text=make_fake_post_text(), circles_ids=[circle.pk]) created_posts_ids.append(post.pk) headers = make_authentication_headers_for_user(user) url = self._get_url() response = self.client.get(url, {'username': user_to_connect_with.username}, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_posts = json.loads(response.content) self.assertEqual(len(response_posts), len(created_posts_ids)) response_posts_ids = [post['id'] for post in response_posts] for post_id in created_posts_ids: self.assertIn(post_id, response_posts_ids)
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_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_cannot_react_to_blocking_user_post_comment(self): """ should not be able to react to a blocking user post comment and return 400 """ user = make_user() headers = make_authentication_headers_for_user(user) blocking_user = make_user() user.follow_user_with_id(blocking_user.pk) post = blocking_user.create_public_post(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(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_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_can_retrieve_encircled_posts_of_confirmed_connection(self): """ should be able to retrieve the encircled posts of a confirmed connection """ user = make_user() user_to_connect_to = make_user() user.connect_with_user_with_id(user_id=user_to_connect_to.pk) user_to_connect_to_circle = make_circle(creator=user_to_connect_to) user_to_connect_to.confirm_connection_with_user_with_id(user_id=user.pk, circles_ids=[user_to_connect_to_circle.pk]) post = user_to_connect_to.create_encircled_post(text=make_fake_post_text(), circles_ids=[user_to_connect_to_circle.pk]) url = self._get_url() headers = make_authentication_headers_for_user(user) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_posts = json.loads(response.content) self.assertEqual(1, len(response_posts)) response_post = response_posts[0] self.assertEqual(response_post['id'], post.pk)
def test_retrieves_no_posts_when_filtering_on_empty_circle(self): """ should retrieve no posts when filtering on an empty circle """ user = make_user() connections_circle_id = user.connections_circle_id headers = make_authentication_headers_for_user(user) amount_of_foreign_public_posts = 10 public_posts_ids = [] for i in range(amount_of_foreign_public_posts): post_text = make_fake_post_text() foreign_user = make_user() public_post = foreign_user.create_public_post(text=post_text) public_posts_ids.append(public_post.pk) url = self._get_url() response = self.client.get(url, {'circle_id': connections_circle_id}, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_posts = json.loads(response.content) self.assertEqual(len(response_posts), 0)
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_retrieve_reaction_from_blocked_user(self): """ should not be able to retrieve the reaction from a blocked user """ user = make_user() post_creator = make_user() blocked_user = make_user() post = post_creator.create_public_post(text=make_fake_post_text()) emoji_group = make_reactions_emoji_group() emoji = make_emoji(group=emoji_group) blocked_user.react_to_post_with_id( post_id=post.pk, emoji_id=emoji.pk, ) user.block_user_with_id(user_id=blocked_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_reactions = json.loads(response.content) self.assertEqual(len(response_reactions), 0)
def test_can_react_to_blocking_community_staff_member_post(self): """ should be able to react to a blocking community staff member post 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()) 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_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_cannot_react_in_post_from_community_banned_from(self): """ should not be able to react in the post 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()) community_owner.ban_user_with_username_from_community_with_name( username=user.username, community_name=community.name) 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_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_cannot_react_to_followed_user_encircled_post(self): """ should be able to reaction in the encircled post of a followed user return 400 """ user = make_user() headers = make_authentication_headers_for_user(user) user_to_follow = make_user() circle = make_circle(creator=user_to_follow) user.follow_user_with_id(user_to_follow.pk) followed_user_post = user_to_follow.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 data = self._get_create_post_reaction_request_data( post_reaction_emoji_id, emoji_group.pk) url = self._get_url(followed_user_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=followed_user_post.pk, emoji_id=post_reaction_emoji_id, reactor_id=user.pk).count() == 0)
def test_get_all_public_posts_for_unconnected_user(self): """ should be able to retrieve all the public posts of an unconnected user and return 200 """ user = make_user() amount_of_users_to_follow = random.randint(1, 5) users_to_retrieve_posts_from = make_users(amount_of_users_to_follow) for user_to_retrieve_posts_from in users_to_retrieve_posts_from: post_text = make_fake_post_text() user_to_retrieve_posts_from.create_public_post(text=post_text) user_to_retrieve_posts_from = random.choice(users_to_retrieve_posts_from) headers = make_authentication_headers_for_user(user) url = self._get_url() response = self.client.get(url, { 'username': user_to_retrieve_posts_from.username }, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_posts = json.loads(response.content) self.assertEqual(len(response_posts), 1) post = response_posts[0] self.assertEqual(post['creator']['id'], user_to_retrieve_posts_from.pk)
def test_filter_community_post_from_own_posts(self): """ should filter out the community posts when retrieving all own posts and return 200 """ user = make_user() community = make_community(creator=user) amount_of_community_posts = random.randint(1, 5) created_posts_ids = [] for i in range(amount_of_community_posts): post = user.create_community_post(community_name=community.name, text=make_fake_post_text()) created_posts_ids.append(post.pk) headers = make_authentication_headers_for_user(user) url = self._get_url() response = self.client.get(url, { 'username': user.username }, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_posts = json.loads(response.content) self.assertEqual(len(response_posts), 0)
def test_cannot_delete_foreign_reaction_in_connected_user_encircled_post_not_part_of( self): """ should NOT be able to delete foreign reaction in a connected user encircled post NOT part of and return 400 """ user = make_user() user_to_connect = make_user() circle = make_circle(creator=user_to_connect) foreign_user = make_user() foreign_user.connect_with_user_with_id(user_to_connect.pk) user_to_connect.confirm_connection_with_user_with_id( foreign_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 = foreign_user.react_to_post_with_id( post.pk, emoji_id=post_reaction_emoji_id, emoji_group_id=emoji_group.pk) 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_retrieves_own_posts_of_own_filtered_circle(self): """ should retrieve own posts when filtering on a circle that is from us """ user = make_user() circle = make_circle(creator=user) circle_id = circle.pk headers = make_authentication_headers_for_user(user) amount_of_posts = 10 posts_ids = [] for i in range(amount_of_posts): post_text = make_fake_post_text() post = user.create_encircled_post(text=post_text, circles_ids=[circle_id]) posts_ids.append(post.pk) url = self._get_url() response = self.client.get(url, {'circle_id': circle_id}, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_posts = json.loads(response.content) self.assertEqual(len(posts_ids), len(response_posts)) response_posts_ids = [post['id'] for post in response_posts] for post_id in posts_ids: self.assertIn(post_id, response_posts_ids)
def test_can_delete_own_reaction_in_followed_user_public_post(self): """ should be able to delete own reaction in a followed user public post and return 200 """ user = make_user() user_to_follow = make_user() user.follow_user_with_id(user_to_follow.pk) post = user_to_follow.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 = user.react_to_post_with_id( post.pk, emoji_id=post_reaction_emoji_id, emoji_group_id=emoji_group.pk) 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_retrieve_posts_from_public_community(self): """ should be able to retrieve the posts for a public community and 200 """ user = make_user() headers = make_authentication_headers_for_user(user) other_user = make_user() community = make_community(creator=other_user, type='P') community_name = community.name amount_of_community_posts = 5 community_posts_ids = [] for i in range(0, amount_of_community_posts): community_member = make_user() community_member.join_community_with_name( community_name=community_name) community_member_post = community_member.create_community_post( community_name=community.name, text=make_fake_post_text()) community_posts_ids.append(community_member_post.pk) url = self._get_url(community_name=community.name) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) response_posts = json.loads(response.content) self.assertEqual(len(response_posts), len(community_posts_ids)) for response_post in response_posts: response_post_id = response_post.get('id') self.assertIn(response_post_id, community_posts_ids)
def test_cannot_delete_foreign_reaction_in_foreign_public_post(self): """ should NOT be able to delete foreign reaction in foreign public post and return 400 """ user = make_user() foreign_user = make_user() post = foreign_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 = foreign_user.react_to_post_with_id( post.pk, emoji_id=post_reaction_emoji_id, emoji_group_id=emoji_group.pk) 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_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_retrieves_world_circle_post_with_hashtag(self): """ should retrieve world circle post with a given hashtag and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) post_creator = make_user() hashtag = make_hashtag() fake_post_text = make_fake_post_text( ) + ' and a little hashtag #%s' % hashtag.name post_creator.create_public_post(text=fake_post_text) url = self._get_url(hashtag_name=hashtag.name) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) parsed_response = json.loads(response.content) self.assertEqual(len(parsed_response), 1) retrieved_posts = parsed_response[0] self.assertEqual(retrieved_posts['text'], fake_post_text)
def test_can_react_to_post_comment_only_once(self): """ should be able to react in own post comment only once, update the old reaction 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_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) new_post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk data = self._get_create_post_comment_reaction_request_data(new_post_comment_reaction_emoji_id) 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, reactor_id=user.pk).count() == 1)
def test_does_not_retrieve_private_community_not_part_of_post_with_hashtag( self): """ should not retrieve a private community not part of post with a givne hashtag and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) community_creator = make_user() community = make_community(creator=community_creator, type=Community.COMMUNITY_TYPE_PRIVATE) post_creator = make_user() community_creator.invite_user_with_username_to_community_with_name( community_name=community.name, username=post_creator.username) post_creator.join_community_with_name(community_name=community.name) hashtag = make_hashtag() fake_post_text = make_fake_post_text( ) + ' and a little hashtag #%s' % hashtag.name post_creator.create_community_post(community_name=community.name, text=fake_post_text) url = self._get_url(hashtag_name=hashtag.name) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) parsed_response = json.loads(response.content) self.assertEqual(len(parsed_response), 0)
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_does_not_retrieve_encircled_post_with_hashtag(self): """ should not retrieve an encircled post with a givne hashtag and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) post_creator = make_user() circle = make_circle(creator=post_creator) hashtag = make_hashtag() fake_post_text = make_fake_post_text( ) + ' and a little hashtag #%s' % hashtag.name post_creator.create_encircled_post(circles_ids=[circle.pk], text=fake_post_text) url = self._get_url(hashtag_name=hashtag.name) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) parsed_response = json.loads(response.content) self.assertEqual(len(parsed_response), 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_does_not_retrieve_post_from_blocking_person_with_hashtag(self): """ should not retrieve a post from a blocking person with a given hashtag and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) post_creator = make_user() hashtag = make_hashtag() fake_post_text = make_fake_post_text( ) + ' and a little hashtag #%s' % hashtag.name post_creator.create_public_post(text=fake_post_text) post_creator.block_user_with_username(username=user.username) url = self._get_url(hashtag_name=hashtag.name) response = self.client.get(url, **headers) self.assertEqual(response.status_code, status.HTTP_200_OK) parsed_response = json.loads(response.content) self.assertEqual(len(parsed_response), 0)