Esempio n. 1
0
    def test_create_post_notification_user_is_same(self):
        post = Post(content='as;ldkfja;')
        post.save()
        response = create_notification_util(post.object_uuid, self.pleb,
                                            [self.pleb], str(uuid1()),
                                            self.url, post.action_name)

        self.assertTrue(response)
Esempio n. 2
0
 def setUp(self):
     self.email = "*****@*****.**"
     self.pleb = create_user_util_test(self.email)
     self.user = User.objects.get(email=self.email)
     self.post = Post(content='test',
                      object_uuid=str(uuid1()),
                      owner_username=self.pleb.username,
                      wall_owner_username=self.pleb.username).save()
     self.post.owned_by.connect(self.pleb)
Esempio n. 3
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()
Esempio n. 4
0
    def test_create_post_notification_already_exists_not_sent(self):
        notification = Notification().save()
        post = Post(object_uuid=uuid1(), content='as;ldkfja;')
        post.save()
        response = create_notification_util(post.object_uuid, self.pleb,
                                            [self.pleb2],
                                            notification.object_uuid, self.url,
                                            post.action_name)

        self.assertTrue(response)
Esempio n. 5
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)
Esempio n. 6
0
 def test_create_comment_notification_already_exists_not_sent(self):
     comment = Comment(content='sdfasd')
     comment.save()
     notification = Notification().save()
     post = Post(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)
Esempio n. 7
0
 def setUp(self):
     self.email = "*****@*****.**"
     self.pleb = create_user_util_test(self.email)
     self.user = User.objects.get(email=self.email)
     self.post = Post(content='test',
                      owner_username=self.pleb.username,
                      wall_owner_username=self.pleb.username).save()
     self.post.owned_by.connect(self.pleb)
     self.uploaded_object = UploadedObject(url='www.example.com',
                                           height=300,
                                           width=300).save()
     self.post.uploaded_objects.connect(self.uploaded_object)
Esempio n. 8
0
    def test_create_notification_task_failure(self):
        post = Post(**self.post_info_dict)
        post.save()

        data = {
            'sb_object': post,
            'from_pleb': self.pleb.email,
            'to_plebs': [self.pleb2.email, '*****@*****.**']
        }
        response = spawn_notifications.apply_async(kwargs=data)
        while not response.ready():
            time.sleep(1)
        self.assertIsInstance(response.result, Exception)
Esempio n. 9
0
    def test_create_notification_post_task(self):
        post = Post(**self.post_info_dict)
        post.save()

        data = {
            'sb_object': post,
            'from_pleb': self.pleb.email,
            'to_plebs': [
                self.pleb2.email,
            ]
        }
        response = spawn_notifications.apply_async(kwargs=data)
        while not response.ready():
            time.sleep(3)
        self.assertTrue(response.result)
 def test_list_with_items_friends(self):
     from sb_wall.neo_models import Wall
     self.client.force_authenticate(user=self.user)
     email2 = "*****@*****.**"
     friend = create_user_util_test(email2)
     query = 'MATCH (pleb:Pleb {username: "******"})' \
             '-[:OWNS_WALL]->(wall:Wall) ' \
             'RETURN wall' % friend.username
     res, _ = db.cypher_query(query)
     if res.one is None:
         wall = Wall(wall_id=str(uuid1())).save()
         query = 'MATCH (pleb:Pleb {username: "******"}),' \
                 '(wall:Wall {wall_id: "%s"}) ' \
                 'CREATE UNIQUE (pleb)-[:OWNS_WALL]->(wall) ' \
                 'RETURN wall' % (friend.username, wall.wall_id)
         res, _ = db.cypher_query(query)
     wall = Wall.inflate(res.one)
     post = Post(content="My first post",
                 owner_username=self.pleb.username,
                 wall_owner_username=self.pleb.username).save()
     post.owned_by.connect(self.pleb)
     wall.posts.connect(post)
     post.posted_on_wall.connect(wall)
     self.pleb.friends.connect(friend)
     friend.friends.connect(self.pleb)
     url = reverse('profile-wall', kwargs={'username': friend.username})
     response = self.client.get(url, format='json')
     self.assertGreater(response.data['count'], 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)
