Пример #1
0
def test_query_mismatch():
    """Make sure that the lack of matching prevents calling
    the AnnotationNotifier"""
    annotation = {
        'permissions': {
            'read': ["group:__world__"]
        },
        'parent': {
            'user': '******'
        },
        'user': '******'
    }
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, 'create')
    with patch('h.notifier.AnnotationNotifier') as mock_notif:
        with patch('h.auth.local.models.UserSubscriptions') as mock_subs:
            with patch('h.notifier.FilterHandler') as mock_filter:
                query = QueryMock(active=True)
                als = Mock()
                als.all = Mock(return_value=[query])
                mock_subs.get_all = Mock(return_value=als)

                mock_filter().match = Mock(return_value=False)
                notifier.send_notifications(event)
                actual = mock_notif().send_notification_to_owner.call_count
                assert actual == 0
Пример #2
0
def test_authorization():
    """Make sure private annotations don't send notifications
    """
    annotation = {"permissions": {"read": ["acct:[email protected]"]}}
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, "create")

    with patch("h.notifier.AnnotationNotifier") as mock:
        notifier.send_notifications(event)
        assert mock.call_count == 0
Пример #3
0
def test_authorization():
    """Make sure private annotations don't send notifications
    """
    annotation = {'permissions': {'read': ['acct:[email protected]']}}
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, 'create')

    with patch('h.notifier.AnnotationNotifier') as mock:
        notifier.send_notifications(event)
        assert mock.call_count == 0
Пример #4
0
def test_authorization():
    """Make sure private annotations don't send notifications
    """
    annotation = {'permissions': {'read': ['acct:[email protected]']}}
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, 'create')

    with patch('h.notifier.AnnotationNotifier') as mock:
        notifier.send_notifications(event)
        assert mock.call_count == 0
Пример #5
0
def test_passive_queries():
    """Make sure if a query is passive the notifier system
    does not get called"""
    annotation = {"permissions": {"read": ["group:__world__"]}}
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, "create")

    with patch("h.notifier.AnnotationNotifier") as mock_notif:
        with patch("h.auth.local.models.UserSubscriptions.get_all") as mock_subscription:
            query = QueryMock()
            mock_subscription.all = Mock(return_value=[query])
            mock_notif().send_notification_to_owner = Mock()
            notifier.send_notifications(event)
            assert mock_notif().send_notification_to_owner.call_count == 0
Пример #6
0
def test_reply_update():
    """Should not do anything if the action is update"""
    annotation = {
        'user': '******',
        'permissions': {'read': ["group:__world__"]}
    }
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, 'update')

    with patch('h.notifier.AnnotationNotifier') as mock_notif:
        with patch('h.notifier.parent_values') as mock_parent:
            mock_parent.return_value = {}
            notifier.send_notifications(event)
            assert mock_notif().send_notification_to_owner.call_count == 0
Пример #7
0
def test_no_parent_user():
    """Should not throw or send annotation if the parent user is missing"""
    annotation = {
        'user': '******',
        'permissions': {'read': ["group:__world__"]}
    }
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, 'create')

    with patch('h.notifier.AnnotationNotifier') as mock_notif:
        with patch('h.notifier.parent_values') as mock_parent:
            mock_parent.return_value = {}
            notifier.send_notifications(event)
            assert mock_notif().send_notification_to_owner.call_count == 0
Пример #8
0
def test_reply_same_creator():
    """Username same, domain same -> should not send reply"""
    annotation = {
        'user': '******',
        'permissions': {'read': ["group:__world__"]}
    }
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, 'create')

    with patch('h.notifier.AnnotationNotifier') as mock_notif:
        with patch('h.notifier.parent_values') as mock_parent:
            mock_parent.return_value = {'user': '******'}
            notifier.send_notifications(event)
            assert mock_notif().send_notification_to_owner.call_count == 0
Пример #9
0
def test_reply_query_match():
    """Test if the notifier.send_notifications is called
    """
    annotation = {
        'user': '******',
        'permissions': {'read': ["group:__world__"]}
    }
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, 'create')

    with patch('h.notifier.AnnotationNotifier') as mock_notif:
        with patch('h.notifier.parent_values') as mock_parent:
            mock_parent.return_value = {'user': '******'}
            notifier.send_notifications(event)
            assert mock_notif().send_notification_to_owner.call_count == 1
Пример #10
0
def test_passive_queries():
    """Make sure if a query is passive the notifier system
    does not get called"""
    annotation = {'permissions': {'read': ["group:__world__"]}}
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, 'create')

    with patch('h.notifier.AnnotationNotifier') as mock_notif:
        with patch('h.auth.local.models.UserSubscriptions.get_all') \
                as mock_subscription:
            query = QueryMock()
            mock_subscription.all = Mock(return_value=[query])
            mock_notif().send_notification_to_owner = Mock()
            notifier.send_notifications(event)
            assert mock_notif().send_notification_to_owner.call_count == 0
Пример #11
0
def test_query_matches():
    """Make sure that the query match triggers the notifier call"""
    annotation = {
        "permissions": {"read": ["group:__world__"]},
        "parent": {"user": "******"},
        "user": "******",
    }
    request = DummyRequest()
    event = events.AnnotationEvent(request, annotation, "create")
    with patch("h.notifier.AnnotationNotifier") as mock_notif:
        with patch("h.auth.local.models.UserSubscriptions") as mock_subs:
            with patch("h.notifier.FilterHandler") as mock_filter:
                query = QueryMock(active=True)
                als = Mock()
                als.all = Mock(return_value=[query])
                mock_subs.get_all = Mock(return_value=als)

                mock_filter().match = Mock(return_value=True)
                notifier.send_notifications(event)
                actual = mock_notif().send_notification_to_owner.call_count
                assert actual == 1