Ejemplo n.º 1
0
    def test_copy_annotation(self):
        asset = AssetFactory(course=self.sample_course, primary_source='image')

        self.assertIsNone(asset.global_annotation(self.student_two, False))

        note = SherdNoteFactory(asset=asset,
                                author=self.student_one,
                                title='Sample Note',
                                annotation_data='{1:2}',
                                body='student one notes',
                                tags=',student_one_selection',
                                range1=0,
                                range2=1)

        params = {'asset_id': asset.id, 'annotation_id': note.id}

        url = reverse('annotation-copy-view', args=[asset.id, note.id])
        self.client.login(username=self.student_two.username, password='******')
        response = self.client.post(url,
                                    params,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        the_json = loads(response.content)

        self.assertEquals(the_json['asset']['id'], asset.id)
        self.assertNotEquals(the_json['annotation']['id'], note.id)

        self.assertEquals(response.status_code, 200)
        note = SherdNote.objects.get(author=self.student_two,
                                     title=note.title,
                                     range1=note.range1,
                                     range2=note.range2,
                                     annotation_data=note.annotation_data)
        self.assertEquals(note.tags, '')
        self.assertIsNone(note.body)
        self.assertIsNotNone(asset.global_annotation(self.student_two, False))
Ejemplo n.º 2
0
    def test_update_reference_in_string(self):
        old_asset = AssetFactory(course=self.sample_course, author=self.student_one)
        old_note = SherdNoteFactory(asset=old_asset, author=self.student_one, title="Selection", range1=43, range2=75)
        alt_note = SherdNoteFactory(
            asset=old_asset, author=self.student_one, title="Alt Selection", range1=43, range2=75
        )

        new_asset = AssetFactory(course=self.sample_course, author=self.student_one)
        new_note = SherdNoteFactory(asset=new_asset, author=self.student_one, title="Selection", range1=43, range2=75)

        text = (
            '<p><a href="/asset/%s/annotations/%s/">Selection</a>'
            '</p><p><a href="/asset/%s/annotations/%s/">Selection</a>'
            '</p><p><a href="/asset/%s/annotations/%s/">Alt Selection</a>'
            '</p><a href="/asset/%s/">Global</a></p>'
            % (old_asset.id, old_note.id, old_asset.id, old_note.id, old_asset.id, alt_note.id, old_asset.id)
        )

        new_text = new_note.update_references_in_string(text, old_note)

        citations = SherdNote.objects.references_in_string(new_text, old_note.author)
        self.assertEquals(len(citations), 4)
        self.assertEquals(citations[0].id, new_note.id)
        self.assertEquals(citations[0].asset.id, new_note.asset.id)

        self.assertEquals(citations[1].id, new_note.id)
        self.assertEquals(citations[1].asset.id, new_note.asset.id)

        self.assertEquals(citations[2].id, alt_note.id)
        self.assertEquals(citations[2].asset.id, old_asset.id)

        gann = old_asset.global_annotation(self.student_one, auto_create=False)
        self.assertEquals(citations[3].id, gann.id)
        self.assertEquals(citations[3].asset.id, old_asset.id)
Ejemplo n.º 3
0
    def test_update_reference_in_string(self):
        old_asset = AssetFactory(course=self.sample_course,
                                 author=self.student_one)
        old_note = SherdNoteFactory(asset=old_asset,
                                    author=self.student_one,
                                    title="Selection",
                                    range1=43,
                                    range2=75)
        alt_note = SherdNoteFactory(asset=old_asset,
                                    author=self.student_one,
                                    title="Alt Selection",
                                    range1=43,
                                    range2=75)

        new_asset = AssetFactory(course=self.sample_course,
                                 author=self.student_one)
        new_note = SherdNoteFactory(asset=new_asset,
                                    author=self.student_one,
                                    title="Selection",
                                    range1=43,
                                    range2=75)

        text = ('<p><a href="/asset/%s/annotations/%s/">Selection</a>'
                '</p><p><a href="/asset/%s/annotations/%s/">Selection</a>'
                '</p><p><a href="/asset/%s/annotations/%s/">Alt Selection</a>'
                '</p><a href="/asset/%s/">Global</a></p>' %
                (old_asset.id, old_note.id, old_asset.id, old_note.id,
                 old_asset.id, alt_note.id, old_asset.id))

        new_text = new_note.update_references_in_string(text, old_note)

        citations = SherdNote.objects.references_in_string(
            new_text, old_note.author)
        self.assertEquals(len(citations), 4)
        self.assertEquals(citations[0].id, new_note.id)
        self.assertEquals(citations[0].asset.id, new_note.asset.id)

        self.assertEquals(citations[1].id, new_note.id)
        self.assertEquals(citations[1].asset.id, new_note.asset.id)

        self.assertEquals(citations[2].id, alt_note.id)
        self.assertEquals(citations[2].asset.id, old_asset.id)

        gann = old_asset.global_annotation(self.student_one, auto_create=False)
        self.assertEquals(citations[3].id, gann.id)
        self.assertEquals(citations[3].asset.id, old_asset.id)
Ejemplo n.º 4
0
    def test_annotation_create_global(self):
        asset = AssetFactory(course=self.sample_course, primary_source='image')
        request = RequestFactory().post('/', {},
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.student_one
        request.course = self.sample_course
        response = annotation_create_global(request, asset.id)
        self.assertEquals(response.status_code, 200)

        ga = asset.global_annotation(self.student_one, auto_create=False)
        self.assertIsNotNone(ga)

        the_json = loads(response.content)
        self.assertEquals(the_json['asset']['id'], asset.id)
        self.assertEquals(the_json['annotation']['id'], ga.id)

        # invalid asset
        with self.assertRaises(Http404):
            annotation_create_global(request, 1234)
Ejemplo n.º 5
0
    def test_annotation_create_global(self):
        asset = AssetFactory(course=self.sample_course, primary_source='image')
        request = RequestFactory().post('/', {},
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.student_one
        request.course = self.sample_course
        response = annotation_create_global(request, asset.id)
        self.assertEquals(response.status_code, 200)

        ga = asset.global_annotation(self.student_one, auto_create=False)
        self.assertIsNotNone(ga)

        the_json = loads(response.content)
        self.assertEquals(the_json['asset']['id'], asset.id)
        self.assertEquals(the_json['annotation']['id'], ga.id)

        # invalid asset
        with self.assertRaises(Http404):
            annotation_create_global(request, 1234)