Esempio n. 12
0
 def test_multiple_posts(self):
     post_array = []
     wall = self.pleb.get_wall()
     for item in range(0, 50):
         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)
         post_array.append(test_post)
     self.client.login(username=self.username, password=self.password)
     response = self.client.get(reverse(
         "profile_page", kwargs={"pleb_username": self.pleb.username}),
                                follow=True)
     self.assertEqual(response.status_code, 200)
     for post in post_array:
         post.delete()
 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)
 def test_list_with_items(self):
     self.client.force_authenticate(user=self.user)
     post = Post(content="My first post",
                 owner_username=self.pleb.username,
                 wall_owner_username=self.pleb.username).save()
     post.owned_by.connect(self.pleb)
     self.wall.posts.connect(post)
     post.posted_on_wall.connect(self.wall)
     url = reverse('profile-wall', kwargs={'username': self.pleb.username})
     response = self.client.get(url, format='json')
     self.assertGreater(response.data['count'], 0)
Esempio n. 15
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()
Esempio n. 16
0
class TestGetUploadedObject(TestCase):
    def setUp(self):
        self.email = "*****@*****.**"
        self.pleb = create_user_util_test(self.email)
        self.user = User.objects.get(email=self.email)
        self.post = Post(content='test',
                         owner_username=self.pleb.username,
                         wall_owner_username=self.pleb.username).save()
        self.post.owned_by.connect(self.pleb)
        self.uploaded_object = UploadedObject(url='www.example.com',
                                              height=300,
                                              width=300).save()
        self.post.uploaded_objects.connect(self.uploaded_object)

    def test_get_uploaded_object(self):
        res = self.post.get_uploaded_objects()
        self.assertEqual(res[0]['url'], self.uploaded_object.url)

    def test_get_uploaded_object_no_objects(self):
        self.post.uploaded_objects.disconnect(self.uploaded_object)
        res = self.post.get_uploaded_objects()
        self.assertFalse(res)
Esempio n. 17
0
    def test_initial_vote_create_private_content(self):
        post = Post(content='test content').save()
        data = {
            "object_uuid": post.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)
 def test_update(self):
     self.client.force_authenticate(user=self.user)
     post = Post(content='This is a test post',
                 wall_owner_username=self.pleb.username).save()
     url = reverse("post-detail", kwargs={"object_uuid": post.object_uuid})
     url_content = URLContent(url="http://reddit.com").save()
     self.client.patch(url,
                       data={
                           "content": "This is a test post reddit.com",
                           "included_urls": ["http://reddit.com"]
                       },
                       format='json')
     self.assertTrue(post.url_content.is_connected(url_content))
     url_content.delete()
Esempio n. 19
0
class TestVotableContentNeoModel(TestCase):
    def setUp(self):
        self.email = "*****@*****.**"
        self.pleb = create_user_util_test(self.email)
        self.user = User.objects.get(email=self.email)
        self.post = Post(content='test',
                         object_uuid=str(uuid1()),
                         owner_username=self.pleb.username,
                         wall_owner_username=self.pleb.username).save()
        self.post.owned_by.connect(self.pleb)

    def test_vote_content(self):
        res = self.post.vote_content(True, self.pleb)

        self.assertIsInstance(res, Post)

    def test_vote_content_already_voted(self):
        rel = self.post.votes.connect(self.pleb)
        rel.vote_type = True
        rel.save()

        res = self.post.vote_content(True, self.pleb)

        self.assertIsInstance(res, Post)

    def test_vote_content_change_vote(self):
        rel = self.post.votes.connect(self.pleb)
        rel.vote_type = False
        rel.save()

        res = self.post.vote_content(True, self.pleb)

        self.assertIsInstance(res, Post)

    def test_vote_content_change_vote_negative(self):
        rel = self.post.votes.connect(self.pleb)
        rel.vote_type = False
        rel.save()

        res = self.post.vote_content(2, self.pleb)
        rel = self.post.votes.relationship(self.pleb)
        self.assertFalse(rel.active)
        self.assertIsInstance(res, Post)

    def test_council_vote(self):
        res = self.post.council_vote(True, self.pleb)
        self.assertIsNotNone(res)

    def test_council_vote_already_vote(self):
        rel = self.post.council_votes.connect(self.pleb)
        rel.vote_type = True
        rel.active = True
        rel.save()
        res = self.post.council_vote(True, self.pleb)
        self.assertIsNotNone(res)
 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"
 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)
