示例#1
0
 def test_patch_annotation__deny__non_owner(self):
     owner_user, owner_user_pass = create_test_user(unique=True)
     annotation = Annotation.objects.create(
         user=owner_user,
         url='www.przypis.pl',
         comment="good job",
         annotation_link="www.przypispowszechny.com",
         annotation_link_title="very nice",
         quote='not this time')
     put_string = 'not so well'
     put_data = json.dumps({
         'data': {
             'type': 'annotations',
             'id': annotation.id,
             'attributes': {
                 'annotationLinkTitle': put_string
             }
         }
     })
     response = self.client.patch(self.base_url.format(annotation.id),
                                  put_data,
                                  content_type='application/vnd.api+json',
                                  HTTP_AUTHORIZATION=self.token_header)
     annotation = Annotation.objects.get(id=annotation.id)
     self.assertEqual(response.status_code, 403)
     self.assertNotEqual(annotation.comment, put_string)
示例#2
0
    def test_list_annotations__upvote_count(self):
        list_url = '/api/annotations'
        annotation = Annotation.objects.create(
            user=self.user,
            comment="good job",
            range='{}',
            url='http://localhost/',
            annotation_link="www.przypispowszechny.com",
            annotation_link_title="very nice")

        # No relation, no count

        response = self.client.get(list_url,
                                   HTTP_AUTHORIZATION=self.token_header)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['content-type'], 'application/vnd.api+json')
        response_content_data = json.loads(
            response.content.decode('utf8')).get('data')
        self.assertTrue(response_content_data)
        attributes = response_content_data[0].get('attributes')
        self.assertIsNotNone(attributes)
        self.assertEqual(attributes.get('upvoteCountExceptUser'), 0)
        relationships = response_content_data[0].get('relationships')
        self.assertIsNotNone(relationships)
        self.assertDictEqual(
            relationships.get('annotationUpvote'), {
                'links': {
                    'related':
                    testserver_reverse(
                        'api:annotation:annotation_related_upvote',
                        kwargs={'annotation_id': annotation.id})
                },
                'data': None
            })

        # Existing relation, no count

        urf = AnnotationUpvote.objects.create(user=self.user,
                                              annotation=annotation)

        response = self.client.get(list_url,
                                   HTTP_AUTHORIZATION=self.token_header)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['content-type'], 'application/vnd.api+json')
        response_content_data = json.loads(
            response.content.decode('utf8')).get('data')
        self.assertTrue(response_content_data)
        attributes = response_content_data[0].get('attributes')
        self.assertIsNotNone(attributes)
        self.assertEqual(attributes.get('upvoteCountExceptUser'), 0)
        relationships = response_content_data[0].get('relationships')
        self.assertIsNotNone(relationships)
        self.assertDictEqual(
            relationships.get('annotationUpvote'), {
                'links': {
                    'related':
                    testserver_reverse(
                        'api:annotation:annotation_related_upvote',
                        kwargs={'annotation_id': annotation.id})
                },
                'data': {
                    'id': str(urf.id),
                    'type': 'annotationUpvotes'
                }
            })

        # Existing relation, positive count

        other_user1, password1 = create_test_user(unique=True)
        other_user2, password2 = create_test_user(unique=True)
        AnnotationUpvote.objects.create(user=other_user1,
                                        annotation=annotation)
        AnnotationUpvote.objects.create(user=other_user2,
                                        annotation=annotation)
        upvote_count = AnnotationUpvote.objects.filter(
            annotation=annotation).exclude(user=self.user).count()

        response = self.client.get(list_url,
                                   HTTP_AUTHORIZATION=self.token_header)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['content-type'], 'application/vnd.api+json')
        response_content_data = json.loads(
            response.content.decode('utf8')).get('data')
        self.assertTrue(response_content_data)
        attributes = response_content_data[0].get('attributes')
        self.assertIsNotNone(attributes)
        self.assertEqual(attributes.get('upvoteCountExceptUser'), upvote_count)
        relationships = response_content_data[0].get('relationships')
        self.assertIsNotNone(relationships)
        self.assertDictEqual(
            relationships.get('annotationUpvote'), {
                'links': {
                    'related':
                    testserver_reverse(
                        'api:annotation:annotation_related_upvote',
                        kwargs={'annotation_id': annotation.id})
                },
                'data': {
                    'id': str(urf.id),
                    'type': 'annotationUpvotes'
                }
            })
示例#3
0
 def setUp(self):
     self.user, self.password = create_test_user()
     self.user.role = self.user.ROLE_EDITOR
     self.user.save()
     self.token = str(AccessToken.for_user(self.user))
     self.token_header = 'JWT %s' % self.token
示例#4
0
 def setUp(self):
     self.user, self.password = create_test_user()
     self.client.login(username=self.user, password=self.password)
 def setUp(self):
     self.user, self.password = create_test_user()
     self.token = str(AccessToken.for_user(self.user))
     self.token_header = 'JWT %s' % self.token
示例#6
0
 def setUp(self):
     self.user, password = create_test_user()
     self.token = str(AccessToken.for_user(self.user))
     self.token_header = 'JWT %s' % self.token
     Annotation.objects.all().update(check_status=Annotation.UNVERIFIED)