示例#1
0
    def test_add_formatter(self):
        presenter = AnnotationJSONPresenter(mock.Mock())

        formatter = FakeFormatter()

        presenter.add_formatter(formatter)
        assert formatter in presenter.formatters
示例#2
0
    def test_add_formatter_raises_for_wrong_formatter_type(self):
        presenter = AnnotationJSONPresenter(mock.Mock())

        formatter = mock.Mock()

        with pytest.raises(ValueError) as exc:
            presenter.add_formatter(formatter)

        assert 'not implementing IAnnotationFormatter interface' in exc.value.message
示例#3
0
    def test_formatter_uses_annotation_resource(self, group_service, fake_links_service):
        annotation = mock.Mock(id='the-id', extra={})
        resource = AnnotationResource(annotation, group_service, fake_links_service)

        presenter = AnnotationJSONPresenter(resource)
        presenter.add_formatter(IDDuplicatingFormatter())

        output = presenter.asdict()

        assert output['duplicated-id'] == 'the-id'
示例#4
0
    def test_asdict_merges_formatters(self, group_service, fake_links_service):
        ann = mock.Mock(id='the-real-id', extra={})
        resource = AnnotationResource(ann, group_service, fake_links_service)

        presenter = AnnotationJSONPresenter(resource)
        presenter.add_formatter(FakeFormatter({'flagged': 'nope'}))
        presenter.add_formatter(FakeFormatter({'nipsa': 'maybe'}))
        presented = presenter.asdict()

        assert presented['flagged'] == 'nope'
        assert presented['nipsa'] == 'maybe'