Ejemplo n.º 1
0
 def setUp(self):
     self.unit_under_test_name = 'comment'
     self.email = "*****@*****.**"
     self.pleb = create_user_util_test(self.email)
     self.user = User.objects.get(email=self.email)
     self.url = "http://testserver"
     self.comment = Comment(content="test comment",
                            owner_username=self.pleb.username).save()
     self.comment.owned_by.connect(self.pleb)
Ejemplo n.º 2
0
 def test_create_comment_notification_already_exists_sent(self):
     comment = Comment(content='sdfasd')
     comment.save()
     notification = Notification(sent=True).save()
     post = Post(object_uuid=uuid1(), content='as;ldkfja;')
     post.save()
     response = create_notification_util(comment.object_uuid, self.pleb,
                                         [self.pleb2],
                                         notification.object_uuid, self.url,
                                         post.action_name)
     self.assertTrue(response)
Ejemplo n.º 3
0
    def test_create_comment_notification_pleb_is_the_same(self):
        post = Post(content='as;ldkfja;')
        post.save()
        comment = Comment(content='sdfasd')
        comment.save()

        response = create_notification_util(comment.object_uuid, self.pleb,
                                            [self.pleb], str(uuid1()),
                                            self.url, post.action_name)

        self.assertTrue(response)
Ejemplo n.º 4
0
 def test_can_flag(self, m):
     m.get(reverse('question-detail',
                   kwargs={'object_uuid': self.question.object_uuid}),
           json=QuestionSerializerNeo(self.question).data,
           status_code=status.HTTP_200_OK)
     self.client.force_authenticate(user=self.user)
     comment = Comment(content='test_content',
                       owner_username=self.pleb2.username,
                       parent_type="question",
                       parent_id=self.question.object_uuid).save()
     comment.owned_by.connect(self.pleb2)
     self.question.comments.connect(comment)
     privilege = Privilege.nodes.get(name="flag")
     self.pleb.privileges.connect(privilege)
     cache.clear()
     url = "%scomments/%s/?expedite=true" % (reverse(
         'question-detail',
         kwargs={'object_uuid': self.question.object_uuid
                 }), comment.object_uuid)
     response = self.client.get(url, format='json')
     self.pleb.privileges.disconnect(privilege)
     self.question.comments.disconnect(comment)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertTrue(response.data['can_flag']['status'])
     self.assertIsNone(response.data['can_flag']['detail'])
     self.assertIsNone(response.data['can_flag']['short_detail'])
Ejemplo n.º 5
0
 def test_can_not_flag(self, m):
     m.get(reverse('question-detail',
                   kwargs={'object_uuid': self.question.object_uuid}),
           json=QuestionSerializerNeo(self.question).data,
           status_code=status.HTTP_200_OK)
     self.client.force_authenticate(user=self.user)
     comment = Comment(content='test_content',
                       owner_username=self.pleb2.username,
                       parent_type="question",
                       parent_id=self.question.object_uuid).save()
     comment.owned_by.connect(self.pleb2)
     self.question.comments.connect(comment)
     self.pleb.save()
     for item in self.pleb.privileges.all():
         self.pleb.privileges.disconnect(item)
     cache.clear()
     url = "%scomments/%s/" % (reverse(
         'question-detail',
         kwargs={'object_uuid': self.question.object_uuid
                 }), comment.object_uuid)
     response = self.client.get(url, format='json')
     self.question.comments.disconnect(comment)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertFalse(response.data['can_flag']['status'])
     self.assertEqual(
         response.data['can_flag']['detail'],
         "You must have 50+ reputation to flag Conversation "
         "Cloud content.")
     self.assertEqual(response.data['can_flag']['short_detail'],
                      "Requirement: 50+ Reputation")
