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()
 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_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()
Example #4
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)
Example #5
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)
 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)
Example #7
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)
 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)
Example #9
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)
 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)
Example #11
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)
Example #12
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)
Example #13
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)
Example #14
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()
Example #16
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_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)
 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 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)
Example #20
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()
 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'])
Example #22
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'], [])
Example #25
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 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()