Exemplo n.º 1
0
def test_notification_updates_with_unique_id(client, app):
    get_resource_service('notifications').post([notification])
    old_notifications = get_user_notifications(ObjectId(user))
    app.data.update('notifications', '{}_Foo'.format(user),
                    {'created': utcnow() - datetime.timedelta(hours=1)},
                    old_notifications[0])
    old_notifications = get_user_notifications(ObjectId(user))
    app.config['NOTIFICATIONS_TTL'] = 1
    old_created = old_notifications[0]['created']
    assert len(old_notifications) == 1
    assert old_notifications[0]['_id'] == '{}_Foo'.format(user)
    get_resource_service('notifications').post([notification])
    notifications = get_user_notifications(ObjectId(user))
    new_created = notifications[0]['created']
    assert len(notifications) == 1
    assert old_created != new_created
Exemplo n.º 2
0
def test_watched_event_sends_notification_for_unpost_event(
        client, app, mocker):
    event = deepcopy(test_event)
    set_watch_products(app)
    post_json(client, '/push', event)

    with client.session_transaction() as session:
        session['user'] = PUBLIC_USER_ID
        session['user_type'] = 'public'

    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update the event for unpost
    event['pubstatus'] = 'cancelled'
    event['state'] = 'cancelled'

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', event)
    notifications = get_user_notifications(PUBLIC_USER_ID)

    assert len(outbox) == 1
    assert 'Subject: Event cancelled' in str(outbox[0])
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 1
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_foo'.format(PUBLIC_USER_ID)
Exemplo n.º 3
0
def test_watched_event_sends_notification_for_cancelled_planning(
        client, app, mocker):
    event = deepcopy(test_event)
    planning = deepcopy(test_planning)
    set_watch_products(app)
    post_json(client, '/push', event)
    post_json(client, '/push', planning)

    with client.session_transaction() as session:
        session['user'] = PUBLIC_USER_ID
        session['user_type'] = 'public'

    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update the planning for cancel
    planning['pubstatus'] = 'cancelled'
    planning['state'] = 'cancelled'

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', planning)
    notifications = get_user_notifications(PUBLIC_USER_ID)

    assert len(outbox) == 0
    assert len(notifications) == 0
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 0
Exemplo n.º 4
0
def test_watched_event_sends_notification_for_cancelled_planning(
        client, app, mocker):
    event = deepcopy(test_event)
    planning = deepcopy(test_planning)
    post_json(client, '/push', event)
    post_json(client, '/push', planning)
    user_id = assign_active_company(app)
    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update the planning for cancel
    planning['pubstatus'] = 'cancelled'
    planning['state'] = 'cancelled'

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', planning)
    notifications = get_user_notifications(user_id)

    assert len(outbox) == 1
    assert 'Subject: Planning cancelled' in str(outbox[0])
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 1
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_foo'.format(user_id)
Exemplo n.º 5
0
def test_watched_event_sends_notification_for_event_update(
        client, app, mocker):
    event = deepcopy(test_event)
    post_json(client, '/push', event)
    set_watch_products(app)

    with client.session_transaction() as session:
        session['user'] = PUBLIC_USER_ID
        session['user_type'] = 'public'

    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update comes in
    event['state'] = 'rescheduled'
    event['dates'] = {
        'start': '2018-05-27T08:00:00+0000',
        'end': '2018-06-30T09:00:00+0000',
        'tz': 'Australia/Sydney'
    }

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', event)
    notifications = get_user_notifications(PUBLIC_USER_ID)

    assert len(outbox) == 1
    assert 'Subject: Event updated' in str(outbox[0])
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 1
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_foo'.format(PUBLIC_USER_ID)
Exemplo n.º 6
0
def test_watched_event_sends_notification_for_cancelled_planning(
        client, app, mocker):
    event = deepcopy(test_event)
    planning = deepcopy(test_planning)
    post_json(client, '/push', event)
    post_json(client, '/push', planning)
    user_id = assign_active_company(app)
    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update the planning for cancel
    planning['pubstatus'] = 'cancelled'
    planning['state'] = 'cancelled'

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', planning)
    notifications = get_user_notifications(user_id)

    assert len(outbox) == 1
    assert 'Subject: Prime minister press conference - Coverage updated' in str(
        outbox[0])
    assert '! Text coverage \'Vivid Text Explainer\' has been cancelled.\r\nNote: ed note here' in str(
        outbox[0])
    assert '! Picture coverage \'Vivid Photos\' has been cancelled.\r\nNote: ed note here' in str(
        outbox[0])
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 1
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_foo'.format(user_id)
Exemplo n.º 7
0
def test_watched_event_sends_notification_for_added_planning(
        client, app, mocker):
    event = deepcopy(test_event)
    post_json(client, '/push', event)
    user_id = assign_active_company(app)
    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # planning comes in
    planning = deepcopy(test_planning)

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', planning)
    notifications = get_user_notifications(user_id)

    assert len(outbox) == 1
    assert 'Subject: Prime minister press conference - Coverage updated' in str(
        outbox[0])
    assert 'The event you have been following has new coverage(s)' in str(
        outbox[0])
    assert '! Text coverage \'Vivid Text Explainer\' due' in str(outbox[0])
    assert '! Picture coverage \'Vivid Photos\' due' in str(outbox[0])

    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 1
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_foo'.format(user_id)
Exemplo n.º 8
0
def test_watched_event_sends_notification_for_unpost_event(
        client, app, mocker):
    event = deepcopy(test_event)
    planning = deepcopy(test_planning)
    post_json(client, '/push', event)
    post_json(client, '/push', planning)
    user_id = assign_active_company(app)
    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update the event for unpost
    event['pubstatus'] = 'cancelled'
    event['state'] = 'cancelled'

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', event)
    notifications = get_user_notifications(user_id)

    assert len(outbox) == 1
    assert 'Subject: Prime minister press conference - Coverage updated' in str(
        outbox[0])
    assert 'The event you have been following has been cancelled' in str(
        outbox[0])
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 1
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_foo'.format(user_id)
Exemplo n.º 9
0
def test_watched_event_sends_notification_for_event_update(
        client, app, mocker):
    event = deepcopy(test_event)
    post_json(client, '/push', event)
    user_id = assign_active_company(app)
    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update comes in
    event['state'] = 'rescheduled'
    event['dates'] = {
        'start': '2018-05-27T08:00:00+0000',
        'end': '2018-06-30T09:00:00+0000',
        'tz': 'Australia/Sydney'
    }

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', event)
    notifications = get_user_notifications(user_id)

    assert len(outbox) == 1
    assert 'Subject: Prime minister press conference - updated' in str(
        outbox[0])
    assert 'The event you have been following has been rescheduled' in str(
        outbox[0])
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 1
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_foo'.format(user_id)
Exemplo n.º 10
0
def test_watched_event_sends_notification_for_added_coverage(
        client, app, mocker):
    event = deepcopy(test_event)
    planning = deepcopy(test_planning)
    set_watch_products(app)
    post_json(client, '/push', event)
    post_json(client, '/push', planning)

    with client.session_transaction() as session:
        session['user'] = PUBLIC_USER_ID
        session['user_type'] = 'public'

    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update the planning with an added coverage
    planning['coverages'].append({
        "planning": {
            "g2_content_type": "video",
            "slugline": "Vivid planning item",
            "internal_note": "internal note here",
            "genre": [{
                "name": "Article (news)",
                "qcode": "Article"
            }],
            "ednote": "ed note here",
            "scheduled": "2018-05-29T10:51:52+0000"
        },
        "coverage_status": {
            "name": "coverage intended",
            "label": "Planned",
            "qcode": "ncostat:int"
        },
        "workflow_status": "draft",
        "firstcreated": "2018-05-29T10:55:00+0000",
        "coverage_id": "coverage-3"
    })

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', planning)
    notifications = get_user_notifications(PUBLIC_USER_ID)

    assert len(outbox) == 0
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 0
    assert len(notifications) == 0
