Exemplo n.º 1
0
def test_users_not_subscribed_to_discussion(test_session, discussion,
                                            participant1_user, reply_post_2,
                                            test_app, root_post_1,
                                            synthesis_post_1,
                                            discussion2_root_post_1,
                                            test_webrequest):
    test_session.flush()
    subscription = NotificationSubscriptionFollowAllMessages(
        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 + 1, "A new post should have been caught"

    # Smoke test that unsubscribing from a discussion
    # does inhibit notifications
    participant1_user.unsubscribe(discussion)
    test_session.commit()
    dispatcher.processPostCreated(reply_post_2.id)
    notification_count = test_session.query(Notification).count()
    assert notification_count == initial_notification_count + 1, "The user should NOT receive notification if not subscribed to the discussion"
    participant1_user.subscribe(discussion)
Exemplo n.º 2
0
def test_notification_follow_all_messages(test_session, discussion,
                                          participant1_user, reply_post_2,
                                          test_app, root_post_1,
                                          synthesis_post_1,
                                          discussion2_root_post_1):
    test_session.flush()
    subscription = NotificationSubscriptionFollowAllMessages(
        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 + 1, "A new post should have been caught"

    # Check that subclasses are still caught
    dispatcher.processPostCreated(synthesis_post_1.id)
    notification_count = test_session.query(Notification).count()
    assert notification_count == initial_notification_count + 2, "A post with a subclass should have been caught"

    # Smoke test that other discussion's post do not leak
    dispatcher.processPostCreated(discussion2_root_post_1.id)
    notification_count = test_session.query(Notification).count()
    assert notification_count == initial_notification_count + 2, "A post from another discussion should NOT have been caught"
Exemplo n.º 3
0
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