Пример #1
0
def test_generate_notifications_only_if_author_can_read_reply(Subscriptions,
                                                              render_reply_notification,
                                                              effective_principals):
    """
    If the annotation is not readable by the parent author, no notifications
    should be generated.
    """
    private_annotation = Annotation.fetch(6)
    shared_annotation = Annotation.fetch(7)
    request = _create_request()
    effective_principals.return_value = [
        security.Everyone,
        security.Authenticated,
        'acct:[email protected]',
        'group:wibble',
    ]
    Subscriptions.get_active_subscriptions_for_a_type.return_value = [
        MockSubscription(id=1, uri='acct:[email protected]')
    ]
    render_reply_notification.return_value = (
        'Dummy subject',
        'Dummy text',
        'Dummy HTML',
        ['*****@*****.**']
    )

    notifications = rt.generate_notifications(request, private_annotation, 'create')
    assert list(notifications) == []

    notifications = rt.generate_notifications(request, shared_annotation, 'create')
    assert list(notifications) != []
Пример #2
0
def parent_values(annotation):
    if 'references' in annotation:
        parent = Annotation.fetch(annotation['references'][-1])
        if 'references' in parent:
            grandparent = Annotation.fetch(parent['references'][-1])
            parent['quote'] = grandparent['text']
        return parent
    else:
        return {}
Пример #3
0
def parent_values(annotation):
    if 'references' in annotation:
        parent = Annotation.fetch(annotation['references'][-1])
        if 'references' in parent:
            grandparent = Annotation.fetch(parent['references'][-1])
            parent['quote'] = grandparent['text']
        return parent
    else:
        return {}
Пример #4
0
def test_generate_notifications_empty_if_annotation_has_no_parent():
    """If the annotation has no parent no notifications should be generated."""
    annotation = Annotation.fetch(0)
    request = DummyRequest()

    notifications = rt.generate_notifications(request, annotation, 'create')

    assert list(notifications) == []
Пример #5
0
    def __getitem__(self, key):
        annotation = Annotation.fetch(key)
        if annotation is None:
            raise KeyError(key)
        annotation.__name__ = key
        annotation.__parent__ = self

        return annotation
Пример #6
0
def test_generate_notifications_checks_subscriptions(Subscriptions):
    """If the annotation has a parent, then proceed to check subscriptions."""
    request = _create_request()
    annotation = Annotation.fetch(1)
    Subscriptions.get_active_subscriptions_for_a_type.return_value = []

    notifications = rt.generate_notifications(request, annotation, "create")

    # Read the generator
    list(notifications)

    Subscriptions.get_active_subscriptions_for_a_type.assert_called_with(REPLY_TYPE)
Пример #7
0
def test_generate_notifications_checks_subscriptions(Subscriptions):
    """If the annotation has a parent, then proceed to check subscriptions."""
    request = _create_request()
    annotation = Annotation.fetch(1)
    Subscriptions.get_active_subscriptions_for_a_type.return_value = []

    notifications = rt.generate_notifications(request, annotation, 'create')

    # Read the generator
    list(notifications)

    Subscriptions.get_active_subscriptions_for_a_type.assert_called_with(
        REPLY_TYPE)
Пример #8
0
def test_check_conditions_false_stops_sending():
    """If the check conditions() returns False, no notifications are generated"""
    request = _create_request()

    annotation = Annotation.fetch(1)
    with patch('h.notification.reply_template.Subscriptions') as mock_subs:
        mock_subs.get_active_subscriptions_for_a_type.return_value = [
            MockSubscription(id=1, uri='acct:[email protected]')
        ]
        with patch('h.notification.reply_template.check_conditions') as mock_conditions:
            mock_conditions.return_value = False
            with pytest.raises(StopIteration):
                msgs = rt.generate_notifications(request, annotation, 'create')
                msgs.next()
Пример #9
0
def test_send_if_everything_is_okay():
    """Test whether we generate notifications if every condition is okay"""
    request = _create_request()

    annotation = Annotation.fetch(1)
    with patch('h.notification.reply_template.Subscriptions') as mock_subs:
        mock_subs.get_active_subscriptions_for_a_type.return_value = [
            MockSubscription(id=1, uri='acct:[email protected]')
        ]
        with patch('h.notification.reply_template.check_conditions') as mock_conditions:
            mock_conditions.return_value = True
            with patch('h.notification.reply_template.render') as mock_render:
                mock_render.return_value = ''
                with patch('h.notification.reply_template.get_user_by_name') as mock_user_db:
                    user = Mock()
                    user.email = '*****@*****.**'
                    mock_user_db.return_value = user
                    msgs = rt.generate_notifications(request, annotation, 'create')
                    msgs.next()
Пример #10
0
def parent_values(annotation):
    if 'references' in annotation:
        parent = Annotation.fetch(annotation['references'][-1])
        return parent
    else:
        return {}
Пример #11
0
def parent_values(annotation):
    if 'references' in annotation:
        parent = Annotation.fetch(annotation['references'][-1])
        return parent
    else:
        return {}