How to use post_comment method in Kiwi

Best Python code snippet using Kiwi_python

test_post_comment.py

Source:test_post_comment.py Github

copy

Full Screen

...22 fixtures = [23 'openbook_circles/fixtures/circles.json',24 'openbook_common/fixtures/languages.json'25 ]26 def test_can_get_own_post_comment(self):27 """28 should be able to get an own comment in own post and return 20029 """30 user = make_user()31 post = user.create_public_post(text=make_fake_post_text())32 post_comment_text = make_fake_post_comment_text()33 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)34 url = self._get_url(post_comment=post_comment, post=post)35 headers = make_authentication_headers_for_user(user)36 response = self.client.get(url, **headers)37 self.assertEqual(response.status_code, status.HTTP_200_OK)38 def test_can_get_foreign_public_post_comment(self):39 """40 should be able to get an own comment in a foreign public post and return 20041 """42 user = make_user()43 post_creator = make_user()44 commenter = make_user()45 foreign_post = post_creator.create_public_post(text=make_fake_post_text())46 post_comment_text = make_fake_post_comment_text()47 post_comment = commenter.comment_post_with_id(foreign_post.pk, text=post_comment_text)48 url = self._get_url(post_comment=post_comment, post=foreign_post)49 headers = make_authentication_headers_for_user(user)50 response = self.client.get(url, **headers)51 self.assertEqual(response.status_code, status.HTTP_200_OK)52 def test_can_get_foreign_encircled_post_comment_part_of(self):53 """54 should be able to get a foreign encircled post comment part of and return 20055 """56 user = make_user()57 post_creator = make_user()58 circle = make_user()59 post_creator.connect_with_user_with_id(user.pk)60 user.confirm_connection_with_user_with_id(post_creator.pk)61 commenter = make_user()62 post_creator.connect_with_user_with_id(commenter.pk)63 commenter.confirm_connection_with_user_with_id(post_creator.pk)64 foreign_post = post_creator.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])65 post_comment_text = make_fake_post_comment_text()66 post_comment = commenter.comment_post_with_id(foreign_post.pk, text=post_comment_text)67 url = self._get_url(post_comment=post_comment, post=foreign_post)68 headers = make_authentication_headers_for_user(user)69 response = self.client.get(url, **headers)70 self.assertEqual(response.status_code, status.HTTP_200_OK)71 def test_cant_get_foreign_encircled_post_comment_part_of(self):72 """73 should NOT be able to get a foreign encircled post comment NOT part of and return 40074 """75 user = make_user()76 post_creator = make_user()77 circle = make_user()78 commenter = make_user()79 post_creator.connect_with_user_with_id(commenter.pk)80 commenter.confirm_connection_with_user_with_id(post_creator.pk)81 foreign_post = post_creator.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])82 post_comment_text = make_fake_post_comment_text()83 post_comment = commenter.comment_post_with_id(foreign_post.pk, text=post_comment_text)84 url = self._get_url(post_comment=post_comment, post=foreign_post)85 headers = make_authentication_headers_for_user(user)86 response = self.client.get(url, **headers)87 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)88 def test_can_get_public_community_post_comment(self):89 """90 should be able to get a comment in a public community post and return 20091 """92 user = make_user()93 community_creator = make_user()94 community = make_community(creator=community_creator)95 community_post_creator = make_user()96 community_post_creator.join_community_with_name(community_name=community.name)97 community_post_commentator = make_user()98 community_post_commentator.join_community_with_name(community_name=community.name)99 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)100 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),101 post_id=post.pk)102 url = self._get_url(post_comment=post_comment, post=post)103 headers = make_authentication_headers_for_user(user)104 response = self.client.get(url, **headers)105 self.assertEqual(response.status_code, status.HTTP_200_OK)106 def test_can_get_private_community_post_comment_part_of(self):107 """108 should be able to get a comment in a private community part of post and return 200109 """110 user = make_user()111 community_creator = make_user()112 community = make_community(creator=community_creator, type=Community.COMMUNITY_TYPE_PRIVATE)113 community_creator.invite_user_with_username_to_community_with_name(username=user.username,114 community_name=community.name)115 user.join_community_with_name(community_name=community.name)116 community_post_creator = make_user()117 community_creator.invite_user_with_username_to_community_with_name(username=community_post_creator.username,118 community_name=community.name)119 community_post_creator.join_community_with_name(community_name=community.name)120 community_post_commentator = make_user()121 community_creator.invite_user_with_username_to_community_with_name(122 username=community_post_commentator.username,123 community_name=community.name)124 community_post_commentator.join_community_with_name(community_name=community.name)125 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)126 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),127 post_id=post.pk)128 url = self._get_url(post_comment=post_comment, post=post)129 headers = make_authentication_headers_for_user(user)130 response = self.client.get(url, **headers)131 self.assertEqual(response.status_code, status.HTTP_200_OK)132 def test_cant_get_private_community_post_comment_not_part_of(self):133 """134 should NOT be able to get a comment in a private community NOT part of post and return 200135 """136 user = make_user()137 community_creator = make_user()138 community = make_community(creator=community_creator, type=Community.COMMUNITY_TYPE_PRIVATE)139 community_post_creator = make_user()140 community_creator.invite_user_with_username_to_community_with_name(username=community_post_creator.username,141 community_name=community.name)142 community_post_creator.join_community_with_name(community_name=community.name)143 community_post_commentator = make_user()144 community_creator.invite_user_with_username_to_community_with_name(145 username=community_post_commentator.username,146 community_name=community.name)147 community_post_commentator.join_community_with_name(community_name=community.name)148 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)149 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),150 post_id=post.pk)151 url = self._get_url(post_comment=post_comment, post=post)152 headers = make_authentication_headers_for_user(user)153 response = self.client.get(url, **headers)154 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)155 def test_can_delete_foreign_comment_in_own_post(self):156 """157 should be able to delete a foreign comment in own post and return 200158 """159 user = make_user()160 commenter = make_user()161 post = user.create_public_post(text=make_fake_post_text())162 post_comment_text = make_fake_post_comment_text()163 post_comment = commenter.comment_post_with_id(post.pk, text=post_comment_text)164 url = self._get_url(post_comment=post_comment, post=post)165 headers = make_authentication_headers_for_user(user)166 response = self.client.delete(url, **headers)167 self.assertEqual(response.status_code, status.HTTP_200_OK)168 self.assertFalse(PostComment.objects.filter(id=post_comment.pk).exists())169 def test_can_delete_community_post_comment_if_mod(self):170 """171 should be able to delete a community post comment if is moderator and return 200172 """173 user = make_user()174 community_creator = make_user()175 community = make_community(creator=community_creator)176 user.join_community_with_name(community_name=community.name)177 community_creator.add_moderator_with_username_to_community_with_name(username=user.username,178 community_name=community.name)179 community_post_creator = make_user()180 community_post_creator.join_community_with_name(community_name=community.name)181 community_post_commentator = make_user()182 community_post_commentator.join_community_with_name(community_name=community.name)183 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)184 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),185 post_id=post.pk)186 url = self._get_url(post_comment=post_comment, post=post)187 headers = make_authentication_headers_for_user(user)188 response = self.client.delete(url, **headers)189 self.assertEqual(response.status_code, status.HTTP_200_OK)190 self.assertFalse(PostComment.objects.filter(id=post_comment.pk).exists())191 def test_can_delete_community_post_comment_if_admin(self):192 """193 should be able to delete a community post comment if is administrator and return 200194 """195 user = make_user()196 community_creator = make_user()197 community = make_community(creator=community_creator)198 user.join_community_with_name(community_name=community.name)199 community_creator.add_administrator_with_username_to_community_with_name(username=user.username,200 community_name=community.name)201 community_post_creator = make_user()202 community_post_creator.join_community_with_name(community_name=community.name)203 community_post_commentator = make_user()204 community_post_commentator.join_community_with_name(community_name=community.name)205 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)206 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),207 post_id=post.pk)208 url = self._get_url(post_comment=post_comment, post=post)209 headers = make_authentication_headers_for_user(user)210 response = self.client.delete(url, **headers)211 self.assertEqual(response.status_code, status.HTTP_200_OK)212 self.assertFalse(PostComment.objects.filter(id=post_comment.pk).exists())213 def test_can_delete_community_post_comment_for_post_with_disabled_comments_if_comment_owner(self):214 """215 should be able to delete a community post comment for post with disabled comments if comment owner216 """217 user = make_user()218 admin = make_user()219 community = make_community(creator=admin)220 user.join_community_with_name(community_name=community.name)221 community_post_creator = make_user()222 community_post_creator.join_community_with_name(community_name=community.name)223 commenter = make_user()224 commenter.join_community_with_name(community_name=community.name)225 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)226 post_comment = commenter.comment_post_with_id(text=make_fake_post_comment_text(),227 post_id=post.pk)228 post.comments_enabled = False229 post.save()230 url = self._get_url(post_comment=post_comment, post=post)231 headers = make_authentication_headers_for_user(commenter)232 response = self.client.delete(url, **headers)233 self.assertEqual(response.status_code, status.HTTP_200_OK)234 self.assertFalse(PostComment.objects.filter(id=post_comment.pk).exists())235 def test_can_delete_community_post_comment_with_disabled_comments_if_admin(self):236 """237 should be able to delete a community post comment for post with comments disabled if administrator238 """239 user = make_user()240 community_creator = make_user()241 community = make_community(creator=community_creator)242 user.join_community_with_name(community_name=community.name)243 community_creator.add_administrator_with_username_to_community_with_name(username=user.username,244 community_name=community.name)245 community_post_creator = make_user()246 community_post_creator.join_community_with_name(community_name=community.name)247 community_post_commentator = make_user()248 community_post_commentator.join_community_with_name(community_name=community.name)249 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)250 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),251 post_id=post.pk)252 post.comments_enabled = False253 post.save()254 url = self._get_url(post_comment=post_comment, post=post)255 headers = make_authentication_headers_for_user(user)256 response = self.client.delete(url, **headers)257 self.assertEqual(response.status_code, status.HTTP_200_OK)258 self.assertFalse(PostComment.objects.filter(id=post_comment.pk).exists())259 def test_can_delete_community_post_comment_for_post_with_disabled_comments_if_moderator(self):260 """261 should be able to delete a community post comment for post with disabled comments if moderator262 """263 user = make_user()264 community_creator = make_user()265 community = make_community(creator=community_creator)266 user.join_community_with_name(community_name=community.name)267 community_creator.add_moderator_with_username_to_community_with_name(username=user.username,268 community_name=community.name)269 community_post_creator = make_user()270 community_post_creator.join_community_with_name(community_name=community.name)271 community_post_commentator = make_user()272 community_post_commentator.join_community_with_name(community_name=community.name)273 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)274 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),275 post_id=post.pk)276 post.comments_enabled = False277 post.save()278 url = self._get_url(post_comment=post_comment, post=post)279 headers = make_authentication_headers_for_user(user)280 response = self.client.delete(url, **headers)281 self.assertEqual(response.status_code, status.HTTP_200_OK)282 self.assertFalse(PostComment.objects.filter(id=post_comment.pk).exists())283 def test_can_delete_community_post_comment_with_closed_post_if_admin(self):284 """285 should be able to delete a community post comment for closed post if administrator286 """287 user = make_user()288 community_creator = make_user()289 community = make_community(creator=community_creator)290 user.join_community_with_name(community_name=community.name)291 community_creator.add_administrator_with_username_to_community_with_name(username=user.username,292 community_name=community.name)293 community_post_creator = make_user()294 community_post_creator.join_community_with_name(community_name=community.name)295 community_post_commentator = make_user()296 community_post_commentator.join_community_with_name(community_name=community.name)297 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)298 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),299 post_id=post.pk)300 post.is_closed = True301 post.save()302 url = self._get_url(post_comment=post_comment, post=post)303 headers = make_authentication_headers_for_user(user)304 response = self.client.delete(url, **headers)305 self.assertEqual(response.status_code, status.HTTP_200_OK)306 self.assertFalse(PostComment.objects.filter(id=post_comment.pk).exists())307 def test_can_delete_community_post_comment_for_closed_post_if_moderator(self):308 """309 should be able to delete a community post comment for closed post if moderator310 """311 user = make_user()312 community_creator = make_user()313 community = make_community(creator=community_creator)314 user.join_community_with_name(community_name=community.name)315 community_creator.add_moderator_with_username_to_community_with_name(username=user.username,316 community_name=community.name)317 community_post_creator = make_user()318 community_post_creator.join_community_with_name(community_name=community.name)319 community_post_commentator = make_user()320 community_post_commentator.join_community_with_name(community_name=community.name)321 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)322 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),323 post_id=post.pk)324 post.is_closed = True325 post.save()326 url = self._get_url(post_comment=post_comment, post=post)327 headers = make_authentication_headers_for_user(user)328 response = self.client.delete(url, **headers)329 self.assertEqual(response.status_code, status.HTTP_200_OK)330 self.assertFalse(PostComment.objects.filter(id=post_comment.pk).exists())331 def test_cannot_delete_community_post_comment_for_closed_post_if_comment_owner(self):332 """333 should NOT be able to delete a community post comment for closed post if comment owner334 """335 user = make_user()336 admin = make_user()337 community = make_community(creator=admin)338 user.join_community_with_name(community_name=community.name)339 community_post_creator = make_user()340 community_post_creator.join_community_with_name(community_name=community.name)341 commenter = make_user()342 commenter.join_community_with_name(community_name=community.name)343 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)344 post_comment = commenter.comment_post_with_id(text=make_fake_post_comment_text(),345 post_id=post.pk)346 post.is_closed = True347 post.save()348 url = self._get_url(post_comment=post_comment, post=post)349 headers = make_authentication_headers_for_user(commenter)350 response = self.client.delete(url, **headers)351 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)352 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).exists())353 def test_cannot_delete_own_community_post_comment_for_closed_post_if_post_creator(self):354 """355 should NOT be able to delete own community post comment for closed post if post creator356 """357 user = make_user()358 admin = make_user()359 community = make_community(creator=admin)360 user.join_community_with_name(community_name=community.name)361 community_post_creator = make_user()362 community_post_creator.join_community_with_name(community_name=community.name)363 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)364 post_comment = community_post_creator.comment_post_with_id(text=make_fake_post_comment_text(),365 post_id=post.pk)366 post.is_closed = True367 post.save()368 url = self._get_url(post_comment=post_comment, post=post)369 headers = make_authentication_headers_for_user(community_post_creator)370 response = self.client.delete(url, **headers)371 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)372 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).exists())373 def test_logs_community_post_comment_deleted_by_non_creator(self):374 """375 should create a log when a community post comment was deleted by an admin/moderator376 """377 user = make_user()378 community_creator = make_user()379 community = make_community(creator=community_creator)380 user.join_community_with_name(community_name=community.name)381 community_creator.add_administrator_with_username_to_community_with_name(username=user.username,382 community_name=community.name)383 community_post_creator = make_user()384 community_post_creator.join_community_with_name(community_name=community.name)385 community_post_commentator = make_user()386 community_post_commentator.join_community_with_name(community_name=community.name)387 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)388 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),389 post_id=post.pk)390 url = self._get_url(post_comment=post_comment, post=post)391 headers = make_authentication_headers_for_user(user)392 self.client.delete(url, **headers)393 self.assertTrue(394 community.logs.filter(action_type='RPC', target_user=community_post_commentator, source_user=user).exists())395 def test_can_delete_own_comment_in_foreign_public_post(self):396 """397 should be able to delete own comment in foreign public post and return 200398 """399 user = make_user()400 foreign_user = make_user()401 post = foreign_user.create_public_post(text=make_fake_post_text())402 post_comment_text = make_fake_post_comment_text()403 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)404 url = self._get_url(post_comment=post_comment, post=post)405 headers = make_authentication_headers_for_user(user)406 response = self.client.delete(url, **headers)407 self.assertEqual(response.status_code, status.HTTP_200_OK)408 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 0)409 def test_cannot_delete_foreign_comment_in_foreign_public_post(self):410 """411 should NOT be able to delete foreign comment in foreign public post and return 400412 """413 user = make_user()414 foreign_user = make_user()415 post = foreign_user.create_public_post(text=make_fake_post_text())416 post_comment_text = make_fake_post_comment_text()417 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)418 url = self._get_url(post_comment=post_comment, post=post)419 headers = make_authentication_headers_for_user(user)420 response = self.client.delete(url, **headers)421 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)422 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 1)423 def test_can_delete_own_comment_in_connected_user_public_post(self):424 """425 should be able to delete own comment in a connected user public post and return 200426 """427 user = make_user()428 user_to_connect = make_user()429 user.connect_with_user_with_id(user_to_connect.pk)430 user_to_connect.confirm_connection_with_user_with_id(user.pk)431 post = user_to_connect.create_public_post(text=make_fake_post_text())432 post_comment_text = make_fake_post_comment_text()433 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)434 url = self._get_url(post_comment=post_comment, post=post)435 headers = make_authentication_headers_for_user(user)436 response = self.client.delete(url, **headers)437 self.assertEqual(response.status_code, status.HTTP_200_OK)438 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 0)439 def test_cannot_delete_foreign_comment_in_connected_user_public_post(self):440 """441 should not be able to delete foreign comment in a connected user public post and return 400442 """443 user = make_user()444 user_to_connect = make_user()445 user.connect_with_user_with_id(user_to_connect.pk)446 user_to_connect.confirm_connection_with_user_with_id(user.pk)447 foreign_user = make_user()448 post = user_to_connect.create_public_post(text=make_fake_post_text())449 post_comment_text = make_fake_post_comment_text()450 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)451 url = self._get_url(post_comment=post_comment, post=post)452 headers = make_authentication_headers_for_user(user)453 response = self.client.delete(url, **headers)454 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)455 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 1)456 def test_can_delete_own_comment_in_connected_user_encircled_post_part_of(self):457 """458 should be able to delete own comment in a connected user encircled post it's part of and return 200459 """460 user = make_user()461 user_to_connect = make_user()462 circle = make_circle(creator=user_to_connect)463 user.connect_with_user_with_id(user_to_connect.pk)464 user_to_connect.confirm_connection_with_user_with_id(user.pk, circles_ids=[circle.pk])465 post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])466 post_comment_text = make_fake_post_comment_text()467 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)468 url = self._get_url(post_comment=post_comment, post=post)469 headers = make_authentication_headers_for_user(user)470 response = self.client.delete(url, **headers)471 self.assertEqual(response.status_code, status.HTTP_200_OK)472 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 0)473 def test_cannot_delete_foreign_comment_in_connected_user_encircled_post_part_of(self):474 """475 should NOT be able to delete foreign comment in a connected user encircled post it's part of and return 400476 """477 user = make_user()478 user_to_connect = make_user()479 circle = make_circle(creator=user_to_connect)480 user.connect_with_user_with_id(user_to_connect.pk)481 user_to_connect.confirm_connection_with_user_with_id(user.pk, circles_ids=[circle.pk])482 foreign_user = make_user()483 foreign_user.connect_with_user_with_id(user_to_connect.pk)484 user_to_connect.confirm_connection_with_user_with_id(foreign_user.pk, circles_ids=[circle.pk])485 post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])486 post_comment_text = make_fake_post_comment_text()487 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)488 url = self._get_url(post_comment=post_comment, post=post)489 headers = make_authentication_headers_for_user(user)490 response = self.client.delete(url, **headers)491 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)492 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 1)493 def test_cannot_delete_foreign_comment_in_connected_user_encircled_post_not_part_of(self):494 """495 should NOT be able to delete foreign comment in a connected user encircled post NOT part of and return 400496 """497 user = make_user()498 user_to_connect = make_user()499 circle = make_circle(creator=user_to_connect)500 foreign_user = make_user()501 foreign_user.connect_with_user_with_id(user_to_connect.pk)502 user_to_connect.confirm_connection_with_user_with_id(foreign_user.pk, circles_ids=[circle.pk])503 post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])504 post_comment_text = make_fake_post_comment_text()505 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)506 url = self._get_url(post_comment=post_comment, post=post)507 headers = make_authentication_headers_for_user(user)508 response = self.client.delete(url, **headers)509 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)510 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 1)511 def test_can_delete_own_comment_in_followed_user_public_post(self):512 """513 should be able to delete own comment in a followed user public post and return 200514 """515 user = make_user()516 user_to_follow = make_user()517 user.follow_user_with_id(user_to_follow.pk)518 post = user_to_follow.create_public_post(text=make_fake_post_text())519 post_comment_text = make_fake_post_comment_text()520 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)521 url = self._get_url(post_comment=post_comment, post=post)522 headers = make_authentication_headers_for_user(user)523 response = self.client.delete(url, **headers)524 self.assertEqual(response.status_code, status.HTTP_200_OK)525 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 0)526 def test_cannot_delete_foreign_comment_in_followed_user_public_post(self):527 """528 should not be able to delete foreign comment in a followed user public post and return 400529 """530 user = make_user()531 user_to_follow = make_user()532 user.follow_user_with_id(user_to_follow.pk)533 foreign_user = make_user()534 post = user_to_follow.create_public_post(text=make_fake_post_text())535 post_comment_text = make_fake_post_comment_text()536 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)537 url = self._get_url(post_comment=post_comment, post=post)538 headers = make_authentication_headers_for_user(user)539 response = self.client.delete(url, **headers)540 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)541 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 1)542 def test_cannot_delete_foreign_comment_in_folowed_user_encircled_post(self):543 """544 should not be able to delete foreign comment in a followed user encircled post and return 400545 """546 user = make_user()547 user_to_follow = make_user()548 circle = make_circle(creator=user_to_follow)549 user.follow_user_with_id(user_to_follow.pk)550 foreign_user = make_user()551 foreign_user.connect_with_user_with_id(user_to_follow.pk)552 user_to_follow.confirm_connection_with_user_with_id(foreign_user.pk, circles_ids=[circle.pk])553 post = user_to_follow.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])554 post_comment_text = make_fake_post_comment_text()555 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)556 url = self._get_url(post_comment=post_comment, post=post)557 headers = make_authentication_headers_for_user(user)558 response = self.client.delete(url, **headers)559 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)560 self.assertTrue(PostComment.objects.filter(id=post_comment.pk).count() == 1)561 def test_post_comment_notification_is_deleted_when_deleting_comment(self):562 """563 should delete the post comment notification when a post comment is deleted564 """565 user = make_user()566 commenter = make_user()567 post = user.create_public_post(text=make_fake_post_text())568 post_comment_text = make_fake_post_comment_text()569 post_comment = commenter.comment_post_with_id(post.pk, text=post_comment_text)570 post_comment_notification = PostCommentNotification.objects.get(post_comment=post_comment,571 notification__owner=user)572 notification = Notification.objects.get(notification_type=Notification.POST_COMMENT,573 object_id=post_comment_notification.pk)574 url = self._get_url(post_comment=post_comment, post=post)575 headers = make_authentication_headers_for_user(commenter)576 self.client.delete(url, **headers)577 self.assertFalse(PostCommentReplyNotification.objects.filter(pk=post_comment_notification.pk).exists())578 self.assertFalse(Notification.objects.filter(pk=notification.pk).exists())579 def test_can_edit_own_post_comment_on_own_post(self):580 """581 should be able to edit own post comment582 """583 user = make_user()584 post = user.create_public_post(text=make_fake_post_text())585 original_post_comment_text = make_fake_post_comment_text()586 post_comment = user.comment_post_with_id(post.pk, text=original_post_comment_text)587 url = self._get_url(post_comment=post_comment, post=post)588 edited_post_comment_text = make_fake_post_comment_text()589 headers = make_authentication_headers_for_user(user)590 response = self.client.patch(url, {591 'text': edited_post_comment_text592 }, **headers)593 self.assertEqual(response.status_code, status.HTTP_200_OK)594 post_comment.refresh_from_db()595 self.assertTrue(post_comment.text == edited_post_comment_text)596 self.assertTrue(post_comment.is_edited)597 def test_editing_own_post_comment_updates_mentions(self):598 """599 should update mentions when updating text600 """601 user = make_user()602 headers = make_authentication_headers_for_user(user=user)603 mentioned_user = make_user()604 post_comment_text = 'Hello @' + mentioned_user.username605 post = user.create_public_post(text=make_fake_post_text())606 post_comment = user.comment_post(post=post, text=post_comment_text)607 post_comment_user_mention = PostCommentUserMention.objects.get(user_id=mentioned_user.pk,608 post_comment_id=post_comment.pk)609 newly_mentioned_user = make_user()610 post_comment_text = 'Hello @' + newly_mentioned_user.username611 data = {612 'text': post_comment_text613 }614 url = self._get_url(post_comment=post_comment, post=post)615 response = self.client.patch(url, data, **headers, format='multipart')616 self.assertEqual(status.HTTP_200_OK, response.status_code)617 post_comment = PostComment.objects.get(text=post_comment_text, commenter_id=user.pk)618 self.assertFalse(619 PostCommentUserMention.objects.filter(user_id=mentioned_user.pk, post_comment_id=post_comment.pk).exists())620 self.assertEqual(PostCommentUserMention.objects.filter(user_id=newly_mentioned_user.pk,621 post_comment_id=post_comment.pk).count(), 1)622 new_post_comment_user_mention = PostCommentUserMention.objects.get(user_id=newly_mentioned_user.pk,623 post_comment_id=post_comment.pk)624 self.assertFalse(625 PostCommentUserMentionNotification.objects.filter(post_comment_user_mention_id=post_comment_user_mention.pk,626 notification__owner_id=mentioned_user.pk,627 notification__notification_type=Notification.POST_COMMENT_USER_MENTION).exists())628 self.assertTrue(PostCommentUserMentionNotification.objects.filter(629 post_comment_user_mention_id=new_post_comment_user_mention.pk,630 notification__owner_id=newly_mentioned_user.pk,631 notification__notification_type=Notification.POST_COMMENT_USER_MENTION).exists())632 def test_editing_text_post_comment_ignores_non_existing_mentioned_usernames(self):633 """634 should ignore non existing mentioned usernames when editing a post_comment635 """636 user = make_user()637 headers = make_authentication_headers_for_user(user=user)638 post = user.create_public_post(text=make_fake_post_text())639 post_comment = user.comment_post(post=post, text=make_fake_post_text())640 fake_username = 'nonexistinguser'641 post_comment_text = 'Hello @' + fake_username642 data = {643 'text': post_comment_text644 }645 url = self._get_url(post_comment=post_comment, post=post)646 response = self.client.patch(url, data, **headers, format='multipart')647 self.assertEqual(response.status_code, status.HTTP_200_OK)648 post_comment = PostComment.objects.get(text=post_comment_text, commenter_id=user.pk)649 self.assertEqual(PostCommentUserMention.objects.filter(post_comment_id=post_comment.pk).count(), 0)650 def test_editing_text_post_comment_ignores_casing_of_mentioned_usernames(self):651 """652 should ignore non existing mentioned usernames casings when editing a post_comment653 """654 user = make_user()655 newly_mentioned_user = make_user(username='Miguel')656 headers = make_authentication_headers_for_user(user=user)657 post = user.create_public_post(text=make_fake_post_text())658 post_comment = user.comment_post(post=post, text=make_fake_post_text())659 post_comment_text = 'Hello @miguel'660 data = {661 'text': post_comment_text662 }663 url = self._get_url(post_comment=post_comment, post=post)664 response = self.client.patch(url, data, **headers, format='multipart')665 self.assertEqual(response.status_code, status.HTTP_200_OK)666 post_comment = PostComment.objects.get(text=post_comment_text, commenter_id=user.pk)667 self.assertTrue(PostCommentUserMention.objects.filter(user_id=newly_mentioned_user.pk,668 post_comment_id=post_comment.pk).exists())669 def test_editing_own_post_comment_does_not_create_double_mentions(self):670 """671 should not create double mentions when editing our own post_comment672 """673 user = make_user()674 headers = make_authentication_headers_for_user(user=user)675 mentioned_user = make_user()676 post_comment_text = 'Hello @' + mentioned_user.username677 post = user.create_public_post(text=make_fake_post_text())678 post_comment = user.comment_post(post=post, text=post_comment_text)679 post_comment_user_mention = PostCommentUserMention.objects.get(user_id=mentioned_user.pk,680 post_comment_id=post_comment.pk)681 data = {682 'text': post_comment_text683 }684 url = self._get_url(post_comment=post_comment, post=post)685 response = self.client.patch(url, data, **headers, format='multipart')686 self.assertEqual(status.HTTP_200_OK, response.status_code)687 post_comment = PostComment.objects.get(text=post_comment_text, commenter_id=user.pk)688 self.assertEqual(689 PostCommentUserMention.objects.filter(user_id=mentioned_user.pk, post_comment_id=post_comment.pk).count(),690 1)691 new_post_comment_user_mention = PostCommentUserMention.objects.get(user_id=mentioned_user.pk,692 post_comment_id=post_comment.pk,693 id=post_comment_user_mention.pk)694 self.assertEqual(new_post_comment_user_mention.pk, post_comment_user_mention.pk)695 def test_editing_own_post_comment_comment_with_hashtag_creates_hashtag_if_not_exist(self):696 """697 when editing a post comment with a hashtag, should create it if not exists698 """699 user = make_user()700 headers = make_authentication_headers_for_user(user=user)701 hashtag_name = make_hashtag_name()702 post_comment_text = 'One hashtag #' + hashtag_name703 post = user.create_public_post(text=make_fake_post_text())704 post_comment = user.comment_post(post=post, text=post_comment_text)705 new_hashtag_name = make_hashtag_name()706 new_post_comment_commenttext = 'Another hashtag #' + new_hashtag_name707 data = {708 'text': new_post_comment_commenttext709 }710 url = self._get_url(post=post, post_comment=post_comment)711 response = self.client.patch(url, data, **headers, format='multipart')712 self.assertEqual(status.HTTP_200_OK, response.status_code)713 created_hashtag = Hashtag.objects.get(name=new_hashtag_name)714 self.assertTrue(post_comment.hashtags.filter(pk=created_hashtag.pk).exists())715 self.assertEqual(post_comment.hashtags.all().count(), 1)716 def test_editing_own_post_comment_comment_with_hashtag_updates_to_existing_hashtag_exists(self):717 """718 when editing a post comment with a hashtag, should update to it if exists719 """720 user = make_user()721 headers = make_authentication_headers_for_user(user=user)722 hashtag = make_hashtag()723 post_comment_text = 'One hashtag #' + hashtag.name724 post = user.create_public_post(text=make_fake_post_text())725 post_comment = user.comment_post(post=post, text=post_comment_text)726 new_hashtag = make_hashtag()727 new_post_comment_commenttext = 'Another hashtag #' + new_hashtag.name728 data = {729 'text': new_post_comment_commenttext730 }731 url = self._get_url(post=post, post_comment=post_comment)732 response = self.client.patch(url, data, **headers, format='multipart')733 self.assertEqual(status.HTTP_200_OK, response.status_code)734 self.assertTrue(post_comment.hashtags.filter(pk=new_hashtag.pk).exists())735 self.assertEqual(post_comment.hashtags.all().count(), 1)736 def test_editing_own_post_comment_comment_with_hashtag_does_not_create_double_hashtags(self):737 """738 when editing a post comment with a hashtag, should not create duplicate hashtags739 """740 user = make_user()741 headers = make_authentication_headers_for_user(user=user)742 hashtag = make_hashtag()743 post_comment_text = 'One hashtag #' + hashtag.name744 post = user.create_public_post(text=make_fake_post_text())745 post_comment = user.comment_post(post=post, text=post_comment_text)746 new_post_comment_commenttext = 'Same hashtag #' + hashtag.name747 data = {748 'text': new_post_comment_commenttext749 }750 url = self._get_url(post_comment=post_comment, post=post)751 response = self.client.patch(url, data, **headers, format='multipart')752 self.assertEqual(status.HTTP_200_OK, response.status_code)753 self.assertEqual(post_comment.hashtags.filter(name=hashtag.name).count(), 1)754 self.assertEqual(post_comment.hashtags.all().count(), 1)755 @mock.patch('openbook_posts.models.get_language_for_text')756 def test_editing_own_post_comment_updates_language_of_comment(self, get_language_for_text_call):757 """758 should update language of comment when editing post comment759 """760 Language = get_language_model()761 get_language_for_text_call.return_value = Language.objects.get(id=1)762 user = make_user()763 post = user.create_public_post(text=make_fake_post_text())764 original_post_comment_text = make_fake_post_comment_text()765 post_comment = user.comment_post_with_id(post.pk, text=original_post_comment_text)766 url = self._get_url(post_comment=post_comment, post=post)767 edited_post_comment_text = make_fake_post_comment_text()768 headers = make_authentication_headers_for_user(user)769 response = self.client.patch(url, {770 'text': edited_post_comment_text771 }, **headers)772 self.assertEqual(response.status_code, status.HTTP_200_OK)773 get_language_for_text_call.assert_called_with(edited_post_comment_text)774 def test_can_edit_own_post_comment_on_others_post(self):775 """776 should be able to edit own post comment on someone else's post777 """778 user = make_user()779 post_creator = make_user()780 post = post_creator.create_public_post(text=make_fake_post_text())781 original_post_comment_text = make_fake_post_comment_text()782 post_comment = user.comment_post_with_id(post.pk, text=original_post_comment_text)783 url = self._get_url(post_comment=post_comment, post=post)784 edited_post_comment_text = make_fake_post_comment_text()785 headers = make_authentication_headers_for_user(user)786 response = self.client.patch(url, {787 'text': edited_post_comment_text788 }, **headers)789 self.assertEqual(response.status_code, status.HTTP_200_OK)790 post_comment.refresh_from_db()791 self.assertTrue(post_comment.text == edited_post_comment_text)792 def test_cannot_edit_others_post_comment(self):793 """794 should not be able to edit someone else's comment795 """796 user = make_user()797 commenter = make_user()798 post = user.create_public_post(text=make_fake_post_text())799 original_post_comment_text = make_fake_post_comment_text()800 post_comment = commenter.comment_post_with_id(post.pk, text=original_post_comment_text)801 url = self._get_url(post_comment=post_comment, post=post)802 edited_post_comment_text = make_fake_post_comment_text()803 headers = make_authentication_headers_for_user(user)804 response = self.client.patch(url, {805 'text': edited_post_comment_text806 }, **headers)807 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)808 post_comment.refresh_from_db()809 self.assertTrue(post_comment.text == original_post_comment_text)810 self.assertFalse(post_comment.is_edited)811 def test_cannot_edit_post_comment_if_comments_disabled(self):812 """813 should not be able to edit own comment if comments are disabled814 """815 admin = make_user()816 user = make_user()817 community = make_community(admin)818 user.join_community_with_name(community_name=community.name)819 post = user.create_community_post(community.name, text=make_fake_post_text())820 original_post_comment_text = make_fake_post_comment_text()821 post_comment = user.comment_post_with_id(post.pk, text=original_post_comment_text)822 post.comments_enabled = False823 post.save()824 url = self._get_url(post_comment=post_comment, post=post)825 edited_post_comment_text = make_fake_post_comment_text()826 headers = make_authentication_headers_for_user(user)827 response = self.client.patch(url, {828 'text': edited_post_comment_text829 }, **headers)830 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)831 post_comment.refresh_from_db()832 self.assertTrue(post_comment.text == original_post_comment_text)833 self.assertFalse(post_comment.is_edited)834 def test_cannot_edit_post_comment_if_post_closed_and_not_not_post_creator(self):835 """836 should NOT be able to edit own comment if post is closed and not post creator837 """838 admin = make_user()839 user = make_user()840 community = make_community(admin)841 user.join_community_with_name(community_name=community.name)842 post = admin.create_community_post(community.name, text=make_fake_post_text())843 original_post_comment_text = make_fake_post_comment_text()844 post_comment = user.comment_post_with_id(post.pk, text=original_post_comment_text)845 post.is_closed = True846 post.save()847 url = self._get_url(post_comment=post_comment, post=post)848 edited_post_comment_text = make_fake_post_comment_text()849 headers = make_authentication_headers_for_user(user)850 response = self.client.patch(url, {851 'text': edited_post_comment_text852 }, **headers)853 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)854 post_comment.refresh_from_db()855 self.assertTrue(post_comment.text == original_post_comment_text)856 self.assertFalse(post_comment.is_edited)857 def test_cannot_edit_post_comment_if_post_closed_and_post_creator(self):858 """859 should NOT be able to edit own comment if post is closed even if post creator860 """861 admin = make_user()862 user = make_user()863 community = make_community(admin)864 user.join_community_with_name(community_name=community.name)865 post = user.create_community_post(community.name, text=make_fake_post_text())866 original_post_comment_text = make_fake_post_comment_text()867 post_comment = user.comment_post_with_id(post.pk, text=original_post_comment_text)868 post.is_closed = True869 post.save()870 url = self._get_url(post_comment=post_comment, post=post)871 edited_post_comment_text = make_fake_post_comment_text()872 headers = make_authentication_headers_for_user(user)873 response = self.client.patch(url, {874 'text': edited_post_comment_text875 }, **headers)876 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)877 post_comment.refresh_from_db()878 self.assertTrue(post_comment.text == original_post_comment_text)879 self.assertFalse(post_comment.is_edited)880 def test_cannot_edit_others_community_post_comment_even_if_admin(self):881 """882 should not be able to edit someone else's comment even if community admin883 """884 user = make_user()885 admin = make_user()886 community = make_community(admin)887 user.join_community_with_name(community_name=community.name)888 post = user.create_community_post(community.name, text=make_fake_post_text())889 original_post_comment_text = make_fake_post_comment_text()890 post_comment = user.comment_post_with_id(post.pk, text=original_post_comment_text)891 url = self._get_url(post_comment=post_comment, post=post)892 edited_post_comment_text = make_fake_post_comment_text()893 headers = make_authentication_headers_for_user(admin)894 response = self.client.patch(url, {895 'text': edited_post_comment_text896 }, **headers)897 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)898 post_comment.refresh_from_db()899 self.assertTrue(post_comment.text == original_post_comment_text)900 # Post Comments that are replies901 def test_can_delete_foreign_comment_reply_in_own_post(self):902 """903 should be able to delete a foreign comment reply in own post and return 200904 """905 user = make_user()906 commenter = make_user()907 post = user.create_public_post(text=make_fake_post_text())908 post_comment_reply_text = make_fake_post_comment_text()909 post_comment = commenter.comment_post_with_id(post.pk, text=make_fake_post_comment_text())910 post_comment_reply = commenter.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,911 post_uuid=post.uuid,912 text=post_comment_reply_text)913 url = self._get_url(post_comment=post_comment_reply, post=post)914 headers = make_authentication_headers_for_user(user)915 response = self.client.delete(url, **headers)916 self.assertEqual(response.status_code, status.HTTP_200_OK)917 self.assertFalse(PostComment.objects.filter(id=post_comment_reply.pk).exists())918 def test_can_delete_community_post_comment_reply_if_mod(self):919 """920 should be able to delete a community post comment reply if is moderator and return 200921 """922 user = make_user()923 community_creator = make_user()924 community = make_community(creator=community_creator)925 user.join_community_with_name(community_name=community.name)926 community_creator.add_moderator_with_username_to_community_with_name(username=user.username,927 community_name=community.name)928 community_post_creator = make_user()929 community_post_creator.join_community_with_name(community_name=community.name)930 community_post_commentator = make_user()931 community_post_commentator.join_community_with_name(community_name=community.name)932 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)933 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),934 post_id=post.pk)935 post_comment_reply = \936 community_post_commentator.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,937 post_uuid=post.uuid,938 text=make_fake_post_comment_text())939 url = self._get_url(post_comment=post_comment_reply, post=post)940 headers = make_authentication_headers_for_user(user)941 response = self.client.delete(url, **headers)942 self.assertEqual(response.status_code, status.HTTP_200_OK)943 self.assertFalse(PostComment.objects.filter(id=post_comment_reply.pk).exists())944 def test_can_delete_community_post_comment_reply_if_admin(self):945 """946 should be able to delete a community post comment reply if is administrator and return 200947 """948 user = make_user()949 community_creator = make_user()950 community = make_community(creator=community_creator)951 user.join_community_with_name(community_name=community.name)952 community_creator.add_administrator_with_username_to_community_with_name(username=user.username,953 community_name=community.name)954 community_post_creator = make_user()955 community_post_creator.join_community_with_name(community_name=community.name)956 community_post_commentator = make_user()957 community_post_commentator.join_community_with_name(community_name=community.name)958 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)959 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),960 post_id=post.pk)961 post_comment_reply = \962 community_post_commentator.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,963 post_uuid=post.uuid,964 text=make_fake_post_comment_text())965 url = self._get_url(post_comment=post_comment_reply, post=post)966 headers = make_authentication_headers_for_user(user)967 response = self.client.delete(url, **headers)968 self.assertEqual(response.status_code, status.HTTP_200_OK)969 self.assertFalse(PostComment.objects.filter(id=post_comment_reply.pk).exists())970 def test_can_delete_community_post_comment_reply_for_post_with_disabled_comments_if_comment_owner(self):971 """972 should be able to delete a community post comment reply for post with disabled comments if comment owner973 """974 user = make_user()975 admin = make_user()976 community = make_community(creator=admin)977 user.join_community_with_name(community_name=community.name)978 community_post_creator = make_user()979 community_post_creator.join_community_with_name(community_name=community.name)980 commenter = make_user()981 commenter.join_community_with_name(community_name=community.name)982 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)983 post_comment = commenter.comment_post_with_id(text=make_fake_post_comment_text(),984 post_id=post.pk)985 post_comment_reply = \986 commenter.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,987 post_uuid=post.uuid,988 text=make_fake_post_comment_text())989 post.comments_enabled = False990 post.save()991 url = self._get_url(post_comment=post_comment_reply, post=post)992 headers = make_authentication_headers_for_user(commenter)993 response = self.client.delete(url, **headers)994 self.assertEqual(response.status_code, status.HTTP_200_OK)995 self.assertFalse(PostComment.objects.filter(id=post_comment_reply.pk).exists())996 def test_can_delete_community_post_comment_reply_with_disabled_comments_if_admin(self):997 """998 should be able to delete a community post comment reply for post with comments disabled if administrator999 """1000 user = make_user()1001 community_creator = make_user()1002 community = make_community(creator=community_creator)1003 user.join_community_with_name(community_name=community.name)1004 community_creator.add_administrator_with_username_to_community_with_name(username=user.username,1005 community_name=community.name)1006 community_post_creator = make_user()1007 community_post_creator.join_community_with_name(community_name=community.name)1008 community_post_commentator = make_user()1009 community_post_commentator.join_community_with_name(community_name=community.name)1010 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)1011 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),1012 post_id=post.pk)1013 post_comment_reply = \1014 community_post_commentator.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1015 post_uuid=post.uuid,1016 text=make_fake_post_comment_text())1017 post.comments_enabled = False1018 post.save()1019 url = self._get_url(post_comment=post_comment_reply, post=post)1020 headers = make_authentication_headers_for_user(user)1021 response = self.client.delete(url, **headers)1022 self.assertEqual(response.status_code, status.HTTP_200_OK)1023 self.assertFalse(PostComment.objects.filter(id=post_comment_reply.pk).exists())1024 def test_can_delete_community_post_comment_reply_for_post_with_disabled_comments_if_moderator(self):1025 """1026 should be able to delete a community post comment reply for post with disabled comments if moderator1027 """1028 user = make_user()1029 community_creator = make_user()1030 community = make_community(creator=community_creator)1031 user.join_community_with_name(community_name=community.name)1032 community_creator.add_moderator_with_username_to_community_with_name(username=user.username,1033 community_name=community.name)1034 community_post_creator = make_user()1035 community_post_creator.join_community_with_name(community_name=community.name)1036 community_post_commentator = make_user()1037 community_post_commentator.join_community_with_name(community_name=community.name)1038 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)1039 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),1040 post_id=post.pk)1041 post_comment_reply = \1042 community_post_commentator.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1043 post_uuid=post.uuid,1044 text=make_fake_post_comment_text())1045 post.comments_enabled = False1046 post.save()1047 url = self._get_url(post_comment=post_comment_reply, post=post)1048 headers = make_authentication_headers_for_user(user)1049 response = self.client.delete(url, **headers)1050 self.assertEqual(response.status_code, status.HTTP_200_OK)1051 self.assertFalse(PostComment.objects.filter(id=post_comment_reply.pk).exists())1052 def test_can_delete_community_post_comment_reply_with_closed_post_if_admin(self):1053 """1054 should be able to delete a community post comment reply for closed post if administrator1055 """1056 user = make_user()1057 community_creator = make_user()1058 community = make_community(creator=community_creator)1059 user.join_community_with_name(community_name=community.name)1060 community_creator.add_administrator_with_username_to_community_with_name(username=user.username,1061 community_name=community.name)1062 community_post_creator = make_user()1063 community_post_creator.join_community_with_name(community_name=community.name)1064 community_post_commentator = make_user()1065 community_post_commentator.join_community_with_name(community_name=community.name)1066 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)1067 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),1068 post_id=post.pk)1069 post_comment_reply = \1070 community_post_commentator.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1071 post_uuid=post.uuid,1072 text=make_fake_post_comment_text())1073 post.is_closed = True1074 post.save()1075 url = self._get_url(post_comment=post_comment_reply, post=post)1076 headers = make_authentication_headers_for_user(user)1077 response = self.client.delete(url, **headers)1078 self.assertEqual(response.status_code, status.HTTP_200_OK)1079 self.assertFalse(PostComment.objects.filter(id=post_comment_reply.pk).exists())1080 def test_can_delete_community_post_comment_reply_for_closed_post_if_moderator(self):1081 """1082 should be able to delete a community post comment reply for closed post if moderator1083 """1084 user = make_user()1085 community_creator = make_user()1086 community = make_community(creator=community_creator)1087 user.join_community_with_name(community_name=community.name)1088 community_creator.add_moderator_with_username_to_community_with_name(username=user.username,1089 community_name=community.name)1090 community_post_creator = make_user()1091 community_post_creator.join_community_with_name(community_name=community.name)1092 community_post_commentator = make_user()1093 community_post_commentator.join_community_with_name(community_name=community.name)1094 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)1095 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),1096 post_id=post.pk)1097 post_comment_reply = \1098 community_post_commentator.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1099 post_uuid=post.uuid,1100 text=make_fake_post_comment_text())1101 post.is_closed = True1102 post.save()1103 url = self._get_url(post_comment=post_comment_reply, post=post)1104 headers = make_authentication_headers_for_user(user)1105 response = self.client.delete(url, **headers)1106 self.assertEqual(response.status_code, status.HTTP_200_OK)1107 self.assertFalse(PostComment.objects.filter(id=post_comment_reply.pk).exists())1108 def test_cannot_delete_community_post_comment_reply_for_closed_post_if_comment_owner(self):1109 """1110 should NOT be able to delete a community post comment reply for closed post if comment owner1111 """1112 user = make_user()1113 admin = make_user()1114 community = make_community(creator=admin)1115 user.join_community_with_name(community_name=community.name)1116 community_post_creator = make_user()1117 community_post_creator.join_community_with_name(community_name=community.name)1118 commenter = make_user()1119 commenter.join_community_with_name(community_name=community.name)1120 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)1121 post_comment = commenter.comment_post_with_id(text=make_fake_post_comment_text(),1122 post_id=post.pk)1123 post_comment_reply = \1124 commenter.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1125 post_uuid=post.uuid,1126 text=make_fake_post_comment_text())1127 post.is_closed = True1128 post.save()1129 url = self._get_url(post_comment=post_comment_reply, post=post)1130 headers = make_authentication_headers_for_user(commenter)1131 response = self.client.delete(url, **headers)1132 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1133 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).exists())1134 def test_cannot_delete_own_community_post_comment_reply_for_closed_post_if_post_creator(self):1135 """1136 should NOT be able to delete own community post comment reply for closed post if post creator1137 """1138 user = make_user()1139 admin = make_user()1140 community = make_community(creator=admin)1141 user.join_community_with_name(community_name=community.name)1142 community_post_creator = make_user()1143 community_post_creator.join_community_with_name(community_name=community.name)1144 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)1145 post_comment = community_post_creator.comment_post_with_id(text=make_fake_post_comment_text(),1146 post_id=post.pk)1147 post_comment_reply = \1148 community_post_creator.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1149 post_uuid=post.uuid,1150 text=make_fake_post_comment_text())1151 post.is_closed = True1152 post.save()1153 url = self._get_url(post_comment=post_comment_reply, post=post)1154 headers = make_authentication_headers_for_user(community_post_creator)1155 response = self.client.delete(url, **headers)1156 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1157 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).exists())1158 def test_logs_community_post_comment_reply_deleted_by_non_creator(self):1159 """1160 should create a log when a community post comment reply was deleted by an admin/moderator1161 """1162 user = make_user()1163 community_creator = make_user()1164 community = make_community(creator=community_creator)1165 user.join_community_with_name(community_name=community.name)1166 community_creator.add_administrator_with_username_to_community_with_name(username=user.username,1167 community_name=community.name)1168 community_post_creator = make_user()1169 community_post_creator.join_community_with_name(community_name=community.name)1170 community_post_commentator = make_user()1171 community_post_commentator.join_community_with_name(community_name=community.name)1172 post = community_post_creator.create_community_post(text=make_fake_post_text(), community_name=community.name)1173 post_comment = community_post_commentator.comment_post_with_id(text=make_fake_post_comment_text(),1174 post_id=post.pk)1175 post_comment_reply = \1176 community_post_commentator.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1177 post_uuid=post.uuid,1178 text=make_fake_post_comment_text())1179 url = self._get_url(post_comment=post_comment_reply, post=post)1180 headers = make_authentication_headers_for_user(user)1181 self.client.delete(url, **headers)1182 self.assertTrue(1183 community.logs.filter(action_type='RPCR',1184 target_user=community_post_commentator,1185 source_user=user).exists())1186 def test_can_delete_own_comment_reply_in_foreign_public_post(self):1187 """1188 should be able to delete own comment reply in foreign public post and return 2001189 """1190 user = make_user()1191 foreign_user = make_user()1192 post = foreign_user.create_public_post(text=make_fake_post_text())1193 post_comment_text = make_fake_post_comment_text()1194 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)1195 post_comment_reply = user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1196 post_uuid=post.uuid,1197 text=make_fake_post_comment_text())1198 url = self._get_url(post_comment=post_comment_reply, post=post)1199 headers = make_authentication_headers_for_user(user)1200 response = self.client.delete(url, **headers)1201 self.assertEqual(response.status_code, status.HTTP_200_OK)1202 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 0)1203 def test_cannot_delete_foreign_comment_reply_in_foreign_public_post(self):1204 """1205 should NOT be able to delete foreign comment reply in foreign public post and return 4001206 """1207 user = make_user()1208 foreign_user = make_user()1209 post = foreign_user.create_public_post(text=make_fake_post_text())1210 post_comment_text = make_fake_post_comment_text()1211 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)1212 post_comment_reply = foreign_user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1213 post_uuid=post.uuid,1214 text=make_fake_post_comment_text())1215 url = self._get_url(post_comment=post_comment_reply, post=post)1216 headers = make_authentication_headers_for_user(user)1217 response = self.client.delete(url, **headers)1218 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1219 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 1)1220 def test_can_delete_own_comment_reply_in_connected_user_public_post(self):1221 """1222 should be able to delete own comment reply in a connected user public post and return 2001223 """1224 user = make_user()1225 user_to_connect = make_user()1226 user.connect_with_user_with_id(user_to_connect.pk)1227 user_to_connect.confirm_connection_with_user_with_id(user.pk)1228 post = user_to_connect.create_public_post(text=make_fake_post_text())1229 post_comment_text = make_fake_post_comment_text()1230 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)1231 post_comment_reply = user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1232 post_uuid=post.uuid,1233 text=make_fake_post_comment_text())1234 url = self._get_url(post_comment=post_comment_reply, post=post)1235 headers = make_authentication_headers_for_user(user)1236 response = self.client.delete(url, **headers)1237 self.assertEqual(response.status_code, status.HTTP_200_OK)1238 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 0)1239 def test_cannot_delete_foreign_comment_reply_in_connected_user_public_post(self):1240 """1241 should not be able to delete foreign comment reply in a connected user public post and return 4001242 """1243 user = make_user()1244 user_to_connect = make_user()1245 user.connect_with_user_with_id(user_to_connect.pk)1246 user_to_connect.confirm_connection_with_user_with_id(user.pk)1247 foreign_user = make_user()1248 post = user_to_connect.create_public_post(text=make_fake_post_text())1249 post_comment_text = make_fake_post_comment_text()1250 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)1251 post_comment_reply = foreign_user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1252 post_uuid=post.uuid,1253 text=make_fake_post_comment_text())1254 url = self._get_url(post_comment=post_comment_reply, post=post)1255 headers = make_authentication_headers_for_user(user)1256 response = self.client.delete(url, **headers)1257 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1258 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 1)1259 def test_can_delete_own_comment_reply_in_connected_user_encircled_post_part_of(self):1260 """1261 should be able to delete own comment reply in a connected user encircled post it's part of and return 2001262 """1263 user = make_user()1264 user_to_connect = make_user()1265 circle = make_circle(creator=user_to_connect)1266 user.connect_with_user_with_id(user_to_connect.pk)1267 user_to_connect.confirm_connection_with_user_with_id(user.pk, circles_ids=[circle.pk])1268 post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])1269 post_comment_text = make_fake_post_comment_text()1270 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)1271 post_comment_reply = user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1272 post_uuid=post.uuid,1273 text=make_fake_post_comment_text())1274 url = self._get_url(post_comment=post_comment_reply, post=post)1275 headers = make_authentication_headers_for_user(user)1276 response = self.client.delete(url, **headers)1277 self.assertEqual(response.status_code, status.HTTP_200_OK)1278 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 0)1279 def test_cannot_delete_foreign_comment_reply_in_connected_user_encircled_post_part_of(self):1280 """1281 should NOT be able to delete foreign comment reply in a connected user encircled post it's part of and return 4001282 """1283 user = make_user()1284 user_to_connect = make_user()1285 circle = make_circle(creator=user_to_connect)1286 user.connect_with_user_with_id(user_to_connect.pk)1287 user_to_connect.confirm_connection_with_user_with_id(user.pk, circles_ids=[circle.pk])1288 foreign_user = make_user()1289 foreign_user.connect_with_user_with_id(user_to_connect.pk)1290 user_to_connect.confirm_connection_with_user_with_id(foreign_user.pk, circles_ids=[circle.pk])1291 post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])1292 post_comment_text = make_fake_post_comment_text()1293 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)1294 post_comment_reply = foreign_user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1295 post_uuid=post.uuid,1296 text=make_fake_post_comment_text())1297 url = self._get_url(post_comment=post_comment_reply, post=post)1298 headers = make_authentication_headers_for_user(user)1299 response = self.client.delete(url, **headers)1300 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1301 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 1)1302 def test_cannot_delete_foreign_comment_reply_in_connected_user_encircled_post_not_part_of(self):1303 """1304 should NOT be able to delete foreign comment reply in a connected user encircled post NOT part of and return 4001305 """1306 user = make_user()1307 user_to_connect = make_user()1308 circle = make_circle(creator=user_to_connect)1309 foreign_user = make_user()1310 foreign_user.connect_with_user_with_id(user_to_connect.pk)1311 user_to_connect.confirm_connection_with_user_with_id(foreign_user.pk, circles_ids=[circle.pk])1312 post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])1313 post_comment_text = make_fake_post_comment_text()1314 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)1315 post_comment_reply = foreign_user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1316 post_uuid=post.uuid,1317 text=make_fake_post_comment_text())1318 url = self._get_url(post_comment=post_comment_reply, post=post)1319 headers = make_authentication_headers_for_user(user)1320 response = self.client.delete(url, **headers)1321 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1322 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 1)1323 def test_can_delete_own_comment_reply_in_followed_user_public_post(self):1324 """1325 should be able to delete own comment reply in a followed user public post and return 2001326 """1327 user = make_user()1328 user_to_follow = make_user()1329 user.follow_user_with_id(user_to_follow.pk)1330 post = user_to_follow.create_public_post(text=make_fake_post_text())1331 post_comment_text = make_fake_post_comment_text()1332 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)1333 post_comment_reply = user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1334 post_uuid=post.uuid,1335 text=make_fake_post_comment_text())1336 url = self._get_url(post_comment=post_comment_reply, post=post)1337 headers = make_authentication_headers_for_user(user)1338 response = self.client.delete(url, **headers)1339 self.assertEqual(response.status_code, status.HTTP_200_OK)1340 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 0)1341 def test_cannot_delete_foreign_comment_reply_in_followed_user_public_post(self):1342 """1343 should not be able to delete foreign comment reply in a followed user public post and return 4001344 """1345 user = make_user()1346 user_to_follow = make_user()1347 user.follow_user_with_id(user_to_follow.pk)1348 foreign_user = make_user()1349 post = user_to_follow.create_public_post(text=make_fake_post_text())1350 post_comment_text = make_fake_post_comment_text()1351 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)1352 post_comment_reply = foreign_user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1353 post_uuid=post.uuid,1354 text=make_fake_post_comment_text())1355 url = self._get_url(post_comment=post_comment_reply, post=post)1356 headers = make_authentication_headers_for_user(user)1357 response = self.client.delete(url, **headers)1358 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1359 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 1)1360 def test_cannot_delete_foreign_comment_reply_in_folowed_user_encircled_post(self):1361 """1362 should not be able to delete foreign comment reply in a followed user encircled post and return 4001363 """1364 user = make_user()1365 user_to_follow = make_user()1366 circle = make_circle(creator=user_to_follow)1367 user.follow_user_with_id(user_to_follow.pk)1368 foreign_user = make_user()1369 foreign_user.connect_with_user_with_id(user_to_follow.pk)1370 user_to_follow.confirm_connection_with_user_with_id(foreign_user.pk, circles_ids=[circle.pk])1371 post = user_to_follow.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])1372 post_comment_text = make_fake_post_comment_text()1373 post_comment = foreign_user.comment_post_with_id(post.pk, text=post_comment_text)1374 post_comment_reply = foreign_user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1375 post_uuid=post.uuid,1376 text=make_fake_post_comment_text())1377 url = self._get_url(post_comment=post_comment_reply, post=post)1378 headers = make_authentication_headers_for_user(user)1379 response = self.client.delete(url, **headers)1380 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1381 self.assertTrue(PostComment.objects.filter(id=post_comment_reply.pk).count() == 1)1382 def test_post_comment_reply_notification_is_deleted_when_deleting_comment(self):1383 """1384 should delete the post comment reply notification when a post comment is deleted1385 """1386 user = make_user()1387 commenter = make_user()1388 post = user.create_public_post(text=make_fake_post_text())1389 post_comment_text = make_fake_post_comment_text()1390 post_comment = user.comment_post_with_id(post.pk, text=post_comment_text)1391 post_comment_reply = commenter.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1392 post_uuid=post.uuid,1393 text=make_fake_post_comment_text())1394 post_comment_reply_notification = PostCommentReplyNotification.objects.get(post_comment=post_comment_reply,1395 notification__owner=user)1396 notification = Notification.objects.get(notification_type=Notification.POST_COMMENT_REPLY,1397 object_id=post_comment_reply_notification.pk)1398 url = self._get_url(post_comment=post_comment_reply, post=post)1399 headers = make_authentication_headers_for_user(commenter)1400 self.client.delete(url, **headers)1401 self.assertFalse(PostCommentReplyNotification.objects.filter(pk=post_comment_reply_notification.pk).exists())1402 self.assertFalse(Notification.objects.filter(pk=notification.pk).exists())1403 def test_can_edit_own_post_comment_reply_on_own_post(self):1404 """1405 should be able to edit own post comment reply1406 """1407 user = make_user()1408 post = user.create_public_post(text=make_fake_post_text())1409 post_comment = user.comment_post_with_id(post.pk, text=make_fake_post_comment_text())1410 post_comment_reply = user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1411 post_uuid=post.uuid,1412 text=make_fake_post_comment_text())1413 url = self._get_url(post_comment=post_comment_reply, post=post)1414 edited_comment_reply_text = make_fake_post_comment_text()1415 headers = make_authentication_headers_for_user(user)1416 response = self.client.patch(url, {1417 'text': edited_comment_reply_text1418 }, **headers)1419 self.assertEqual(response.status_code, status.HTTP_200_OK)1420 post_comment_reply.refresh_from_db()1421 self.assertTrue(post_comment_reply.text == edited_comment_reply_text)1422 self.assertTrue(post_comment_reply.is_edited)1423 def test_can_edit_own_post_comment_reply_on_others_post_comment(self):1424 """1425 should be able to edit own post comment reply on someone else's post comment1426 """1427 user = make_user()1428 post_creator = make_user()1429 post = post_creator.create_public_post(text=make_fake_post_text())1430 post_comment = post_creator.comment_post_with_id(post.pk, text=make_fake_post_comment_text())1431 post_comment_reply = user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1432 post_uuid=post.uuid,1433 text=make_fake_post_comment_text())1434 url = self._get_url(post_comment=post_comment_reply, post=post)1435 edited_post_comment_reply_text = make_fake_post_comment_text()1436 headers = make_authentication_headers_for_user(user)1437 response = self.client.patch(url, {1438 'text': edited_post_comment_reply_text1439 }, **headers)1440 self.assertEqual(response.status_code, status.HTTP_200_OK)1441 post_comment_reply.refresh_from_db()1442 self.assertTrue(post_comment_reply.text == edited_post_comment_reply_text)1443 def test_cannot_edit_others_post_comment_reply(self):1444 """1445 should not be able to edit someone else's comment reply1446 """1447 user = make_user()1448 commenter = make_user()1449 post = user.create_public_post(text=make_fake_post_text())1450 original_post_comment_reply_text = make_fake_post_comment_text()1451 post_comment = commenter.comment_post_with_id(post.pk, text=make_fake_post_comment_text())1452 post_comment_reply = commenter.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1453 post_uuid=post.uuid,1454 text=original_post_comment_reply_text)1455 url = self._get_url(post_comment=post_comment_reply, post=post)1456 edited_post_comment_reply_text = make_fake_post_comment_text()1457 headers = make_authentication_headers_for_user(user)1458 response = self.client.patch(url, {1459 'text': edited_post_comment_reply_text1460 }, **headers)1461 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1462 post_comment_reply.refresh_from_db()1463 self.assertTrue(post_comment_reply.text == original_post_comment_reply_text)1464 self.assertFalse(post_comment_reply.is_edited)1465 def test_cannot_edit_post_comment_reply_if_comments_disabled(self):1466 """1467 should not be able to edit own comment reply if comments are disabled1468 """1469 admin = make_user()1470 user = make_user()1471 community = make_community(admin)1472 user.join_community_with_name(community_name=community.name)1473 post = user.create_community_post(community.name, text=make_fake_post_text())1474 original_post_comment_reply_text = make_fake_post_comment_text()1475 post_comment = user.comment_post_with_id(post.pk, text=make_fake_post_comment_text())1476 post_comment_reply = user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1477 post_uuid=post.uuid,1478 text=original_post_comment_reply_text)1479 post.comments_enabled = False1480 post.save()1481 url = self._get_url(post_comment=post_comment_reply, post=post)1482 edited_post_comment_reply_text = make_fake_post_comment_text()1483 headers = make_authentication_headers_for_user(user)1484 response = self.client.patch(url, {1485 'text': edited_post_comment_reply_text1486 }, **headers)1487 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1488 post_comment_reply.refresh_from_db()1489 self.assertTrue(post_comment_reply.text == original_post_comment_reply_text)1490 self.assertFalse(post_comment_reply.is_edited)1491 def test_cannot_edit_post_comment_reply_if_post_closed_and_not_not_post_creator(self):1492 """1493 should NOT be able to edit own comment reply if post is closed and not post creator1494 """1495 admin = make_user()1496 user = make_user()1497 community = make_community(admin)1498 user.join_community_with_name(community_name=community.name)1499 post = admin.create_community_post(community.name, text=make_fake_post_text())1500 original_post_comment_reply_text = make_fake_post_comment_text()1501 post_comment = user.comment_post_with_id(post.pk, text=make_fake_post_comment_text())1502 post_comment_reply = user.reply_to_comment_with_id_for_post_with_uuid(post_comment_id=post_comment.pk,1503 post_uuid=post.uuid,1504 text=original_post_comment_reply_text)1505 post.is_closed = True1506 post.save()1507 url = self._get_url(post_comment=post_comment_reply, post=post)1508 edited_post_comment_reply_text = make_fake_post_comment_text()1509 headers = make_authentication_headers_for_user(user)1510 response = self.client.patch(url, {1511 'text': edited_post_comment_reply_text1512 }, **headers)1513 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1514 post_comment_reply.refresh_from_db()1515 self.assertTrue(post_comment_reply.text == original_post_comment_reply_text)1516 self.assertFalse(post_comment_reply.is_edited)1517 def _get_url(self, post, post_comment):1518 return reverse('post-comment', kwargs={1519 'post_uuid': post.uuid,1520 'post_comment_id': post_comment.pk1521 })1522class MutePostCommentAPITests(OpenbookAPITestCase):1523 """1524 MutePostCommentAPI1525 """1526 fixtures = [1527 'openbook_circles/fixtures/circles.json'1528 ]1529 def test_can_mute_own_post_comment(self):1530 """1531 should be able to mute own post comment and return 2001532 """1533 user = make_user()1534 headers = make_authentication_headers_for_user(user)1535 post = user.create_public_post(text=make_fake_post_text())1536 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())1537 url = self._get_url(post=post, post_comment=post_comment)1538 response = self.client.post(url, **headers)1539 self.assertEqual(response.status_code, status.HTTP_200_OK)1540 self.assertTrue(user.has_muted_post_comment_with_id(post_comment.pk))1541 def test_cant_mute_own_post_comment_if_already_muted(self):1542 """1543 should not be able to mute own post comment if already muted and return 4001544 """1545 user = make_user()1546 headers = make_authentication_headers_for_user(user)1547 post = user.create_public_post(text=make_fake_post_text())1548 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())1549 url = self._get_url(post=post, post_comment=post_comment)1550 user.mute_post_comment_with_id(post_comment.pk)1551 response = self.client.post(url, **headers)1552 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1553 self.assertTrue(user.has_muted_post_comment_with_id(post_comment.pk))1554 def test_can_mute_foreign_post_comment_if_public_post_comment(self):1555 user = make_user()1556 foreign_user = make_user()1557 headers = make_authentication_headers_for_user(user)1558 post = foreign_user.create_public_post(text=make_fake_post_text())1559 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())1560 url = self._get_url(post=post, post_comment=post_comment)1561 response = self.client.post(url, **headers)1562 self.assertEqual(response.status_code, status.HTTP_200_OK)1563 self.assertTrue(user.has_muted_post_comment_with_id(post_comment.pk))1564 def test_cannot_mute_foreign_post_comment_if_encircled_post(self):1565 user = make_user()1566 foreign_user = make_user()1567 headers = make_authentication_headers_for_user(user)1568 circle = make_circle(creator=foreign_user)1569 post = foreign_user.create_encircled_post(text=make_fake_post_text(),1570 circles_ids=[circle.pk])1571 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())1572 url = self._get_url(post=post, post_comment=post_comment)1573 response = self.client.post(url, **headers)1574 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1575 self.assertFalse(user.has_muted_post_comment_with_id(post_comment.pk))1576 def test_can_mute_foreign_post_comment_if_part_of_encircled_post_comment(self):1577 user = make_user()1578 foreign_user = make_user()1579 headers = make_authentication_headers_for_user(user)1580 circle = make_circle(creator=foreign_user)1581 post = foreign_user.create_encircled_post(text=make_fake_post_text(),1582 circles_ids=[circle.pk])1583 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())1584 foreign_user.connect_with_user_with_id(user_id=user.pk, circles_ids=[circle.pk])1585 user.confirm_connection_with_user_with_id(user_id=foreign_user.pk)1586 url = self._get_url(post=post, post_comment=post_comment)1587 response = self.client.post(url, **headers)1588 self.assertEqual(response.status_code, status.HTTP_200_OK)1589 self.assertTrue(user.has_muted_post_comment_with_id(post_comment.pk))1590 def test_can_mute_community_post_comment_if_public(self):1591 user = make_user()1592 foreign_user = make_user()1593 community = make_community(creator=foreign_user)1594 headers = make_authentication_headers_for_user(user)1595 post = foreign_user.create_community_post(text=make_fake_post_text(),1596 community_name=community.name)1597 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())1598 url = self._get_url(post=post, post_comment=post_comment)1599 response = self.client.post(url, **headers)1600 self.assertEqual(response.status_code, status.HTTP_200_OK)1601 self.assertTrue(user.has_muted_post_comment_with_id(post_comment.pk))1602 def test_can_mute_closed_community_post_comment(self):1603 """1604 should be able to mute closed post comment if not admin/mod or post comment creator in community1605 """1606 user = make_user()1607 foreign_user = make_user()1608 community = make_community(creator=foreign_user)1609 user.join_community_with_name(community_name=community.name)1610 headers = make_authentication_headers_for_user(user)1611 post = foreign_user.create_community_post(text=make_fake_post_text(),1612 community_name=community.name)1613 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())1614 post_comment.is_closed = True1615 post_comment.save()1616 url = self._get_url(post=post, post_comment=post_comment)1617 response = self.client.post(url, **headers)1618 self.assertEqual(status.HTTP_200_OK, response.status_code)1619 self.assertTrue(user.has_muted_post_comment_with_id(post_comment.pk))1620 def test_can_mute_closed_community_post_comment_if_creator(self):1621 """1622 should be able to mute closed post comment if post_comment creator in community1623 """1624 user = make_user()1625 foreign_user = make_user()1626 community = make_community(creator=foreign_user)1627 user.join_community_with_name(community_name=community.name)1628 headers = make_authentication_headers_for_user(user)1629 post = user.create_community_post(text=make_fake_post_text(),1630 community_name=community.name)1631 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())1632 post_comment.is_closed = True1633 post_comment.save()1634 url = self._get_url(post=post, post_comment=post_comment)1635 response = self.client.post(url, **headers)1636 self.assertEqual(response.status_code, status.HTTP_200_OK)1637 self.assertTrue(user.has_muted_post_comment_with_id(post_comment.pk))1638 def test_can_mute_closed_community_post_comment_administrator(self):1639 """1640 should be able to mute closed post comment if administrator in community1641 """1642 user = make_user()1643 admin = make_user()1644 community = make_community(creator=admin)1645 user.join_community_with_name(community_name=community.name)1646 headers = make_authentication_headers_for_user(admin)1647 post = user.create_community_post(text=make_fake_post_text(),1648 community_name=community.name)1649 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())1650 post_comment.is_closed = True1651 post_comment.save()1652 url = self._get_url(post=post, post_comment=post_comment)1653 response = self.client.post(url, **headers)1654 self.assertEqual(response.status_code, status.HTTP_200_OK)1655 self.assertTrue(admin.has_muted_post_comment_with_id(post_comment.pk))1656 def test_can_mute_closed_community_post_comment_if_moderator(self):1657 """1658 should be able to mute closed post comment if moderator in community1659 """1660 user = make_user()1661 admin = make_user()1662 moderator = make_user()1663 community = make_community(creator=admin)1664 user.join_community_with_name(community_name=community.name)1665 moderator.join_community_with_name(community_name=community.name)1666 admin.add_moderator_with_username_to_community_with_name(username=moderator.username,1667 community_name=community.name)1668 headers = make_authentication_headers_for_user(moderator)1669 post = user.create_community_post(text=make_fake_post_text(),1670 community_name=community.name)1671 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())1672 post_comment.is_closed = True1673 post_comment.save()1674 url = self._get_url(post=post, post_comment=post_comment)1675 response = self.client.post(url, **headers)1676 self.assertEqual(response.status_code, status.HTTP_200_OK)1677 self.assertTrue(moderator.has_muted_post_comment_with_id(post_comment.pk))1678 def test_cant_mute_community_post_comment_if_private_and_not_member(self):1679 user = make_user()1680 foreign_user = make_user()1681 community = make_community(creator=foreign_user, type='T')1682 headers = make_authentication_headers_for_user(user)1683 post = foreign_user.create_community_post(text=make_fake_post_text(),1684 community_name=community.name)1685 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())1686 url = self._get_url(post=post, post_comment=post_comment)1687 response = self.client.post(url, **headers)1688 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1689 self.assertFalse(user.has_muted_post_comment_with_id(post_comment.pk))1690 def test_can_mute_community_post_comment_if_private_and_member(self):1691 user = make_user()1692 foreign_user = make_user()1693 community = make_community(creator=foreign_user, type='T')1694 headers = make_authentication_headers_for_user(user)1695 post = foreign_user.create_community_post(text=make_fake_post_text(),1696 community_name=community.name)1697 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())1698 foreign_user.invite_user_with_username_to_community_with_name(username=user.username,1699 community_name=community.name)1700 user.join_community_with_name(community_name=community.name)1701 url = self._get_url(post=post, post_comment=post_comment)1702 response = self.client.post(url, **headers)1703 self.assertEqual(response.status_code, status.HTTP_200_OK)1704 self.assertTrue(user.has_muted_post_comment_with_id(post_comment.pk))1705 def _get_url(self, post, post_comment):1706 return reverse('mute-post-comment', kwargs={1707 'post_uuid': post.uuid,1708 'post_comment_id': post_comment.id,1709 })1710class UnmutePostCommentAPITests(OpenbookAPITestCase):1711 """1712 UnmutePostCommentAPI1713 """1714 fixtures = [1715 'openbook_circles/fixtures/circles.json'1716 ]1717 def test_can_unmute_own_post_comment(self):1718 """1719 should be able to unmute own post comment and return 2001720 """1721 user = make_user()1722 headers = make_authentication_headers_for_user(user)1723 post = user.create_public_post(text=make_fake_post_text())1724 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())1725 user.mute_post_comment_with_id(post_comment.pk)1726 url = self._get_url(post=post, post_comment=post_comment)1727 response = self.client.post(url, **headers)1728 self.assertEqual(response.status_code, status.HTTP_200_OK)1729 self.assertFalse(user.has_muted_post_comment_with_id(post_comment.pk))1730 def test_cant_unmute_own_post_comment_if_already_unmuted(self):1731 """1732 should not be able to unmute own post comment if already unmuted and return 4001733 """1734 user = make_user()1735 headers = make_authentication_headers_for_user(user)1736 post = user.create_public_post(text=make_fake_post_text())1737 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())1738 url = self._get_url(post=post, post_comment=post_comment)1739 response = self.client.post(url, **headers)1740 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1741 self.assertFalse(user.has_muted_post_comment_with_id(post_comment.pk))1742 def test_can_unmute_closed_community_post_comment(self):1743 """1744 should be able to unmute closed post comment if not admin/mod or post comment creator in community1745 """1746 user = make_user()1747 foreign_user = make_user()1748 community = make_community(creator=foreign_user)1749 user.join_community_with_name(community_name=community.name)1750 headers = make_authentication_headers_for_user(user)1751 post = foreign_user.create_community_post(text=make_fake_post_text(),1752 community_name=community.name)1753 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())1754 user.mute_post_comment_with_id(post_comment.pk)1755 post_comment.is_closed = True1756 post_comment.save()...

