def test_updated_returns_none_if_missing(self): annotation = mock.Mock(updated=None) resource = mock.Mock(annotation=annotation) updated = AnnotationBasePresenter(resource).updated assert updated is None
def test_updated_returns_none_if_missing(self, fake_links_service): annotation = mock.Mock(updated=None) updated = AnnotationBasePresenter(annotation, fake_links_service).updated assert updated is None
def test_updated_uses_iso_format(self, fake_links_service): when = datetime.datetime(1983, 8, 31, 7, 18, 20, 98763) annotation = mock.Mock(updated=when) updated = AnnotationBasePresenter(annotation, fake_links_service).updated assert updated == '1983-08-31T07:18:20.098763+00:00'
def test_created_uses_iso_format(self, fake_links_service): when = datetime.datetime(2012, 3, 14, 23, 34, 47, 12) annotation = mock.Mock(created=when) created = AnnotationBasePresenter(annotation, fake_links_service).created assert created == '2012-03-14T23:34:47.000012+00:00'
def test_constructor_args(self): annotation = mock.Mock() resource = mock.Mock(annotation=annotation) presenter = AnnotationBasePresenter(resource) assert presenter.annotation_resource == resource assert presenter.annotation == annotation
def test_target_missing_selectors(self): annotation = mock.Mock(target_uri='http://example.com', target_selectors=None) resource = mock.Mock(annotation=annotation) expected = [{'source': 'http://example.com'}] actual = AnnotationBasePresenter(resource).target assert expected == actual
def test_links(self, fake_links_service): annotation = mock.Mock() links = AnnotationBasePresenter(annotation, fake_links_service).links assert links == { 'giraffe': 'http://giraffe.com', 'toad': 'http://toad.net' }
def test_target(self, fake_links_service): ann = mock.Mock( target_uri='http://example.com', target_selectors={'PositionSelector': { 'start': 0, 'end': 12 }}) expected = [{ 'source': 'http://example.com', 'selector': { 'PositionSelector': { 'start': 0, 'end': 12 } } }] actual = AnnotationBasePresenter(ann, fake_links_service).target assert expected == actual
def test_links_passes_annotation(self, fake_links_service): annotation = mock.Mock() links = AnnotationBasePresenter(annotation, fake_links_service).links assert fake_links_service.last_annotation == annotation
def test_tags(self, fake_links_service): ann = mock.Mock(tags=['interesting', 'magic']) presenter = AnnotationBasePresenter(ann, fake_links_service) assert ['interesting', 'magic'] == presenter.tags
def test_tags_missing(self): annotation = mock.Mock(tags=None) resource = mock.Mock(annotation=annotation) presenter = AnnotationBasePresenter(resource) assert [] == presenter.tags
def test_tags(self): annotation = mock.Mock(tags=['interesting', 'magic']) resource = mock.Mock(annotation=annotation) presenter = AnnotationBasePresenter(resource) assert ['interesting', 'magic'] == presenter.tags
def test_text_missing(self): annotation = mock.Mock(text=None) resource = mock.Mock(annotation=annotation) presenter = AnnotationBasePresenter(resource) assert '' == presenter.text
def test_text(self): annotation = mock.Mock(text='It is magical!') resource = mock.Mock(annotation=annotation) presenter = AnnotationBasePresenter(resource) assert 'It is magical!' == presenter.text
def test_links(self): annotation = mock.Mock() resource = mock.Mock(annotation=annotation) links = AnnotationBasePresenter(resource).links assert links == resource.links
def test_text(self, fake_links_service): ann = mock.Mock(text='It is magical!') presenter = AnnotationBasePresenter(ann, fake_links_service) assert 'It is magical!' == presenter.text
def test_text_missing(self, fake_links_service): ann = mock.Mock(text=None) presenter = AnnotationBasePresenter(ann, fake_links_service) assert '' == presenter.text
def test_target_missing_selectors(self, fake_links_service): ann = mock.Mock(target_uri='http://example.com', target_selectors=None) expected = [{'source': 'http://example.com'}] actual = AnnotationBasePresenter(ann, fake_links_service).target assert expected == actual
def test_tags_missing(self, fake_links_service): ann = mock.Mock(tags=None) presenter = AnnotationBasePresenter(ann, fake_links_service) assert [] == presenter.tags
def test_constructor_args(self, fake_links_service): annotation = mock.Mock() presenter = AnnotationBasePresenter(annotation, fake_links_service) assert presenter.annotation == annotation