Ejemplo n.º 6
0
    def test_spawn_comment_notifications_comment_on_comment(self, m):
        m.get("%s/questions/%s/" %
              (self.api_endpoint, self.question.object_uuid),
              json={
                  "url":
                  "http://www.sagebrew.com/v1/questions/%s/" %
                  self.question.object_uuid
              },
              status_code=status.HTTP_200_OK)
        comment2 = Comment(
            owner_username=self.pleb2.username,
            url="%s/questions/%s/" %
            (self.api_endpoint, self.question.object_uuid)).save()
        comment = Comment(
            owner_username=self.pleb.username,
            url="%s/questions/%s/" %
            (self.api_endpoint, self.question.object_uuid)).save()
        self.question.owned_by.connect(self.pleb)
        self.question.owner_username = self.pleb.username
        self.question.save()

        comment.owned_by.connect(self.pleb)
        self.question.comments.connect(comment)

        comment2.owned_by.connect(self.pleb2)
        self.question.comments.connect(comment2)

        notification_id = str(uuid1())
        comment_on_comment_id = str(uuid1())
        data = {
            "object_uuid": comment.object_uuid,
            "parent_object_uuid": self.question.object_uuid,
            "from_pleb": self.pleb.username,
            "notification_id": notification_id,
            "comment_on_comment_id": comment_on_comment_id
        }
        res = spawn_comment_notifications.apply_async(kwargs=data)
        while not res.ready():
            time.sleep(1)
        self.assertTrue(res.result)
        while not res.result['comment_on_comment_task'].ready():
            time.sleep(1)
        notification = Notification.nodes.get(
            object_uuid=comment_on_comment_id)
        self.assertEqual(notification.action_name, "commented on a question "
                         "you commented on")
        self.assertTrue(self.pleb2 in notification.notification_to)
Ejemplo n.º 7
0
 def test_multiple_posts_multiple_comments_friends(self):
     wall = self.pleb.get_wall()
     pleb_array = []
     post_array = []
     comment_array = []
     for item in range(0, 2):
         test_pleb = Pleb(email=str(uuid1())[:32],
                          username=str(uuid1())[:32])
         test_pleb.save()
         pleb_array.append(test_pleb)
         for number in range(0, 10):
             test_post = Post(content='test',
                              object_uuid=str(uuid1()),
                              owner_username=self.pleb.username,
                              wall_owner_username=self.pleb.username)
             test_post.save()
             test_post.posted_on_wall.connect(wall)
             wall.posts.connect(test_post)
             test_post.owned_by.connect(test_pleb)
             post_array.append(test_post)
             for num in range(0, 1):
                 my_comment = Comment(content='test comment',
                                      object_uuid=str(uuid1()),
                                      owner_username=self.pleb.username)
                 my_comment.save()
                 my_comment.owned_by.connect(test_pleb)
                 test_post.comments.connect(my_comment)
                 comment_array.append(my_comment)
                 my_comment = Comment(content='test comment',
                                      object_uuid=str(uuid1()),
                                      owner_username=self.pleb.username)
                 my_comment.save()
                 my_comment.owned_by.connect(self.pleb)
                 test_post.comments.connect(my_comment)
                 comment_array.append(my_comment)
     test_post = Post(content='test',
                      object_uuid=str(uuid1()),
                      owner_username=self.pleb.username,
                      wall_owner_username=self.pleb.username)
     test_post.save()
     test_post.posted_on_wall.connect(wall)
     wall.posts.connect(test_post)
     test_post.owned_by.connect(self.pleb)
     request = self.factory.get('/%s' % self.pleb.username)
     request.user = self.user
     profile_page = ProfileView.as_view()
     response = profile_page(request, self.pleb.username)
     self.assertIn(response.status_code,
                   [status.HTTP_200_OK, status.HTTP_302_FOUND])
     for item in pleb_array:
         item.delete()
     for post in post_array:
         post.delete()
     for comment in comment_array:
         comment.delete()
     test_post.delete()
