示例#1
0
def get_notifications(notification_type, processed=False, not_sent=False):
    """Returns specific notifications pids.

    :param notification_type: filter on the notification type.
    :param processed: filter on already processed notifications.
    :param not_sent: filter on not yet send notifications.
    :return a notification pid generator.
    """
    query = NotificationsSearch()\
        .filter('term', notification_type=notification_type) \
        .source('pid')
    if not not_sent:
        query = query.filter('bool',
                             must_not=[
                                 Q('exists', field='notification_sent'),
                                 Q('term', notification_sent=False)
                             ])
    if processed:
        query = query.filter('exists', field='process_date')
    else:
        query = query.filter('bool',
                             must_not=[Q('exists', field='process_date')])

    for hit in query.scan():
        yield hit.pid
def test_notification_organisation_pid(
        org_martigny, notification_availability_martigny):
    """Test organisation pid has been added during the indexing."""
    search = NotificationsSearch()
    pid = notification_availability_martigny.get('pid')
    notification = next(search.filter('term', pid=pid).scan())
    assert notification.organisation.pid == org_martigny.pid

    # test notification can_delete
    assert notification_availability_martigny.get_links_to_me() == {}
    assert notification_availability_martigny.can_delete