Esempio n. 22
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)
 def setUp(self):
     self.unit_under_test_name = 'pleb'
     self.email = "*****@*****.**"
     self.email2 = "*****@*****.**"
     res = create_user_util_test(self.email, task=True)
     while not res['task_id'].ready():
         time.sleep(.1)
     self.pleb = Pleb.nodes.get(email=self.email)
     self.pleb2 = create_user_util_test(self.email2)
     self.user2 = User.objects.get(email=self.email2)
     self.post = Post(content="Hey I'm a post",
                      owner_username=self.pleb.username,
                      wall_owner_username=self.pleb.username).save()
     self.post.owned_by.connect(self.pleb)
     self.post.posted_on_wall.connect(self.pleb.get_wall())
     self.pleb.get_wall().posts.connect(self.post)
     self.user = User.objects.get(email=self.email)
 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'])
Esempio n. 25
0
 def test_vote_private(self):
     post = Post(object_uuid=str(uuid1()),
                 owner_username=self.pleb.username).save()
     post.owned_by.connect(self.pleb)
     task_data = {
         'node_id': str(uuid1()),
         'voter': self.pleb.username,
         'parent_object': post.object_uuid,
         'vote_type': 0
     }
     res = create_vote_node.apply_async(kwargs=task_data)
     while not res.ready():
         time.sleep(1)
     self.assertTrue(res.result)
     test_vote = Vote.nodes.get(object_uuid=task_data['node_id'])
     self.assertEqual(test_vote.reputation_change, 0)
     self.assertTrue(post.first_votes.is_connected(test_vote))
     self.assertTrue(post.last_votes.is_connected(test_vote))
 def test_list_with_items_friends(self):
     self.client.force_authenticate(user=self.user)
     email2 = "*****@*****.**"
     res = create_user_util_test(email2, task=True)
     while not res['task_id'].ready():
         time.sleep(.1)
     friend = Pleb.nodes.get(email=email2)
     post = Post(content="My first post",
                 owner_username=self.pleb.username,
                 wall_owner_username=self.pleb.username).save()
     post.owned_by.connect(self.pleb)
     wall = friend.get_wall()
     wall.posts.connect(post)
     post.posted_on_wall.connect(wall)
     self.pleb.friends.connect(friend)
     friend.friends.connect(self.pleb)
     url = "%s?wall=%s" % (reverse('post-list'), friend.username)
     response = self.client.get(url, format='json')
     self.assertGreater(response.data['count'], 0)
 def test_list_with_items_not_friends(self):
     self.client.force_authenticate(user=self.user)
     email2 = "*****@*****.**"
     res = create_user_util_test(email2, task=True)
     while not res['task_id'].ready():
         time.sleep(.1)
     friend = Pleb.nodes.get(email=email2)
     post = Post(content="My first post",
                 owner_username=self.pleb.username,
                 wall_owner_username=self.pleb.username).save()
     post.owned_by.connect(self.pleb)
     wall = friend.get_wall()
     wall.posts.connect(post)
     post.posted_on_wall.connect(wall)
     self.pleb.friends.disconnect(friend)
     friend.friends.disconnect(self.pleb)
     url = reverse('profile-wall', kwargs={'username': friend.username})
     response = self.client.get(url, format='json')
     self.assertEqual(response.data['results'], [])
