def test_get_all_includes_nonhidden_links(self, registry): svc = LinksService(base_url='http://example.com', registry=registry) result = svc.get_all(mock.sentinel.annotation) assert result['giraffe'] == 'http://giraffes.com' assert result['elephant'] == 'https://elephant.org'
def test_get_passes_generators_annotation(self, registry): annotation = mock.Mock(id=12345) svc = LinksService(base_url='http://example.com', registry=registry) result = svc.get(annotation, 'paramroute') assert result == 'http://example.com/annotations/12345'
def _generate_annotation_event(message, socket, annotation, user_nipsad): """ Get message about annotation event `message` to be sent to `socket`. Inspects the embedded annotation event and decides whether or not the passed socket should receive notification of the event. Returns None if the socket should not receive any message about this annotation event, otherwise a dict containing information about the event. """ action = message['action'] if action == 'read': return None if message['src_client_id'] == socket.client_id: return None # We don't send anything until we have received a filter from the client if socket.filter is None: return None notification = { 'type': 'annotation-notification', 'options': { 'action': action }, } id_ = message['annotation_id'] # Return early when action is delete serialized = None if action == 'delete': serialized = message['annotation_dict'] else: if annotation is None: return None base_url = socket.registry.settings.get('h.app_url', 'http://localhost:5000') links_service = LinksService(base_url, socket.registry) serialized = presenters.AnnotationJSONPresenter( annotation, links_service).asdict() userid = serialized.get('user') if user_nipsad and socket.authenticated_userid != userid: return None permissions = serialized.get('permissions') if not _authorized_to_read(socket.effective_principals, permissions): return None if not socket.filter.match(serialized, action): return None notification['payload'] = [serialized] if action == 'delete': notification['payload'] = [{'id': id_}] return notification
def test_get_all_does_not_include_links_returning_none(self, registry): svc = LinksService(base_url='http://example.com', registry=registry) result = svc.get_all(mock.sentinel.annotation) assert 'returnsnone' not in result
def test_get_all_does_not_include_hidden_links(self, registry): svc = LinksService(base_url='http://example.com', registry=registry) result = svc.get_all(mock.sentinel.annotation) assert 'kiwi' not in result
def test_get_passes_generators_request_with_base_url(self, registry): svc = LinksService(base_url='http://donkeys.com', registry=registry) result = svc.get(mock.sentinel.annotation, 'namedroute') assert result == 'http://donkeys.com/some/path'
def test_get_returns_link_text_for_hidden_links(self, registry): svc = LinksService(base_url='http://example.com', registry=registry) result = svc.get(mock.sentinel.annotation, 'kiwi') assert result == 'http://kiwi.net'
def test_get_returns_link_text(self, registry): svc = LinksService(base_url='http://example.com', registry=registry) result = svc.get(mock.sentinel.annotation, 'giraffe') assert result == 'http://giraffes.com'