Ejemplo n.º 8
0
    def test_create_notification_comment_task(self):
        post = Post(**self.post_info_dict)
        post.save()
        comment = Comment(content='sdfasd')
        comment.save()

        data = {
            'from_pleb': self.pleb.email,
            'to_plebs': [
                self.pleb2.email,
            ],
            'sb_object': comment
        }

        response = spawn_notifications.apply_async(kwargs=data)
        while not response.ready():
            time.sleep(3)
        self.assertTrue(response.result)
Ejemplo n.º 9
0
 def test_get_url(self):
     self.client.force_authenticate(user=self.user)
     comment = Comment(url='this is a url',
                       content='this is content').save()
     parent = Post(content='some content').save()
     parent.comments.connect(comment)
     url = reverse("comment-detail",
                   kwargs={'comment_uuid': comment.object_uuid})
     response = self.client.get(url, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 10
0
 def test_private_content_with_comment_unauthorized(self):
     post = Post(content='test_content',
                 owner_username=self.pleb.username).save()
     post.owned_by.connect(self.pleb)
     comment = Comment(content="This is my new comment").save()
     post.comments.connect(comment)
     url = "%scomments/?expand=true" % reverse(
         'post-detail', kwargs={"object_uuid": post.object_uuid})
     response = self.client.get(url, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['count'], 0)
Ejemplo n.º 11
0
 def test_post_with_comments_from_friend(self):
     test_user = Pleb(email=str(uuid1()) + '@gmail.com',
                      username=str(uuid1())[:32])
     test_user.save()
     test_post = Post(content='test',
                      object_uuid=str(uuid1()),
                      owner_username=self.pleb.username,
                      wall_owner_username=self.pleb.username)
     test_post.save()
     wall = self.pleb.wall.all()[0]
     test_post.posted_on_wall.connect(wall)
     wall.posts.connect(test_post)
     test_post.owned_by.connect(self.pleb)
     my_comment = Comment(content='test comment',
                          object_uuid=str(uuid1()),
                          owner_username=self.pleb.username)
     my_comment.save()
     my_comment.owned_by.connect(test_user)
     test_post.comments.connect(my_comment)
     request = self.factory.get('/%s' % self.pleb.username)
     request.user = self.user
     profile_page = ProfileView.as_view()
     response = profile_page(request, self.pleb.username)
     self.assertIn(response.status_code,
                   [status.HTTP_200_OK, status.HTTP_302_FOUND])
     test_user.delete()
     test_post.delete()
     my_comment.delete()
Ejemplo n.º 12
0
 def setUp(self):
     settings.CELERY_ALWAYS_EAGER = True
     self.api_endpoint = "http://testserver/v1"
     self.email = "*****@*****.**"
     self.pleb = create_user_util_test(self.email)
     self.user = User.objects.get(email=self.email)
     self.question = Question(title=str(uuid1())).save()
     self.comment = Comment(
         owner_username=self.pleb.username,
         url="%s/questions/%s/" %
         (self.api_endpoint, self.question.object_uuid)).save()
     self.email2 = "*****@*****.**"
     self.pleb2 = create_user_util_test(self.email2)
Ejemplo n.º 13
0
 def test_initial_vote_create_private_comment(self):
     post = Post().save()
     comment = Comment(content='test content', visibility="private").save()
     post.comments.connect(comment)
     data = {
         "object_uuid": comment.object_uuid,
         "previous_vote_type": None,
         "new_vote_type": 1,
         "voting_pleb": self.pleb.username
     }
     res = object_vote_notifications.apply_async(kwargs=data)
     while not res.ready():
         time.sleep(1)
     self.assertTrue(res.result)
     self.assertNotIsInstance(res.result, Exception)
Ejemplo n.º 14
0
 def test_update_comment(self):
     self.client.force_authenticate(user=self.user)
     new_content = "this is the new content"
     comment = Comment(url='this is a url',
                       content='this is content').save()
     parent = Post(content='some content').save()
     parent.comments.connect(comment)
     url = reverse("comment-detail",
                   kwargs={'comment_uuid': comment.object_uuid})
     response = self.client.patch(url,
                                  data={'content': new_content},
                                  format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(
         Comment.nodes.get(object_uuid=comment.object_uuid).content,
         new_content)
Ejemplo n.º 15
0
 def setUp(self):
     self.unit_under_test_name = 'comment'
     self.email = "*****@*****.**"
     create_user_util_test(self.email)
     self.pleb = Pleb.nodes.get(email=self.email)
     self.user = User.objects.get(email=self.email)
     self.url = "http://testserver"
     self.post = Post(content='test content',
                      owner_username=self.pleb.username,
                      wall_owner_username=self.pleb.username).save()
     self.post.owned_by.connect(self.pleb)
     self.comment = Comment(content="test comment",
                            owner_username=self.pleb.username).save()
     self.comment.owned_by.connect(self.pleb)
     self.post.comments.connect(self.comment)
     self.api_endpoint = "http://testserver/v1"
Ejemplo n.º 16
0
 def list(self, request, *args, **kwargs):
     council_list = []
     html = request.query_params.get('html', 'false').lower()
     queryset = self.get_queryset()
     page = self.paginate_queryset(queryset)
     for row in page:
         if row[0] is not None:
             row[0].pull()  # fix for None objects being returned
             # from the query due to multiple column returns
         council_object = None
         if row.questions is not None:
             council_object = QuestionSerializerNeo(Question.inflate(
                 row.questions),
                                                    context={
                                                        'request': request
                                                    }).data
         elif row.solutions is not None:
             council_object = SolutionSerializerNeo(Solution.inflate(
                 row.solutions),
                                                    context={
                                                        'request': request
                                                    }).data
         elif row.comments is not None:
             council_object = CommentSerializer(Comment.inflate(
                 row.comments),
                                                context={
                                                    'request': request
                                                }).data
         elif row.posts is not None:
             council_object = PostSerializerNeo(Post.inflate(row.posts),
                                                context={
                                                    'request': request
                                                }).data
         if html == 'true':
             council_object['last_edited_on'] = parser.parse(
                 council_object['last_edited_on'])
             council_object['request'] = request
             council_object = {
                 "html":
                 render_to_string("council_votable.html", council_object),
                 "id":
                 council_object["id"],
                 "type":
                 council_object["type"]
             }
         council_list.append(council_object)
     return self.get_paginated_response(council_list)
Ejemplo n.º 17
0
 def test_update_comment_not_owner(self):
     self.client.force_authenticate(user=self.user2)
     new_content = "this is the new content"
     comment = Comment(url='this is a url',
                       content='this is content',
                       owner_username=self.pleb.username).save()
     parent = Post(content='some content').save()
     parent.comments.connect(comment)
     url = reverse("comment-detail",
                   kwargs={'comment_uuid': comment.object_uuid})
     response = self.client.patch(url,
                                  data={'content': new_content},
                                  format='json')
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertEqual(
         Comment.nodes.get(object_uuid=comment.object_uuid).content,
         'this is content')
     self.assertEqual(response.data, ['Only the owner can edit this'])
Ejemplo n.º 18
0
 def test_login_to_flag(self, m):
     m.get(reverse('question-detail',
                   kwargs={'object_uuid': self.question.object_uuid}),
           json=QuestionSerializerNeo(self.question).data,
           status_code=status.HTTP_200_OK)
     comment = Comment(content='test_content',
                       owner_username=self.pleb.username,
                       parent_type="question",
                       parent_id=self.question.object_uuid,
                       visibility="public").save()
     comment.owned_by.connect(self.pleb)
     self.question.comments.connect(comment)
     url = "%scomments/%s/" % (reverse(
         'question-detail',
         kwargs={'object_uuid': self.question.object_uuid
                 }), comment.object_uuid)
     response = self.client.get(url, format='json')
     self.question.comments.disconnect(comment)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertFalse(response.data['can_flag']['status'])
     self.assertEqual(response.data['can_flag']['detail'],
                      "You must be logged in to flag content.")
     self.assertEqual(response.data['can_flag']['short_detail'],
                      "Signup To Flag")
Ejemplo n.º 19
0
 def test_can_not_flag_own(self, m):
     m.get(reverse('question-detail',
                   kwargs={'object_uuid': self.question.object_uuid}),
           json=QuestionSerializerNeo(self.question).data,
           status_code=status.HTTP_200_OK)
     self.client.force_authenticate(user=self.user)
     comment = Comment(content='test_content',
                       owner_username=self.pleb.username,
                       parent_type="question",
                       parent_id=self.question.object_uuid).save()
     comment.owned_by.connect(self.pleb)
     self.question.comments.connect(comment)
     url = "%scomments/%s/" % (reverse(
         'question-detail',
         kwargs={'object_uuid': self.question.object_uuid
                 }), comment.object_uuid)
     response = self.client.get(url, format='json')
     self.question.comments.disconnect(comment)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertFalse(response.data['can_flag']['status'])
     self.assertEqual(response.data['can_flag']['detail'],
                      "You cannot flag your own content")
     self.assertEqual(response.data['can_flag']['short_detail'],
                      "Cannot Flag Own Content")
Ejemplo n.º 20
0
def object_vote_notifications(object_uuid, previous_vote_type, new_vote_type,
                              voting_pleb):
    sb_object = get_parent_votable_content(object_uuid)
    try:
        current_pleb = Pleb.get(username=voting_pleb)
    except (DoesNotExist, Pleb.DoesNotExist, CypherException, ClientError,
            IOError) as e:
        raise object_vote_notifications.retry(exc=e, countdown=10,
                                              max_retries=None)
    if new_vote_type != 2 and previous_vote_type != new_vote_type:
        reputation_change = sb_object.down_vote_adjustment
        modifier = "downvoted"
        reputation_message = ""
        if new_vote_type:
            reputation_change = sb_object.up_vote_adjustment
            modifier = "upvoted"
        if reputation_change:
            # using b tag here because a div or p will break the rendering of
            # the notification html due to them not being allowed in a tags
            color = "sb_reputation_notification_change_red"
            if reputation_change > 0:
                color = "sb_reputation_notification_change_green"
            reputation_message = render_to_string(
                'notification_message.html',
                {'color': color, 'reputation_change':
                    "%+d" % reputation_change})
            if sb_object.visibility != "public":
                reputation_message = ""
        public = False
        action_name = " %s %s %s " % ("%s your" % modifier,
                                      sb_object.get_child_label(),
                                      reputation_message)
        titled_content = get_parent_titled_content(sb_object.object_uuid)
        if not isinstance(titled_content, Exception):
            truncate_content = titled_content.title
        else:
            truncate_content = sb_object.content
        if sb_object.visibility == "public":
            action_name = '%s from vote on "%s"' % (reputation_message,
                                                    smart_truncate(
                                                        truncate_content))
            public = True
        if previous_vote_type != new_vote_type and new_vote_type != 2:
            if sb_object.get_child_label().lower() == "comment":
                comment_on = Comment.get_comment_on(sb_object.object_uuid)
                page_type = comment_on.get_child_label().lower()
                object_id = comment_on.object_uuid
            else:
                page_type = sb_object.get_child_label().lower()
                object_id = sb_object.object_uuid
            res = spawn_task(spawn_notifications, task_param={
                'from_pleb': current_pleb.username,
                'to_plebs': [sb_object.owner_username],
                'sb_object': sb_object.object_uuid,
                'notification_id': str(uuid1()),
                'url': reverse(
                    "single_%s_page" % page_type,
                    kwargs={"object_uuid": object_id}),
                'action_name': action_name,
                'public': public
            })
            if isinstance(res, Exception):
                raise object_vote_notifications.retry(exc=res, countdown=10,
                                                      max_retries=None)
    return True
Ejemplo n.º 21
0
class VotableContentSerializerTests(APITestCase):

    def setUp(self):
        self.unit_under_test_name = 'comment'
        self.email = "*****@*****.**"
        self.pleb = create_user_util_test(self.email)
        self.user = User.objects.get(email=self.email)
        self.url = "http://testserver"
        self.comment = Comment(content="test comment",
                               owner_username=self.pleb.username).save()
        self.comment.owned_by.connect(self.pleb)

    def test_get_can_comment_mission_owner(self):
        quest = Quest(owner_username=self.pleb.username).save()
        quest.owner.connect(self.pleb)
        mission = Mission(owner_username=self.pleb.username).save()
        quest.missions.connect(mission)
        question = Question(content='test content title',
                            title=str(uuid1())).save()
        mission.associated_with.connect(question)
        factory = APIRequestFactory()
        request = factory.get('')
        request.user = self.user
        res = VotableContentSerializer(
            question, context={'request': request}).data
        self.assertTrue(res['can_comment']['status'])
        mission.delete()
        quest.delete()

    def test_get_can_flag_mission_owner(self):
        quest = Quest(owner_username=self.pleb.username).save()
        quest.owner.connect(self.pleb)
        mission = Mission(owner_username=self.pleb.username).save()
        quest.missions.connect(mission)
        question = Question(content='test content title',
                            title=str(uuid1())).save()
        mission.associated_with.connect(question)
        factory = APIRequestFactory()
        request = factory.get('')
        request.user = self.user
        res = VotableContentSerializer(
            question, context={'request': request}).data
        self.assertTrue(res['can_flag']['status'])
        mission.delete()
        quest.delete()

    def test_get_can_flag_comment_mission_owner(self):
        quest = Quest(owner_username=self.pleb.username).save()
        quest.owner.connect(self.pleb)
        mission = Mission(owner_username=self.pleb.username).save()
        quest.missions.connect(mission)
        question = Question(content='test content title',
                            title=str(uuid1())).save()
        mission.associated_with.connect(question)
        question.comments.connect(self.comment)
        self.comment.parent_type = "question"
        self.comment.parent_id = question.object_uuid
        self.comment.owner_username = "******"
        self.comment.save()
        factory = APIRequestFactory()
        request = factory.get('')
        request.user = self.user
        res = VotableContentSerializer(
            self.comment, context={'request': request}).data
        self.assertTrue(res['can_flag']['status'])
        mission.delete()
        quest.delete()
        self.comment.owner_username = self.pleb.username
        self.comment.save()

    def test_get_can_downvote_mission_owner(self):
        quest = Quest(owner_username=self.pleb.username).save()
        quest.owner.connect(self.pleb)
        mission = Mission(owner_username=self.pleb.username).save()
        quest.missions.connect(mission)
        question = Question(content='test content title',
                            title=str(uuid1())).save()
        mission.associated_with.connect(question)
        factory = APIRequestFactory()
        request = factory.get('')
        request.user = self.user
        res = VotableContentSerializer(
            question, context={'request': request}).data
        self.assertTrue(res['can_downvote']['status'])
        mission.delete()
        quest.delete()

    def test_get_can_downvote_comment_mission_owner(self):
        quest = Quest(owner_username=self.pleb.username).save()
        quest.owner.connect(self.pleb)
        mission = Mission(owner_username=self.pleb.username).save()
        quest.missions.connect(mission)
        question = Question(content='test content title',
                            title=str(uuid1())).save()
        mission.associated_with.connect(question)
        question.comments.connect(self.comment)
        self.comment.parent_type = "question"
        self.comment.parent_id = question.object_uuid
        self.comment.owner_username = "******"
        self.comment.save()
        factory = APIRequestFactory()
        request = factory.get('')
        request.user = self.user
        res = VotableContentSerializer(
            self.comment, context={'request': request}).data
        self.assertTrue(res['can_flag']['status'])
        mission.delete()
        quest.delete()
        self.comment.owner_username = self.pleb.username
        self.comment.save()