示例#1
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'
示例#2
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)

        formatters = [IDDuplicatingFormatter()]
        presenter = AnnotationJSONPresenter(resource, formatters)

        output = presenter.asdict()

        assert output['duplicated-id'] == 'the-id'
示例#3
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'
示例#4
0
    def test_formatter_uses_annotation_resource(
        self, group_service, fake_links_service
    ):
        annotation = mock.Mock(id="the-id", extra={})
        resource = AnnotationContext(annotation, group_service, fake_links_service)

        formatters = [IDDuplicatingFormatter()]
        presenter = AnnotationJSONPresenter(resource, formatters)

        output = presenter.asdict()

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

        formatters = [
            FakeFormatter({"flagged": "nope"}),
            FakeFormatter({"nipsa": "maybe"}),
        ]
        presenter = AnnotationJSONPresenter(resource, formatters)
        presented = presenter.asdict()

        assert presented["flagged"] == "nope"
        assert presented["nipsa"] == "maybe"
示例#6
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)

        formatters = [
            FakeFormatter({'flagged': 'nope'}),
            FakeFormatter({'nipsa': 'maybe'})
        ]
        presenter = AnnotationJSONPresenter(resource, formatters)
        presented = presenter.asdict()

        assert presented['flagged'] == 'nope'
        assert presented['nipsa'] == 'maybe'
示例#7
0
    def test_immutable_formatters(self, group_service, fake_links_service):
        """Double-check we can't mutate the formatters list after the fact.

        This is an extra check just to make sure we can't accidentally change
        the constructor so that it simply aliases the list that's passed in,
        leaving us open to all kinds of mutability horrors.

        """
        ann = mock.Mock(id="the-real-id", extra={})
        resource = AnnotationContext(ann, group_service, fake_links_service)

        formatters = [FakeFormatter({"flagged": "nope"})]
        presenter = AnnotationJSONPresenter(resource, formatters)
        formatters.append(FakeFormatter({"enterprise": "synergy"}))
        presented = presenter.asdict()

        assert "enterprise" not in presented