Full Screen

Full Screen

test_post_comment_reactions.py

Source:test_post_comment_reactions.py Github

copy

Full Screen

...22 """23 fixtures = [24 'openbook_circles/fixtures/circles.json'25 ]26 def test_can_react_to_own_post_comment(self):27 """28 should be able to react in own post comment and return 20129 """30 user = make_user()31 headers = make_authentication_headers_for_user(user)32 post = user.create_public_post(text=make_fake_post_text())33 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())34 emoji_group = make_reactions_emoji_group()35 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk36 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)37 url = self._get_url(post=post, post_comment=post_comment)38 response = self.client.put(url, data, **headers)39 self.assertEqual(status.HTTP_201_CREATED, response.status_code)40 self.assertTrue(41 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,42 reactor_id=user.pk).count() == 1)43 def test_can_react_to_post_comment_reply(self):44 """45 should be able to react to post comment reply and return 20146 """47 user = make_user()48 headers = make_authentication_headers_for_user(user)49 post = user.create_public_post(text=make_fake_post_text())50 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())51 post_comment_reply = user.reply_to_comment_for_post(post=post, post_comment=post_comment,52 text=make_fake_post_comment_text())53 emoji_group = make_reactions_emoji_group()54 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk55 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)56 url = self._get_url(post=post, post_comment=post_comment_reply)57 response = self.client.put(url, data, **headers)58 self.assertEqual(status.HTTP_201_CREATED, response.status_code)59 self.assertTrue(60 PostCommentReaction.objects.filter(post_comment_id=post_comment_reply.pk,61 emoji_id=post_comment_reaction_emoji_id,62 reactor_id=user.pk).count() == 1)63 def test_cannot_react_to_foreign_encircled_post_comment(self):64 """65 should not be able to react in a foreign encircled post comment and return 40066 """67 user = make_user()68 headers = make_authentication_headers_for_user(user)69 foreign_user = make_user()70 circle = make_circle(creator=foreign_user)71 post = foreign_user.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])72 post_comment = foreign_user.comment_post(post=post, text=make_fake_post_comment_text())73 emoji_group = make_reactions_emoji_group()74 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk75 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)76 url = self._get_url(post=post, post_comment=post_comment)77 response = self.client.put(url, data, **headers)78 self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)79 self.assertTrue(80 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,81 reactor_id=user.pk).count() == 0)82 def test_cannot_react_to_foreign_post_comment_with_non_reaction_emoji(self):83 """84 should not be able to react in a post comment with a non reaction emoji group and return 40085 """86 user = make_user()87 headers = make_authentication_headers_for_user(user)88 post = user.create_public_post(text=make_fake_post_text())89 post_comment = user.comment_post(post=post, text=make_fake_post_comment_text())90 emoji_group = make_emoji_group()91 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk92 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)93 url = self._get_url(post=post, post_comment=post_comment)94 response = self.client.put(url, data, **headers)95 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)96 self.assertTrue(97 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,98 reactor_id=user.pk).count() == 0)99 def test_can_react_to_connected_user_public_post_comment(self):100 """101 should be able to react in the public post comment of a connected user post and return 201102 """103 user = make_user()104 headers = make_authentication_headers_for_user(user)105 user_to_connect = make_user()106 user.connect_with_user_with_id(user_to_connect.pk)107 connected_user_post = user_to_connect.create_public_post(text=make_fake_post_text())108 connected_user_post_comment = user_to_connect.comment_post(post=connected_user_post,109 text=make_fake_post_comment_text())110 emoji_group = make_reactions_emoji_group()111 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk112 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)113 url = self._get_url(post=connected_user_post, post_comment=connected_user_post_comment)114 response = self.client.put(url, data, **headers)115 self.assertEqual(response.status_code, status.HTTP_201_CREATED)116 self.assertTrue(117 PostCommentReaction.objects.filter(post_comment_id=connected_user_post_comment.pk,118 emoji_id=post_comment_reaction_emoji_id,119 reactor_id=user.pk).count() == 1)120 def test_can_react_to_connected_user_encircled_post_comment_part_of(self):121 """122 should be able to react in the encircled post comment of a connected user which the user is part of and return 201123 """124 user = make_user()125 headers = make_authentication_headers_for_user(user)126 user_to_connect = make_user()127 circle = make_circle(creator=user_to_connect)128 user.connect_with_user_with_id(user_to_connect.pk)129 user_to_connect.confirm_connection_with_user_with_id(user.pk, circles_ids=[circle.pk])130 connected_user_post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])131 connected_user_post_comment = user_to_connect.comment_post(post=connected_user_post,132 text=make_fake_post_comment_text())133 emoji_group = make_reactions_emoji_group()134 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk135 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)136 url = self._get_url(post=connected_user_post, post_comment=connected_user_post_comment)137 response = self.client.put(url, data, **headers)138 self.assertEqual(response.status_code, status.HTTP_201_CREATED)139 self.assertTrue(140 PostCommentReaction.objects.filter(post_comment_id=connected_user_post.pk,141 emoji_id=post_comment_reaction_emoji_id,142 reactor_id=user.pk).count() == 1)143 def test_cannot_react_to_connected_user_encircled_post_comment_not_part_of(self):144 """145 should NOT be able to react in the encircled post comment of a connected user which the user is NOT part of and return 400146 """147 user = make_user()148 headers = make_authentication_headers_for_user(user)149 user_to_connect = make_user()150 circle = make_circle(creator=user_to_connect)151 user.connect_with_user_with_id(user_to_connect.pk)152 # Note there is no confirmation of the connection on the other side153 connected_user_post = user_to_connect.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])154 connected_user_post_comment = user_to_connect.comment_post(post=connected_user_post,155 text=make_fake_post_comment_text())156 emoji_group = make_reactions_emoji_group()157 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk158 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)159 url = self._get_url(post=connected_user_post, post_comment=connected_user_post_comment)160 response = self.client.put(url, data, **headers)161 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)162 self.assertTrue(163 PostCommentReaction.objects.filter(post_comment_id=connected_user_post.pk,164 emoji_id=post_comment_reaction_emoji_id,165 reactor_id=user.pk).count() == 0)166 def test_can_react_to_user_public_post_comment(self):167 """168 should be able to react in the public post comment of any user and return 201169 """170 user = make_user()171 headers = make_authentication_headers_for_user(user)172 foreign_user = make_user()173 foreign_user_post = foreign_user.create_public_post(text=make_fake_post_text())174 foreign_user_post_comment = foreign_user.comment_post(post=foreign_user_post,175 text=make_fake_post_comment_text())176 emoji_group = make_reactions_emoji_group()177 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk178 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)179 url = self._get_url(post=foreign_user_post, post_comment=foreign_user_post_comment)180 response = self.client.put(url, data, **headers)181 self.assertEqual(response.status_code, status.HTTP_201_CREATED)182 self.assertTrue(183 PostCommentReaction.objects.filter(post_comment_id=foreign_user_post.pk,184 emoji_id=post_comment_reaction_emoji_id,185 reactor_id=user.pk).count() == 1)186 def test_cannot_react_to_followed_user_encircled_post_comment(self):187 """188 should be able to react in the encircled post comment of a followed user return 400189 """190 user = make_user()191 headers = make_authentication_headers_for_user(user)192 user_to_follow = make_user()193 circle = make_circle(creator=user_to_follow)194 user.follow_user_with_id(user_to_follow.pk)195 followed_user_post = user_to_follow.create_encircled_post(text=make_fake_post_text(), circles_ids=[circle.pk])196 followed_user_post_comment = user_to_follow.comment_post(post=followed_user_post,197 text=make_fake_post_comment_text())198 emoji_group = make_reactions_emoji_group()199 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk200 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)201 url = self._get_url(post=followed_user_post, post_comment=followed_user_post_comment)202 response = self.client.put(url, data, **headers)203 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)204 self.assertTrue(205 PostCommentReaction.objects.filter(post_comment_id=followed_user_post.pk,206 emoji_id=post_comment_reaction_emoji_id,207 reactor_id=user.pk).count() == 0)208 def test_cannot_react_in_post_comment_from_community_banned_from(self):209 """210 should not be able to react in the post comment of a community banned from and return 400211 """212 user = make_user()213 headers = make_authentication_headers_for_user(user)214 community_owner = make_user()215 community = make_community(creator=community_owner)216 user.join_community_with_name(community_name=community.name)217 post = community_owner.create_community_post(community_name=community.name, text=make_fake_post_text())218 post_comment = community_owner.comment_post(post=post,219 text=make_fake_post_comment_text())220 community_owner.ban_user_with_username_from_community_with_name(username=user.username,221 community_name=community.name)222 emoji_group = make_reactions_emoji_group()223 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk224 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)225 url = self._get_url(post=post, post_comment=post_comment)226 response = self.client.put(url, data, **headers)227 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)228 self.assertTrue(229 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,230 reactor_id=user.pk).count() == 0)231 def test_cannot_react_to_closed_community_post_comment_if_not_creator(self):232 """233 should NOT be able to react in a closed community post comment if not creator234 """235 user = make_user()236 admin = make_user()237 community = make_community(admin)238 headers = make_authentication_headers_for_user(user)239 post_creator = make_user()240 post_creator.join_community_with_name(community_name=community.name)241 user.join_community_with_name(community_name=community.name)242 community_post = post_creator.create_community_post(community_name=community.name,243 text=make_fake_post_comment_text())244 community_post_comment = post_creator.comment_post(post=community_post,245 text=make_fake_post_comment_text())246 community_post.is_closed = True247 community_post.save()248 emoji_group = make_reactions_emoji_group()249 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk250 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)251 url = self._get_url(post=community_post, post_comment=community_post_comment)252 response = self.client.put(url, data, **headers)253 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)254 self.assertTrue(255 PostCommentReaction.objects.filter(post_comment_id=community_post_comment.pk,256 emoji_id=post_comment_reaction_emoji_id,257 reactor_id=user.pk).count() == 0)258 def test_cannot_react_to_closed_community_post_comment_if_creator(self):259 """260 should NOT be able to react in a closed community post comment if creator261 """262 user = make_user()263 admin = make_user()264 community = make_community(admin)265 post_creator = make_user()266 post_creator.join_community_with_name(community_name=community.name)267 user.join_community_with_name(community_name=community.name)268 community_post = post_creator.create_community_post(community_name=community.name,269 text=make_fake_post_comment_text())270 community_post_comment = post_creator.comment_post(post=community_post,271 text=make_fake_post_comment_text())272 community_post.is_closed = True273 community_post.save()274 emoji_group = make_reactions_emoji_group()275 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk276 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)277 headers = make_authentication_headers_for_user(post_creator)278 url = self._get_url(post=community_post, post_comment=community_post_comment)279 response = self.client.put(url, data, **headers)280 self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)281 self.assertTrue(282 PostCommentReaction.objects.filter(post_comment_id=community_post_comment.pk,283 emoji_id=post_comment_reaction_emoji_id,284 reactor_id=post_creator.pk).count() == 0)285 def test_cannot_react_to_blocked_user_post_comment(self):286 """287 should not be able to react to a blocked user post comment and return 400288 """289 user = make_user()290 headers = make_authentication_headers_for_user(user)291 user_to_block = make_user()292 user.follow_user_with_id(user_to_block.pk)293 post = user_to_block.create_public_post(text=make_fake_post_text())294 post_comment = user_to_block.comment_post(post=post,295 text=make_fake_post_comment_text())296 user.block_user_with_id(user_id=user_to_block.pk)297 emoji_group = make_reactions_emoji_group()298 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk299 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)300 url = self._get_url(post=post, post_comment=post_comment)301 response = self.client.put(url, data, **headers)302 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)303 self.assertTrue(304 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,305 reactor_id=user.pk).count() == 0)306 def test_cannot_react_to_blocking_user_post_comment(self):307 """308 should not be able to react to a blocking user post comment and return 400309 """310 user = make_user()311 headers = make_authentication_headers_for_user(user)312 blocking_user = make_user()313 user.follow_user_with_id(blocking_user.pk)314 post = blocking_user.create_public_post(text=make_fake_post_text())315 post_comment = blocking_user.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text())316 blocking_user.block_user_with_id(user_id=user.pk)317 emoji_group = make_reactions_emoji_group()318 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk319 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)320 url = self._get_url(post=post, post_comment=post_comment)321 response = self.client.put(url, data, **headers)322 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)323 self.assertTrue(324 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,325 reactor_id=user.pk).count() == 0)326 def test_cannot_react_to_blocked_user_community_post_comment(self):327 """328 should not be able to react to a blocked user community post comment and return 400329 """330 user = make_user()331 headers = make_authentication_headers_for_user(user)332 community_owner = make_user()333 community = make_community(creator=community_owner)334 user_to_block = make_user()335 user_to_block.join_community_with_name(community_name=community.name)336 post = user_to_block.create_community_post(community_name=community.name, text=make_fake_post_text())337 post_comment = user_to_block.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text())338 user.block_user_with_id(user_id=user_to_block.pk)339 emoji_group = make_reactions_emoji_group()340 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk341 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)342 url = self._get_url(post=post, post_comment=post_comment)343 response = self.client.put(url, data, **headers)344 self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)345 self.assertTrue(346 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,347 reactor_id=user.pk).count() == 0)348 def test_cannot_react_to_blocking_user_community_post_comment(self):349 """350 should not be able to react to a blocking user community post comment and return 400351 """352 user = make_user()353 headers = make_authentication_headers_for_user(user)354 community_owner = make_user()355 community = make_community(creator=community_owner)356 blocking_user = make_user()357 blocking_user.join_community_with_name(community_name=community.name)358 post = blocking_user.create_community_post(community_name=community.name, text=make_fake_post_text())359 post_comment = blocking_user.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text())360 blocking_user.block_user_with_id(user_id=user.pk)361 emoji_group = make_reactions_emoji_group()362 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk363 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)364 url = self._get_url(post=post, post_comment=post_comment)365 response = self.client.put(url, data, **headers)366 self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)367 self.assertTrue(368 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,369 reactor_id=user.pk).count() == 0)370 def test_can_react_to_blocked_community_staff_member_post_comment(self):371 """372 should be able to react to a blocked community staff member post comment and return 201373 """374 user = make_user()375 headers = make_authentication_headers_for_user(user)376 community_owner = make_user()377 community = make_community(creator=community_owner)378 post = community_owner.create_community_post(community_name=community.name, text=make_fake_post_text())379 post_comment = community_owner.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text())380 user.block_user_with_id(user_id=community_owner.pk)381 emoji_group = make_reactions_emoji_group()382 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk383 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)384 url = self._get_url(post=post, post_comment=post_comment)385 response = self.client.put(url, data, **headers)386 self.assertEqual(response.status_code, status.HTTP_201_CREATED)387 self.assertTrue(388 PostCommentReaction.objects.filter(post_comment_id=post_comment.pk, emoji_id=post_comment_reaction_emoji_id,389 reactor_id=user.pk).count() == 1)390 def test_can_react_to_blocking_community_staff_member_post_comment(self):391 """392 should be able to react to a blocking community staff member post comment and return 201393 """394 user = make_user()395 headers = make_authentication_headers_for_user(user)396 community_owner = make_user()397 community = make_community(creator=community_owner)398 post = community_owner.create_community_post(community_name=community.name, text=make_fake_post_text())399 post_comment = user.comment_post_with_id(post_id=post.pk, text=make_fake_post_comment_text())400 community_owner.block_user_with_id(user_id=user.pk)401 emoji_group = make_reactions_emoji_group()402 post_comment_reaction_emoji_id = make_emoji(group=emoji_group).pk403 data = self._get_create_post_comment_reaction_request_data(post_comment_reaction_emoji_id)404 url = self._get_url(post=post, post_comment=post_comment)...

Full Screen

Full Screen

post_comment.py

Source:post_comment.py Github

copy

Full Screen

...32 request_user = request.user33 if request_user.is_anonymous:34 replies_count = post_comment.count_replies()35 else:36 replies_count = request_user.get_replies_count_for_post_comment(post_comment=post_comment)37 return replies_count38class PostCommentReactionsEmojiCountField(Field):39 def __init__(self, emoji_count_serializer=None, **kwargs):40 kwargs['source'] = '*'41 kwargs['read_only'] = True42 self.emoji_count_serializer = emoji_count_serializer43 super(PostCommentReactionsEmojiCountField, self).__init__(**kwargs)44 def to_representation(self, post_comment):45 request = self.context.get('request')46 request_user = request.user47 if request_user.is_anonymous:48 PostComment = get_post_comment_model()49 reaction_emoji_count = PostComment.get_emoji_counts_for_post_comment_with_id(post_comment.pk)50 else:51 reaction_emoji_count = request_user.get_emoji_counts_for_post_comment(post_comment=post_comment)52 post_comment_reactions_serializer = self.emoji_count_serializer(reaction_emoji_count, many=True,53 context={"request": request,54 'post_comment': post_comment})55 return post_comment_reactions_serializer.data56class PostCommentReactionField(Field):57 def __init__(self, post_comment_reaction_serializer=None, **kwargs):58 kwargs['source'] = '*'59 kwargs['read_only'] = True60 self.comment_reaction_serializer = post_comment_reaction_serializer61 super(PostCommentReactionField, self).__init__(**kwargs)62 def to_representation(self, post_comment):63 request = self.context.get('request')64 request_user = request.user65 serialized_commentReaction = None...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful