Beispiel #1
0
    def test_post_returns_forbidden_for_not_authorized_user(self):
        interpretation = Helpers.createInterpretation()
        url = '/compositions/{0}/interpretations/{1}/comments'.format(interpretation.composition.id, interpretation.id)

        response = self.client.post(url, data={})

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(
            response.data, {"detail": "Authentication credentials were not provided."})
        self.assertEqual(Comment.objects.all().count(), 0)
    def test_delete_return_forbidden_for_non_authenticated_user(self):
        user1 = Helpers.getUser(Helpers.USER1)
        interpretation = Helpers.createInterpretation()
        comment = Comment.objects.create(
            commenter=user1, interpretation=interpretation, comment='comment1')
        url = '/compositions/{0}/interpretations/{1}/comments/{2}'.format(
            interpretation.composition.id,
            interpretation.id,
            comment.id)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Beispiel #3
0
    def test_post_authenticated_user_valid_post_data(self):
        user2 = Helpers.getUser(Helpers.USER2)
        interpretation = Helpers.createInterpretation()
        comment_data = {'comment': 'comment1'}
        url = '/compositions/{0}/interpretations/{1}/comments'.format(interpretation.composition.id, interpretation.id)

        self.client.login(username='******', password='******')
        response = self.client.post(url, data=comment_data)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data, self.createResponse(
            1, 'comment1', user2.id, interpretation.id, datetime.now()))
        self.assertEqual(Comment.objects.all().count(), 1)
Beispiel #4
0
    def test_post_for_authenticated_user_empty_comment(self):
        Helpers.getUser(Helpers.USER2)
        interpretation = Helpers.createInterpretation()
        comment_data = {'comment': ''}
        url = '/compositions/{0}/interpretations/{1}/comments'.format(interpretation.composition.id, interpretation.id)

        self.client.login(username='******', password='******')
        response = self.client.post(url, data=comment_data)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data, {"comment": ["This field is required."]})
        self.assertEqual(Comment.objects.all().count(), 0)
    def test_delete_for_autheticated_valid_commenter(self):
        user1 = Helpers.getUser(Helpers.USER1)
        interpretation = Helpers.createInterpretation()
        comment = Comment.objects.create(
            commenter=user1, interpretation=interpretation, comment='comment1')
        url = '/compositions/{0}/interpretations/{1}/comments/{2}'.format(
            interpretation.composition.id,
            interpretation.id,
            comment.id)

        self.client.login(username='******', password='******')
        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
    def test_delete_returns_forbidden_for_user_not_commenter(self):
        user1 = Helpers.getUser(Helpers.USER1)
        Helpers.getUser(Helpers.USER2)
        interpretation = Helpers.createInterpretation()
        comment = Comment.objects.create(
            commenter=user1, interpretation=interpretation, comment='comment1')
        url = '/compositions/{0}/interpretations/{1}/comments/{2}'.format(
            interpretation.composition.id,
            interpretation.id,
            comment.id)

        self.client.login(username='******', password='******')
        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
    def test_update_for_autheticated_valid_commenter(self):
        user1 = Helpers.getUser(Helpers.USER1)
        interpretation = Helpers.createInterpretation()
        comment = Comment.objects.create(
            commenter=user1, interpretation=interpretation, comment='comment1')
        comment_data = {'comment': 'comment2'}
        url = '/compositions/{0}/interpretations/{1}/comments/{2}'.format(
            interpretation.composition.id,
            interpretation.id,
            comment.id)

        self.client.login(username='******', password='******')
        response = self.client.put(url, data=comment_data)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, self.createResponse(
            1, 'comment2', user1.id, interpretation.id, comment.created, True))
Beispiel #8
0
    def test_get_returns_all_comments_for_interpretation(self):
        user1 = Helpers.getUser(Helpers.USER1)
        user2 = Helpers.getUser(Helpers.USER1)
        interpretation = Helpers.createInterpretation()
        comment1 = Comment.objects.create(
            commenter=user1, interpretation=interpretation, comment='comment1')
        comment2 = Comment.objects.create(
            commenter=user1, interpretation=interpretation, comment='comment2')
        comment3 = Comment.objects.create(
            commenter=user2, interpretation=interpretation, comment='comment3')
        url = '/compositions/{0}/interpretations/{1}/comments'.format(interpretation.composition.id, interpretation.id)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        expected_response = [
            self.createResponse(1, 'comment1', user1.id, interpretation.id, comment1.created)]
        expected_response.append(
            self.createResponse(2, 'comment2', user1.id, interpretation.id, comment2.created))
        expected_response.append(
            self.createResponse(3, 'comment3', user2.id, interpretation.id, comment3.created))
        self.assertEqual(response.data, expected_response)
 def createVote(self):
     interpretation = Helpers.createInterpretation()
     return InterpretationVote.objects.get(interpretation=interpretation)