예제 #1
0
def test_getMessage(mocked_method):
    # This will call persistNotification a first time
    instance = Notification.Notification(requester=values['requester'],
                                         receiver=values['receiver'],
                                         message=values['message'])

    assert instance.getMessage() is values['message']
예제 #2
0
def test_status_setter_invalid(mocked_method):
    # This will call persistNotification a first time
    instance = Notification.Notification(requester=values['requester'],
                                         receiver=values['receiver'],
                                         message=values['message'])

    instance.status = values['invalid_state']
    assert instance.status == values['invalid_state']
    assert instance.persistNotification.call_count == 1
예제 #3
0
def test_acknowledge(mocked_method):
    # This will call persistNotification a first time
    instance = Notification.Notification(requester=values['requester'],
                                         receiver=values['receiver'],
                                         message=values['message'])

    instance.acknowledge()
    assert instance.status == 'ACKNOWLEDGED'
    assert instance.persistNotification.call_count == 2
예제 #4
0
def test_status_setter_valid(mocked_method):
    # This will call persistNotification a first time
    instance = Notification.Notification(requester=values['requester'],
                                         receiver=values['receiver'],
                                         message=values['message'])

    valid_statuses = ['ARRIVED', 'DELIVERED', 'ACKNOWLEDGED', 'FAILED']
    for status in valid_statuses:
        instance.status = status
        assert instance.status == status

    assert instance.persistNotification.call_count == len(valid_statuses) + 1
예제 #5
0
def test_persistNotification_expired_5m(mocked_method):
    mocked_method.return_value = values['notification_id']

    # Testing the edge case: the notification has just passed the 5 allowed minutes for delivery
    expires = datetime.datetime.utcnow().strftime('%s')
    instance = Notification.Notification(requester=values['requester'],
                                         receiver=values['receiver'],
                                         message=values['message'],
                                         expires=expires,
                                         created=values['created'],
                                         status='ARRIVED',
                                         notificationId=1)

    assert instance.status == "FAILED"
    assert mocked_method.call_count == 1
    assert mocked_method.call_args[0][0].startswith('UPDATE ')
예제 #6
0
def test_persistNotification_expired(mocked_method):
    mocked_method.return_value = values['notification_id']

    # Testing the edge case: the notification expires in this very second
    expires = datetime.datetime.utcnow().strftime('%s')
    instance = Notification.Notification(requester=values['requester'],
                                         receiver=values['receiver'],
                                         message=values['message'],
                                         expires=expires,
                                         created=values['created'],
                                         status='DELIVERED',
                                         notificationId=1)

    assert instance.status == "FAILED"
    assert mocked_method.call_count == 1
    assert mocked_method.call_args[0][0].startswith('UPDATE ')
예제 #7
0
def test_persistNotification_new(mocked_method):
    mocked_method.return_value = values['last_row_id']

    # Forcing a notificationId in the constructor to avoid calling persistNotification within the constructor
    instance = Notification.Notification(requester=values['requester'],
                                         receiver=values['receiver'],
                                         message=values['message'],
                                         expires=values['expires'],
                                         created=values['created'],
                                         status='DELIVERED',
                                         notificationId=1)
    assert mocked_method.call_count == 0

    # Now setting the notificationId to None to trigger the creation manually
    instance.notificationId = None

    return_id = instance.persistNotification()
    assert return_id == values['last_row_id']
    assert mocked_method.call_count == 1
    assert mocked_method.call_args[0][0].startswith('INSERT ')