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_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 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, group_service, formatters): """ 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 # Don't sent annotations from NIPSA'd users to anyone other than that # user. if user_nipsad and socket.authenticated_userid != annotation.userid: return None notification = { "type": "annotation-notification", "options": { "action": action } } base_url = socket.registry.settings.get("h.app_url", "http://localhost:8080") links_service = LinksService(base_url, socket.registry) resource = AnnotationContext(annotation, group_service, links_service) serialized = presenters.AnnotationJSONPresenter( resource, formatters=formatters).asdict() 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": annotation.id}] return notification
def _generate_annotation_event(message, socket, annotation, user_nipsad, group_service, formatters): """ 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 # Don't sent annotations from NIPSA'd users to anyone other than that # user. if user_nipsad and socket.authenticated_userid != annotation.userid: return None # The `prepare` function sets the active registry which is an implicit # dependency of some of the authorization logic used to look up annotation # and group permissions. with pyramid.scripting.prepare(registry=socket.registry): notification = { "type": "annotation-notification", "options": { "action": action }, } base_url = socket.registry.settings.get("h.app_url", "http://localhost:5000") links_service = LinksService(base_url, socket.registry) resource = AnnotationContext(annotation, group_service, links_service) # Check whether client is authorized to read this annotation. read_principals = principals_allowed_by_permission(resource, "read") if not set(read_principals).intersection(socket.effective_principals): return None serialized = presenters.AnnotationJSONPresenter( resource, formatters=formatters).asdict() notification["payload"] = [serialized] if action == "delete": notification["payload"] = [{"id": annotation.id}] return notification
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"
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_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'