Пример #1
0
def test_handle_annotation_event_none_if_action_is_read():
    """Should return None if the message action is 'read'."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'read',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert streamer.handle_annotation_event(message, socket) is None
Пример #2
0
def test_handle_annotation_event_none_for_sender_socket():
    """Should return None if the socket's client_id matches the message's."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('pigeon')

    assert streamer.handle_annotation_event(message, socket) is None
Пример #3
0
def test_handle_annotation_event_none_for_sender_socket():
    """Should return None if the socket's client_id matches the message's."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('pigeon')

    assert streamer.handle_annotation_event(message, socket) is None
Пример #4
0
def test_handle_annotation_event_none_if_action_is_read():
    """Should return None if the message action is 'read'."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'read',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert streamer.handle_annotation_event(message, socket) is None
Пример #5
0
def test_handle_annotation_event_none_if_filter_does_not_match():
    """Should return None if the socket filter doesn't match the message."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.filter.match.return_value = False

    assert streamer.handle_annotation_event(message, socket) is None
Пример #6
0
def test_handle_annotation_event_none_if_filter_does_not_match():
    """Should return None if the socket filter doesn't match the message."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.filter.match.return_value = False

    assert streamer.handle_annotation_event(message, socket) is None
Пример #7
0
def test_handle_annotation_event_none_if_no_socket_filter():
    """Should return None if the socket has no filter."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.filter = None

    assert streamer.handle_annotation_event(message, socket) is None
Пример #8
0
def test_handle_annotation_event_none_if_no_socket_filter():
    """Should return None if the socket has no filter."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.filter = None

    assert streamer.handle_annotation_event(message, socket) is None
Пример #9
0
def test_handle_annotation_event_annotation_notification_format():
    """Check the format of the returned notification in the happy case."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert streamer.handle_annotation_event(message, socket) == {
        'payload': [message['annotation']],
        'type': 'annotation-notification',
        'options': {'action': 'update'},
    }
Пример #10
0
def test_handle_annotation_event_none_if_annotation_nipsad():
    """Should return None if the annotation is from a NIPSA'd user."""
    message = {
        'annotation': {
            'user': '******',
            'nipsa': True,
            'permissions': {'read': ['group:__world__']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert streamer.handle_annotation_event(message, socket) is None
Пример #11
0
def test_handle_annotation_event_sends_if_in_group():
    """Users should see annotations in groups they are members of."""
    message = {
        'annotation': {
            'user': '******',
            'permissions': {'read': ['group:private-group']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.effective_principals = ['fred', 'group:private-group']

    assert streamer.handle_annotation_event(message, socket) is not None
Пример #12
0
def test_handle_annotation_event_sends_if_in_group():
    """Users should see annotations in groups they are members of."""
    message = {
        'annotation': {
            'user': '******',
            'permissions': {'read': ['group:private-group']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.effective_principals = ['fred', 'group:private-group']

    assert streamer.handle_annotation_event(message, socket) is not None
Пример #13
0
def test_handle_annotation_event_annotation_notification_format():
    """Check the format of the returned notification in the happy case."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert streamer.handle_annotation_event(message, socket) == {
        'payload': [message['annotation']],
        'type': 'annotation-notification',
        'options': {'action': 'update'},
    }
Пример #14
0
def test_handle_annotation_event_none_if_annotation_nipsad():
    """Should return None if the annotation is from a NIPSA'd user."""
    message = {
        'annotation': {
            'user': '******',
            'nipsa': True,
            'permissions': {'read': ['group:__world__']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert streamer.handle_annotation_event(message, socket) is None
Пример #15
0
def test_handle_annotation_event_sends_nipsad_annotations_to_owners():
    """NIPSA'd users should see their own annotations."""
    message = {
        'annotation': {
            'user': '******',
            'nipsa': True,
            'permissions': {'read': ['group:__world__']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.authenticated_userid = 'fred'

    assert streamer.handle_annotation_event(message, socket) is not None
Пример #16
0
def test_handle_annotation_event_sends_nipsad_annotations_to_owners():
    """NIPSA'd users should see their own annotations."""
    message = {
        'annotation': {
            'user': '******',
            'nipsa': True,
            'permissions': {'read': ['group:__world__']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.authenticated_userid = 'fred'

    assert streamer.handle_annotation_event(message, socket) is not None
Пример #17
0
def test_handle_annotation_event_sends_if_annotation_public():
    """
    Everyone should see annotations which are public.

    When logged-out, effective principals contains only
    `pyramid.security.Everyone`. This test ensures that the system
    principal is correctly equated with the annotation principal
    'group:__world__', ensuring that everyone (including logged-out users)
    receives all public annotations.
    """
    message = {
        'annotation': {
            'user': '******',
            'permissions': {'read': ['group:__world__']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.effective_principals = [security.Everyone]

    assert streamer.handle_annotation_event(message, socket) is not None