Exemplo n.º 11
0
def test_watched_event_sends_notification_for_added_coverage(
        client, app, mocker):
    event = deepcopy(test_event)
    planning = deepcopy(test_planning)
    post_json(client, '/push', event)
    post_json(client, '/push', planning)
    user_id = assign_active_company(app)
    post_json(client, '/agenda_watch', {'items': [event['guid']]})

    # update the planning with an added coverage
    planning['coverages'].append({
        "planning": {
            "g2_content_type": "video",
            "slugline": "Vivid planning item",
            "internal_note": "internal note here",
            "genre": [{
                "name": "Article (news)",
                "qcode": "Article"
            }],
            "ednote": "ed note here",
            "scheduled": "2018-05-29T10:51:52+0000"
        },
        "coverage_status": {
            "name": "coverage intended",
            "label": "Planned",
            "qcode": "ncostat:int"
        },
        "workflow_status": "draft",
        "firstcreated": "2018-05-29T10:55:00+0000",
        "coverage_id": "coverage-3"
    })

    push_mock = mocker.patch('newsroom.agenda.agenda.push_notification')
    with app.mail.record_messages() as outbox:
        post_json(client, '/push', planning)
    notifications = get_user_notifications(user_id)

    assert len(outbox) == 1
    assert 'Subject: Prime minister press conference - Coverage updated' in str(
        outbox[0])
    assert '! Video coverage \'Vivid planning item\' due' in str(outbox[0])
    assert push_mock.call_args[0][0] == 'agenda_update'
    assert push_mock.call_args[1]['item']['_id'] == 'foo'
    assert len(push_mock.call_args[1]['users']) == 1
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_foo'.format(user_id)
Exemplo n.º 12
0
def test_notification_has_unique_id(client, app):
    app.config['NOTIFICATIONS_TTL'] = 1
    get_resource_service('notifications').post([notification])
    notifications = get_user_notifications(ObjectId(user))
    assert len(notifications) == 1
    assert notifications[0]['_id'] == '{}_Foo'.format(user)