コード例 #1
0
    def test_it_renders_replies(self, links_service, pyramid_request,
                                search_run, factories, group_service):
        ann = AnnotationResource(factories.Annotation(userid='luke'),
                                 group_service, links_service)
        reply1 = AnnotationResource(
            factories.Annotation(userid='sarah',
                                 references=[ann.annotation.id]),
            group_service, links_service)
        reply2 = AnnotationResource(
            factories.Annotation(userid='sarah',
                                 references=[ann.annotation.id]),
            group_service, links_service)

        search_run.return_value = SearchResult(
            1, [ann.annotation.id],
            [reply1.annotation.id, reply2.annotation.id], {})

        pyramid_request.params = {'_separate_replies': '1'}

        expected = {
            'total':
            1,
            'rows': [presenters.AnnotationJSONPresenter(ann).asdict()],
            'replies': [
                presenters.AnnotationJSONPresenter(reply1).asdict(),
                presenters.AnnotationJSONPresenter(reply2).asdict(),
            ]
        }

        assert views.search(pyramid_request) == expected
コード例 #2
0
ファイル: views_test.py プロジェクト: zermelozf/h
    def test_it_renders_replies(self, links_service, pyramid_request,
                                search_run):
        ann = models.Annotation(userid='luke')
        pyramid_request.db.add(ann)
        pyramid_request.db.flush()
        reply1 = models.Annotation(userid='sarah', references=[ann.id])
        reply2 = models.Annotation(userid='sarah', references=[ann.id])
        pyramid_request.db.add_all([reply1, reply2])
        pyramid_request.db.flush()

        search_run.return_value = SearchResult(1, [ann.id],
                                               [reply1.id, reply2.id], {})

        pyramid_request.params = {'_separate_replies': '1'}

        expected = {
            'total':
            1,
            'rows':
            [presenters.AnnotationJSONPresenter(ann, links_service).asdict()],
            'replies': [
                presenters.AnnotationJSONPresenter(reply1,
                                                   links_service).asdict(),
                presenters.AnnotationJSONPresenter(reply2,
                                                   links_service).asdict(),
            ]
        }

        assert views.search(pyramid_request) == expected
コード例 #3
0
ファイル: views_test.py プロジェクト: fangang123/h
    def test_it_renders_search_results(self, links_service, pyramid_request, search_run, factories):
        ann1 = factories.Annotation(userid='luke')
        ann2 = factories.Annotation(userid='sarah')

        search_run.return_value = SearchResult(2, [ann1.id, ann2.id], [], {})

        expected = {
            'total': 2,
            'rows': [
                presenters.AnnotationJSONPresenter(ann1, links_service).asdict(),
                presenters.AnnotationJSONPresenter(ann2, links_service).asdict(),
            ]
        }

        assert views.search(pyramid_request) == expected
コード例 #4
0
ファイル: messages.py プロジェクト: tetratorus/h
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