def test_add_formatter(self): presenter = AnnotationJSONPresenter(mock.Mock()) formatter = FakeFormatter() presenter.add_formatter(formatter) assert formatter in presenter.formatters
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
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'
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'