Beispiel #1
0
    def test_asdict(self, DocumentSearchIndexPresenter):
        annotation = mock.Mock(
            id='xyz123',
            created=datetime.datetime(2016, 2, 24, 18, 3, 25, 768),
            updated=datetime.datetime(2016, 2, 29, 10, 24, 5, 564),
            userid='acct:[email protected]',
            target_uri='http://example.com',
            target_uri_normalized='http://example.com/normalized',
            text='It is magical!',
            tags=['magic'],
            groupid='__world__',
            shared=True,
            target_selectors=[{
                'TestSelector': 'foobar'
            }],
            references=['referenced-id-1', 'referenced-id-2'],
            extra={
                'extra-1': 'foo',
                'extra-2': 'bar'
            })
        DocumentSearchIndexPresenter.return_value.asdict.return_value = {
            'foo': 'bar'
        }

        annotation_dict = AnnotationSearchIndexPresenter(annotation).asdict()

        assert annotation_dict == {
            'id':
            'xyz123',
            'created':
            '2016-02-24T18:03:25.000768+00:00',
            'updated':
            '2016-02-29T10:24:05.000564+00:00',
            'user':
            '******',
            'user_raw':
            'acct:[email protected]',
            'uri':
            'http://example.com',
            'text':
            'It is magical!',
            'tags': ['magic'],
            'tags_raw': ['magic'],
            'group':
            '__world__',
            'shared':
            True,
            'target': [{
                'scope': ['http://example.com/normalized'],
                'source': 'http://example.com',
                'selector': [{
                    'TestSelector': 'foobar'
                }]
            }],
            'document': {
                'foo': 'bar'
            },
            'references': ['referenced-id-1', 'referenced-id-2'],
        }
Beispiel #2
0
    def test_it_copies_target_uri_normalized_to_target_scope(self):
        annotation = mock.Mock(
            target_uri_normalized='http://example.com/normalized', extra={})

        annotation_dict = AnnotationSearchIndexPresenter(annotation).asdict()

        assert annotation_dict['target'][0]['scope'] == [
            'http://example.com/normalized'
        ]
Beispiel #3
0
    def test_asdict_does_not_modify_extra(self):
        extra = {'foo': 'bar'}
        annotation = mock.Mock(id='my-id', extra=extra)

        AnnotationSearchIndexPresenter(annotation).asdict()

        assert extra == {
            'foo': 'bar'
        }, ("Presenting the annotation shouldn't change the 'extra' dict")
Beispiel #4
0
    def test_permissions(self, annotation, action, expected):
        presenter = AnnotationSearchIndexPresenter(annotation)

        assert expected == presenter.permissions[action]
Beispiel #5
0
    def test_asdict_extra_cannot_override_other_data(self):
        annotation = mock.Mock(id='the-real-id', extra={'id': 'the-extra-id'})

        annotation_dict = AnnotationSearchIndexPresenter(annotation).asdict()

        assert annotation_dict['id'] == 'the-real-id'