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()
 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()
Beispiel #3
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)
Beispiel #4
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)
    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)
Beispiel #6
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()