Ejemplo n.º 1
0
def read_jsonld(annotation, request):
    request.response.content_type = 'application/ld+json'
    request.response.content_type_params = {
        'profile': AnnotationJSONLDPresenter.CONTEXT_URL
    }
    presenter = AnnotationJSONLDPresenter(request, annotation)
    return presenter.asdict()
Ejemplo n.º 2
0
    def test_id_returns_annotation_url(self):
        request = DummyRequest()
        annotation = mock.Mock(id='foobar')

        presenter = AnnotationJSONLDPresenter(request, annotation)

        assert presenter.id == 'http://example.com/ann/foobar'
Ejemplo n.º 3
0
    def test_bodies_returns_textual_body(self):
        request = DummyRequest()
        annotation = mock.Mock(text='Flib flob flab', tags=None)

        bodies = AnnotationJSONLDPresenter(request, annotation).bodies

        assert bodies == [{
            'type': 'TextualBody',
            'text': 'Flib flob flab',
            'format': 'text/markdown',
        }]
Ejemplo n.º 4
0
    def test_bodies_appends_tag_bodies(self):
        request = DummyRequest()
        annotation = mock.Mock(text='Flib flob flab', tags=['giraffe', 'lion'])

        bodies = AnnotationJSONLDPresenter(request, annotation).bodies

        assert {
            'type': 'TextualBody',
            'text': 'giraffe',
            'purpose': 'tagging',
        } in bodies
        assert {
            'type': 'TextualBody',
            'text': 'lion',
            'purpose': 'tagging',
        } in bodies
Ejemplo n.º 5
0
    def test_asdict(self):
        request = DummyRequest()
        annotation = mock.Mock(
            id='foobar',
            created=datetime.datetime(2016, 2, 24, 18, 3, 25, 768),
            updated=datetime.datetime(2016, 2, 29, 10, 24, 5, 564),
            userid='acct:luke',
            target_uri='http://example.com',
            text='It is magical!',
            tags=['magic'],
            target_selectors=[{
                'TestSelector': 'foobar'
            }])
        expected = {
            '@context':
            'http://www.w3.org/ns/anno.jsonld',
            'type':
            'Annotation',
            'id':
            'http://example.com/ann/foobar',
            'created':
            '2016-02-24T18:03:25.000768+00:00',
            'modified':
            '2016-02-29T10:24:05.000564+00:00',
            'creator':
            'acct:luke',
            'body': [{
                'type': 'TextualBody',
                'format': 'text/markdown',
                'text': 'It is magical!'
            }, {
                'type': 'TextualBody',
                'purpose': 'tagging',
                'text': 'magic'
            }],
            'target': [{
                'source': 'http://example.com',
                'selector': [{
                    'TestSelector': 'foobar'
                }]
            }]
        }

        result = AnnotationJSONLDPresenter(request, annotation).asdict()

        assert result == expected
Ejemplo n.º 6
0
Archivo: views.py Proyecto: djcun95/h
def read_jsonld(annotation, request):
    request.response.content_type = 'application/ld+json'
    request.response.content_type_params = {
        'profile': AnnotationJSONLDPresenter.CONTEXT_URL}
    presenter = AnnotationJSONLDPresenter(request, annotation)
    return presenter.asdict()