Exemple #1
0
def test_notification_follow_synthesis(test_session, discussion,
                                       participant1_user, reply_post_2,
                                       test_app, root_post_1,
                                       synthesis_post_1):
    test_session.flush()
    subscription = NotificationSubscriptionFollowSyntheses(
        discussion=discussion,
        user=participant1_user,
        creation_origin=NotificationCreationOrigin.USER_REQUESTED)
    test_session.add(subscription)

    initial_notification_count = test_session.query(Notification).count()
    dispatcher = ModelEventWatcherNotificationSubscriptionDispatcher()
    dispatcher.processPostCreated(reply_post_2.id)
    notification_count = test_session.query(Notification).count()
    assert notification_count == initial_notification_count, "The post wasn't a synthesis and shouldn't have been caught"
    initial_last_status_change_date = subscription.last_status_change_date
    subscription.status = NotificationSubscriptionStatus.UNSUBSCRIBED
    assert subscription.last_status_change_date > initial_last_status_change_date, "The last status change date should have auto-updated"
    dispatcher.processPostCreated(synthesis_post_1.id)
    notification_count = test_session.query(Notification).count()
    assert notification_count == initial_notification_count, "The synthesis shouldn't have created a notification, because the subscription is unsubscribed"
    subscription.status = NotificationSubscriptionStatus.ACTIVE
    dispatcher.processPostCreated(synthesis_post_1.id)
    notification_count = test_session.query(Notification).count()
    assert notification_count == initial_notification_count + 1, "The synthesis post should have matched and created a notification"
Exemple #2
0
def test_notification_follow_synthesis(test_session, 
        discussion, participant1_user, reply_post_2, test_app, root_post_1, synthesis_post_1):
    
    test_session.flush()
    subscription = NotificationSubscriptionFollowSyntheses(
        discussion=discussion,
        user=participant1_user,
        creation_origin = NotificationCreationOrigin.USER_REQUESTED
       )
    test_session.add(subscription)
    
    initial_notification_count = test_session.query(Notification).count() 
    dispatcher = ModelEventWatcherNotificationSubscriptionDispatcher()
    dispatcher.processPostCreated(reply_post_2.id)
    notification_count = test_session.query(Notification).count() 
    assert notification_count == initial_notification_count, "The post wasn't a synthesis and shouldn't have been caught"
    initial_last_status_change_date = subscription.last_status_change_date
    subscription.status = NotificationSubscriptionStatus.UNSUBSCRIBED
    assert subscription.last_status_change_date > initial_last_status_change_date, "The last status change date should have auto-updated"
    dispatcher.processPostCreated(synthesis_post_1.id)
    notification_count = test_session.query(Notification).count() 
    assert notification_count == initial_notification_count, "The synthesis shouldn't have created a notification, because the subscription is unsubscribed"
    subscription.status = NotificationSubscriptionStatus.ACTIVE
    dispatcher.processPostCreated(synthesis_post_1.id)
    notification_count = test_session.query(Notification).count() 
    assert notification_count == initial_notification_count + 1, "The synthesis post should have matched and created a notification"
Exemple #3
0
def test_subscribe_notification_unique_checks(test_session, discussion,
                                              participant1_user,
                                              participant2_user, reply_post_2,
                                              test_app, root_post_1,
                                              test_webrequest):
    test_session.commit()  # this is voodoo so finalizers do not crash
    test_session.flush()
    subscription = NotificationSubscriptionFollowSyntheses(
        discussion=discussion,
        user=participant1_user,
        creation_origin=NotificationCreationOrigin.USER_REQUESTED)
    test_session.add(subscription)

    # On insert
    from assembl.lib.sqla import ObjectNotUniqueError
    with pytest.raises(ValueError):
        try:
            subscription = NotificationSubscriptionFollowSyntheses(
                discussion=discussion,
                user=participant1_user,
                creation_origin=NotificationCreationOrigin.USER_REQUESTED)
            test_session.add(subscription)
            test_session.flush()

        except ObjectNotUniqueError as e:
            # this is voodoo so finalizers do not crash
            test_session.rollback()
            raise e
def test_notification_multiple_subscriptions_create_single_notification(
        test_session, discussion, participant1_user, reply_post_2, test_app,
        root_post_1, synthesis_post_1):

    test_session.flush()
    subscription = NotificationSubscriptionFollowAllMessages(
        discussion=discussion,
        user=participant1_user,
        creation_origin=NotificationCreationOrigin.USER_REQUESTED,
    )
    test_session.add(subscription)
    subscription2 = NotificationSubscriptionFollowSyntheses(
        discussion=discussion,
        user=participant1_user,
        creation_origin=NotificationCreationOrigin.USER_REQUESTED,
    )
    test_session.add(subscription2)

    initial_notification_count = test_session.query(Notification).count()
    dispatcher = ModelEventWatcherNotificationSubscriptionDispatcher()
    dispatcher.processPostCreated(synthesis_post_1.id)
    notification_count = test_session.query(Notification).count()
    assert notification_count == initial_notification_count + 1


#def test_subscribe_notification_access_control
#TODO: Check that other subscriptions are passed to process method
Exemple #5
0
def test_synthesis_notification_in_user_preferred_language_fr(
        test_session, discussion, participant1_user,
        participant1_user_language_preference_fr_cookie, test_app, root_post_1,
        synthesis_post_1):
    test_session.flush()
    subscription = NotificationSubscriptionFollowSyntheses(
        discussion=discussion,
        user=participant1_user,
        creation_origin=NotificationCreationOrigin.USER_REQUESTED)
    test_session.add(subscription)

    initial_notification_count = test_session.query(Notification).count()
    dispatcher = ModelEventWatcherNotificationSubscriptionDispatcher()

    notification_count = test_session.query(Notification).count()

    dispatcher.processPostCreated(synthesis_post_1.id)

    last_notification = participant1_user.notifications[-1]

    html_content = last_notification.render_to_email_html_part()

    assert "subject FR" in html_content
    assert "introduction FR" in html_content
    assert "conclusion FR" in html_content
Exemple #6
0
def test_subscribe_notification(test_session, discussion, participant1_user,
                                reply_post_2, test_app, root_post_1):

    test_session.flush()
    subscription = NotificationSubscriptionFollowSyntheses(
        discussion=discussion,
        user=participant1_user,
        creation_origin=NotificationCreationOrigin.USER_REQUESTED)
    test_session.add(subscription)
    test_session.flush()
Exemple #7
0
def discussion_synth_notification(request, test_session, discussion):
    """Notification Subscription on Synthesis fixture"""
    from assembl.models import (
        NotificationSubscriptionFollowSyntheses, NotificationCreationOrigin)
    u = discussion.user_templates[0]
    sns = NotificationSubscriptionFollowSyntheses(
        user=u, discussion=discussion,
        creation_origin=NotificationCreationOrigin.USER_REQUESTED)
    test_session.expire(u, ['notification_subscriptions'])

    def fin():
        print "finalizer discussion_synth_notification"
        test_session.delete(sns)
        test_session.flush()
    request.addfinalizer(fin)
    return sns