Esempio n. 28
0
 def test_with_post(self):
     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.get_wall()
     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])
     test_post.delete()
Esempio n. 29
0
    def newsfeed(self, request):
        """
        The newsfeed endpoint expects to be called on the me endpoint and
        assumes that the request object provided will contain the user the
        newsfeed is being provided to. It is not included as a list_route on
        the me endpoint due to the me endpoint not being a viewset.
        If we transition to that structure it could easily be moved to a
        list_route there.
        Query if we want to grab tags:
        MATCH (a:Pleb {username: "******"})-
                [OWNS_QUESTION]->(questions:Question)-[:TAGGED_AS]->(tags:Tag)
            WHERE questions.to_be_deleted = False AND questions.created > %s
            RETURN questions, tags.name AS tags, NULL as solutions,
                NULL as posts UNION
        MATCH (a)-[manyFriends:FRIENDS_WITH*2 {active: True}]->
                ()-[OWNS_QUESTION]->(questions:Question)-[:TAGGED_AS]->
                (tags:Tag)
            WHERE questions.to_be_deleted = False AND questions.created > %s
            RETURN questions, tags.name AS tags, NULL as posts,
                NULL as solutions UNION

        :param request:
        """
        # This query retrieves all of the current user's posts, solutions,
        # and questions as well as their direct friends posts, solutions,
        # and questions. It then looks for all of their friends friends
        # solutions and questions, combines all of the content and
        # returns the result. The query filters out content scheduled for
        # deletion and only looks for content created more recently than the
        # time provided. The reasoning for not including friends of friends
        # posts is to try and improve privacy. Friends of friends have not
        # actually been accepted potentially as friends by the user and
        # therefore should not have access to information posted on the user's
        # wall which in this case would be their posts.
        # We currently do not sort this query in neo because we are waiting
        # for post processing on unions as a whole to be added as a feature.
        # See Github issue #2725 for updates
        # https://github.com/neo4j/neo4j/issues/2725
        then = (datetime.now(pytz.utc) - timedelta(days=120)).strftime("%s")
        query = \
            '// Retrieve all the current users questions\n' \
            'MATCH (a:Pleb {username: "******"})<-[:OWNED_BY]-' \
            '(questions:Question) ' \
            'WHERE questions.to_be_deleted = False AND questions.created > %s' \
            ' AND questions.is_closed = False ' \
            'RETURN questions, NULL AS solutions, NULL AS posts, ' \
            'questions.created AS created, NULL AS s_question, ' \
            'NULL AS mission, NULL AS updates, NULL AS q_mission, ' \
            'NULL AS news UNION ' \
            '' \
            '// Retrieve all the news articles the user may be \n' \
            '// interested in\n' \
            'MATCH (a:Pleb {username: "******"})-[:INTERESTED_IN]->' \
            '(tag:Tag)<-[:TAGGED_AS]-(news:NewsArticle) ' \
            'WHERE news.published > %s AND news.is_closed = False ' \
            ' RETURN DISTINCT news, NULL AS solutions, NULL AS posts, ' \
            'news.published AS created, NULL AS s_question, ' \
            'NULL AS mission, NULL AS updates, NULL AS q_mission, ' \
            'NULL AS questions UNION ' \
            '' \
            '// Retrieve all the current users solutions\n' \
            'MATCH (a:Pleb {username: "******"})<-' \
            '[:OWNED_BY]-(solutions:Solution)<-' \
            '[:POSSIBLE_ANSWER]-(s_question:Question) ' \
            'WHERE s_question.to_be_deleted = False ' \
            'AND solutions.created > %s' \
            ' AND solutions.is_closed = False ' \
            'AND s_question.is_closed = False ' \
            'RETURN solutions, NULL AS questions, NULL AS posts, ' \
            'solutions.created AS created, s_question AS s_question,' \
            'NULL AS mission, NULL AS updates, NULL AS q_mission, ' \
            'NULL AS news UNION ' \
            '' \
            '// Retrieve all the current users posts\n' \
            'MATCH (a:Pleb {username: "******"})<-[:OWNED_BY]-(posts:Post) ' \
            'WHERE posts.to_be_deleted = False AND posts.created > %s ' \
            'AND posts.is_closed = False ' \
            'RETURN posts, NULL as questions, NULL as solutions, ' \
            'posts.created AS created, NULL AS s_question,' \
            'NULL AS mission, NULL AS updates, NULL AS q_mission, ' \
            'NULL AS news UNION ' \
            '' \
            '// Retrieve all the posts on the current users wall that are \n' \
            '// not owned by the current user \n' \
            'MATCH (a:Pleb {username: "******"})-[:OWNS_WALL]->(w:Wall)' \
            '-[:HAS_POST]->(posts:Post) ' \
            'WHERE NOT (posts)-[:OWNED_BY]->(a) AND ' \
            'posts.to_be_deleted = False AND posts.created > %s ' \
            'AND posts.is_closed = False ' \
            'RETURN posts, NULL as questions, NULL as solutions, ' \
            'posts.created AS created, NULL AS s_question,' \
            'NULL AS mission, NULL AS updates, NULL AS q_mission, ' \
            'NULL AS news UNION ' \
            '' \
            '// Retrieve the missions affecting the given user\n' \
            'MATCH (a:Pleb {username: "******"})-[:LIVES_AT]->(:Address)-' \
            '[:ENCOMPASSED_BY*..]->' \
            '(:Location)<-[:WITHIN]-(mission:Mission {active: true})' \
            '<-[:EMBARKS_ON]-(quest:Quest {active: true}) ' \
            'WHERE NOT((mission)-[:FOCUSED_ON]->(:Position {verified:false}))' \
            ' AND mission.created > %s ' \
            'RETURN mission, NULL AS solutions, NULL AS posts, ' \
            'NULL AS questions, mission.created AS created, ' \
            'NULL AS s_question, NULL AS updates, NULL AS q_mission, ' \
            'NULL AS news UNION ' \
            '' \
            '// Retrieve the mission updates affecting ' \
            '// the given user\n' \
            'MATCH (a:Pleb {username: "******"})-[:LIVES_AT]->(:Address)-' \
            '[:ENCOMPASSED_BY*..]->' \
            '(:Location)<-[:WITHIN]-(q_mission:Mission {active: true})' \
            '<-[:EMBARKS_ON]-(quest:Quest {active: true}) WITH q_mission ' \
            'MATCH (q_mission)<-[:ABOUT]-(updates:Update) ' \
            'WHERE NOT((q_mission)-[:FOCUSED_ON]' \
            '->(:Position {verified:false}))' \
            ' AND updates.created > %s AND updates.is_closed = False ' \
            'RETURN updates, NULL AS solutions, NULL AS posts, ' \
            'NULL AS questions, updates.created AS created, ' \
            'NULL AS s_question, NULL as mission, q_mission, ' \
            'NULL AS news UNION ' \
            '' \
            '// Retrieve all the posts owned by users that the current user ' \
            '// is following \n' \
            'MATCH (a:Pleb {username: "******"})-[r:FOLLOWING {active: True}]->' \
            '(:Pleb)<-[:OWNED_BY]-(posts:Post) ' \
            'WHERE posts.to_be_deleted = False AND ' \
            'posts.created > %s AND posts.is_closed = False ' \
            'RETURN NULL AS solutions, posts AS posts, ' \
            'NULL AS questions, posts.created AS created, ' \
            'NULL AS s_question, NULL AS mission, NULL AS updates, ' \
            'NULL AS q_mission, ' \
            'NULL AS news UNION ' \
            '' \
            '// Retrieve all the users questions that the current user is ' \
            '// following \n' \
            'MATCH (a:Pleb {username: "******"})-[r:FOLLOWING {active: True}]->' \
            '(:Pleb)<-[:OWNED_BY]-(questions:Question) ' \
            'WHERE questions.to_be_deleted = False AND ' \
            'questions.created > %s AND questions.is_closed = False ' \
            'RETURN NULL AS solutions, NULL AS posts, ' \
            'questions AS questions, questions.created AS created, ' \
            'NULL AS s_question, NULL AS mission, NULL AS updates, ' \
            'NULL AS q_mission, ' \
            'NULL AS news UNION ' \
            '' \
            '// Retrieve all the users solutions that the current user is ' \
            '// following \n' \
            'MATCH (a:Pleb {username: "******"})-[r:FOLLOWING {active: True}]->' \
            '(:Pleb)<-[:OWNED_BY]-(solutions:Solution)<-' \
            '[:POSSIBLE_ANSWER]-(s_question:Question) ' \
            'WHERE s_question.to_be_deleted = False AND ' \
            'solutions.created > %s AND solutions.is_closed = False ' \
            'RETURN solutions, NULL AS posts, ' \
            'NULL AS questions, solutions.created AS created, ' \
            's_question as s_question, NULL AS mission, NULL AS updates, ' \
            'NULL AS q_mission, ' \
            'NULL AS news' \
            % (
                request.user.username, then, request.user.username, then,
                request.user.username, then,
                request.user.username, then, request.user.username, then,
                request.user.username, then, request.user.username, then,
                request.user.username, then, request.user.username, then,
                request.user.username, then)
        news = []
        res, _ = db.cypher_query(query)
        # Profiled with ~50 objects and it was still performing under 1 ms.
        # By the time sorting in python becomes an issue the above mentioned
        # ticket should be resolved.
        res = sorted(res, key=attrgetter('created'), reverse=True)
        page = self.paginate_queryset(res)
        for row in page:
            news_article = None
            if row.questions is not None:
                row.questions.pull()
                news_article = QuestionSerializerNeo(Question.inflate(
                    row.questions),
                                                     context={
                                                         'request': request
                                                     }).data
            elif row.solutions is not None:
                row.s_question.pull()
                row.solutions.pull()
                question_data = QuestionSerializerNeo(
                    Question.inflate(row.s_question)).data
                news_article = SolutionSerializerNeo(Solution.inflate(
                    row.solutions),
                                                     context={
                                                         'request': request
                                                     }).data
                news_article['question'] = question_data
            elif row.posts is not None:
                row.posts.pull()
                news_article = PostSerializerNeo(Post.inflate(row.posts),
                                                 context={
                                                     'request': request
                                                 }).data
            elif row.mission is not None:
                row.mission.pull()
                news_article = MissionSerializer(Mission.inflate(row.mission),
                                                 context={
                                                     'request': request
                                                 }).data
                news_article['reputation'] = Pleb.get(
                    username=news_article['owner_username']).reputation
            elif row.updates is not None:
                row.updates.pull()
                row.q_mission.pull()
                news_article = UpdateSerializer(Update.inflate(row.updates),
                                                context={
                                                    'request': request
                                                }).data
                news_article['mission'] = MissionSerializer(
                    Mission.inflate(row.q_mission),
                    context={
                        'request': request
                    }).data
            elif row.news is not None:
                row.news.pull()
                news_article = NewsArticleSerializer(NewsArticle.inflate(
                    row.news),
                                                     context={
                                                         'request': request
                                                     }).data
            news.append(news_article)
        return self.get_paginated_response(news)
 def setUp(self):
     self.unit_under_test_name = 'post'
     self.email = "*****@*****.**"
     self.pleb = create_user_util_test(self.email)
     self.user = User.objects.get(email=self.email)
     self.post = Post(content="some dummy content").save()