Example #1
0
    def test_updated_returns_none_if_missing(self):
        request = DummyRequest()
        annotation = mock.Mock(updated=None)

        updated = AnnotationBasePresenter(request, annotation).updated

        assert updated is None
Example #2
0
    def test_links_empty(self):
        request = DummyRequest()
        annotation = mock.Mock()

        links = AnnotationBasePresenter(request, annotation).links

        assert links == {}
Example #3
0
    def test_updated_uses_iso_format(self):
        request = DummyRequest()
        when = datetime.datetime(1983, 8, 31, 7, 18, 20, 98763)
        annotation = mock.Mock(updated=when)

        updated = AnnotationBasePresenter(request, annotation).updated

        assert updated == '1983-08-31T07:18:20.098763+00:00'
Example #4
0
    def test_created_uses_iso_format(self):
        request = DummyRequest()
        when = datetime.datetime(2012, 3, 14, 23, 34, 47, 12)
        annotation = mock.Mock(created=when)

        created = AnnotationBasePresenter(request, annotation).created

        assert created == '2012-03-14T23:34:47.000012+00:00'
Example #5
0
    def test_constructor_args(self):
        request = DummyRequest()
        annotation = mock.Mock()

        presenter = AnnotationBasePresenter(request, annotation)

        assert presenter.request == request
        assert presenter.annotation == annotation
Example #6
0
    def test_links_includes_registered_links(self):
        request = DummyRequest()
        annotation = mock.Mock()
        add_annotation_link_generator(request.registry, 'giraffe',
                                      lambda r, a: 'http://foo.com/bar/123')

        links = AnnotationBasePresenter(request, annotation).links

        assert links == {'giraffe': 'http://foo.com/bar/123'}
Example #7
0
    def test_link_generators_called_with_request_and_annotation(self):
        request = DummyRequest()
        annotation = mock.Mock()
        dummy_link_generator = mock.Mock(return_value='')
        add_annotation_link_generator(request.registry, 'giraffe',
                                      dummy_link_generator)

        links = AnnotationBasePresenter(request, annotation).links

        dummy_link_generator.assert_called_once_with(request, annotation)
Example #8
0
    def test_links_omits_link_generators_that_return_none(self):
        request = DummyRequest()
        annotation = mock.Mock()
        add_annotation_link_generator(request.registry, 'giraffe',
                                      lambda r, a: 'http://foo.com/bar/123')
        add_annotation_link_generator(request.registry, 'donkey',
                                      lambda r, a: None)

        links = AnnotationBasePresenter(request, annotation).links

        assert links == {'giraffe': 'http://foo.com/bar/123'}
Example #9
0
    def test_tags_missing(self):
        request = DummyRequest()
        ann = mock.Mock(tags=None)
        presenter = AnnotationBasePresenter(request, ann)

        assert [] == presenter.tags
Example #10
0
    def test_tags(self):
        request = DummyRequest()
        ann = mock.Mock(tags=['interesting', 'magic'])
        presenter = AnnotationBasePresenter(request, ann)

        assert ['interesting', 'magic'] == presenter.tags
Example #11
0
    def test_text_missing(self):
        request = DummyRequest()
        ann = mock.Mock(text=None)
        presenter = AnnotationBasePresenter(request, ann)

        assert '' == presenter.text
Example #12
0
    def test_text(self):
        request = DummyRequest()
        ann = mock.Mock(text='It is magical!')
        presenter = AnnotationBasePresenter(request, ann)

        assert 'It is magical!' == presenter.text