コード例 #1
0
def test_dequeue_global():
    timestamp_1 = datetime.now()

    calls_collection.delete_many({})
    call_queue.delete_many({})
    helper_behavior_collection.delete_many({})
    helper_accounts_collection.delete_many({})

    helper_id = helper_accounts_collection.insert_one(test_helper).inserted_id

    A = calls_collection.insert_one(test_calls['A']).inserted_id
    B = calls_collection.insert_one(test_calls['B']).inserted_id
    C = calls_collection.insert_one(test_calls['C']).inserted_id
    D = calls_collection.insert_one(test_calls['D']).inserted_id
    E = calls_collection.insert_one(test_calls['E']).inserted_id
    F = calls_collection.insert_one(test_calls['F']).inserted_id
    G = calls_collection.insert_one(test_calls['G']).inserted_id

    # Should be D -> B (others shall be ignored)

    print('IDS (GLOBAL)')
    call_ids = {'A': A, 'B': B, 'C': C, 'D': D, 'E': E, 'F': F, 'G': G}

    for key in call_ids:
        enqueue.enqueue(call_ids[key])
        print(f'call_id_{key} = {call_ids[key]}')

    results = []

    results += testing.check_queues(15, [A, C, G, F, E], [B, D, E, G], [D, E])

    dequeue_1 = dequeue.dequeue(helper_id, only_global=True)
    results += check_dequeue_result(16, D, dequeue_1)
    results += testing.check_queues(17, [A, C, G, F, E], [B, E, G], [E])
    results += check_helper_queue(18, [D], helper_id)
    results += check_call_record(19, D, helper_id)

    dequeue_2 = dequeue.dequeue(helper_id, only_global=True)
    results += check_dequeue_result(20, B, dequeue_2)
    results += testing.check_queues(21, [A, C, G, F, E], [E, G], [E])
    results += check_helper_queue(22, [D, B], helper_id)
    results += check_call_record(23, B, helper_id)

    dequeue_3 = dequeue.dequeue(helper_id, only_global=True)
    dequeue_3_result = {
        'name': 'Test 24',
        'result': dequeue_3['status'] == 'currently no call available'
    }
    if not dequeue_3_result['result']:
        dequeue_3_result.update({'details': f'actual status = {dequeue_3}'})
    results += [dequeue_3_result]

    calls_collection.delete_many({})
    call_queue.delete_many({})
    helper_behavior_collection.delete_many({})
    helper_accounts_collection.delete_many({})

    return results
コード例 #2
0
ファイル: database_reset.py プロジェクト: HelperLine/backend
def delete_all():
    admin_accounts_collection.delete_many({})
    helper_accounts_collection.delete_many({})

    calls_collection.delete_many({})
    caller_accounts_collection.delete_many({})
    helper_behavior_collection.delete_many({})

    helper_api_keys_collection.delete_many({})
    admin_api_keys_collection.delete_many({})
    email_tokens_collection.delete_many({})
    phone_tokens_collection.delete_many({})

    call_queue.delete_many({})
コード例 #3
0
def test_dequeue_everywhere():
    timestamp_1 = datetime.now()

    calls_collection.delete_many({})
    call_queue.delete_many({})
    helper_behavior_collection.delete_many({})
    helper_accounts_collection.delete_many({})

    helper_id = helper_accounts_collection.insert_one(test_helper).inserted_id

    A = calls_collection.insert_one(test_calls['A']).inserted_id
    B = calls_collection.insert_one(test_calls['B']).inserted_id
    C = calls_collection.insert_one(test_calls['C']).inserted_id
    D = calls_collection.insert_one(test_calls['D']).inserted_id
    E = calls_collection.insert_one(test_calls['E']).inserted_id
    F = calls_collection.insert_one(test_calls['F']).inserted_id
    G = calls_collection.insert_one(test_calls['G']).inserted_id

    # Should be D -> E -> C -> A -> G -> B -> F shall be ignored)

    print('IDS (EVERYWHERE)')
    call_ids = {'A': A, 'B': B, 'C': C, 'D': D, 'E': E, 'F': F, 'G': G}

    for key in call_ids:
        enqueue.enqueue(call_ids[key])
        print(f'call_id_{key} = {call_ids[key]}')

    results = []

    results += testing.check_queues(25, [A, C, G, F, E], [B, D, E, G], [D, E])

    '''
    results += check_dequeue_result(2, D, dequeue.dequeue(helper_id))
    results += check_dequeue_result(3, E, dequeue.dequeue(helper_id))
    results += check_dequeue_result(4, C, dequeue.dequeue(helper_id))
    results += check_dequeue_result(5, A, dequeue.dequeue(helper_id))
    results += check_dequeue_result(6, G, dequeue.dequeue(helper_id))
    results += check_dequeue_result(7, B, dequeue.dequeue(helper_id))

    return results
    '''

    dequeue_1 = dequeue.dequeue(helper_id)
    results += check_dequeue_result(26, D, dequeue_1)
    results += testing.check_queues(27, [A, C, G, F, E], [B, E, G], [E])
    results += check_helper_queue(28, [D], helper_id)
    results += check_call_record(29, D, helper_id)

    dequeue_2 = dequeue.dequeue(helper_id)
    results += check_dequeue_result(30, E, dequeue_2)
    results += testing.check_queues(31, [A, C, G, F], [B, G], [])
    results += check_helper_queue(32, [D, E], helper_id)
    results += check_call_record(33, E, helper_id)

    dequeue_3 = dequeue.dequeue(helper_id)
    results += check_dequeue_result(34, C, dequeue_3)
    results += testing.check_queues(35, [A, G, F], [B, G], [])
    results += check_helper_queue(36, [D, E, C], helper_id)
    results += check_call_record(37, C, helper_id)

    dequeue_4 = dequeue.dequeue(helper_id)
    results += check_dequeue_result(38, A, dequeue_4)
    results += testing.check_queues(39, [G, F], [B, G], [])
    results += check_helper_queue(40, [D, E, C, A], helper_id)
    results += check_call_record(41, A, helper_id)

    dequeue_5 = dequeue.dequeue(helper_id)
    results += check_dequeue_result(42, G, dequeue_5)
    results += testing.check_queues(43, [F], [B], [])
    results += check_helper_queue(44, [D, E, C, A, G], helper_id)
    results += check_call_record(45, G, helper_id)

    dequeue_6 = dequeue.dequeue(helper_id)
    results += check_dequeue_result(46, B, dequeue_6)
    results += testing.check_queues(47, [F], [], [])
    results += check_helper_queue(48, [D, E, C, A, G, B], helper_id)
    results += check_call_record(49, B, helper_id)

    dequeue_6 = dequeue.dequeue(helper_id)
    dequeue_6_result = {
        'name': 'Test 50',
        'result': dequeue_6['status'] == 'currently no call available'
    }
    if not dequeue_6_result['result']:
        dequeue_6_result.update({'details': f'actual status = {dequeue_6}'})
    results += [dequeue_6_result]

    calls_collection.delete_many({})
    call_queue.delete_many({})
    helper_behavior_collection.delete_many({})
    helper_accounts_collection.delete_many({})

    return results
コード例 #4
0
def test_dequeue_local():
    timestamp_1 = datetime.now()

    calls_collection.delete_many({})
    call_queue.delete_many({})
    helper_behavior_collection.delete_many({})
    helper_accounts_collection.delete_many({})

    helper_id = helper_accounts_collection.insert_one(test_helper).inserted_id

    A = calls_collection.insert_one(test_calls['A']).inserted_id
    B = calls_collection.insert_one(test_calls['B']).inserted_id
    C = calls_collection.insert_one(test_calls['C']).inserted_id
    D = calls_collection.insert_one(test_calls['D']).inserted_id
    E = calls_collection.insert_one(test_calls['E']).inserted_id
    F = calls_collection.insert_one(test_calls['F']).inserted_id
    G = calls_collection.insert_one(test_calls['G']).inserted_id

    # Should be E -> C -> A (others shall be ignored)

    print('IDS (LOCAL)')
    call_ids = {'A': A, 'B': B, 'C': C, 'D': D, 'E': E, 'F': F, 'G': G}

    for key in call_ids:
        enqueue.enqueue(call_ids[key])
        print(f'call_id_{key} = {call_ids[key]}')

    results = []

    results += testing.check_queues(1, [A, C, G, F, E], [B, D, E, G], [D, E])

    dequeue_1 = dequeue.dequeue(helper_id, only_local=True)
    results += check_dequeue_result(2, E, dequeue_1)
    results += testing.check_queues(3, [A, C, G, F], [B, D, G], [D])
    results += check_helper_queue(4, [E], helper_id)
    results += check_call_record(5, E, helper_id)

    dequeue_2 = dequeue.dequeue(helper_id, only_local=True)
    results += check_dequeue_result(6, C, dequeue_2)
    results += testing.check_queues(7, [A, G, F], [B, D, G], [D])
    results += check_helper_queue(8, [E, C], helper_id)
    results += check_call_record(9, C, helper_id)

    dequeue_3 = dequeue.dequeue(helper_id, only_local=True)
    results += check_dequeue_result(10, A, dequeue_3)
    results += testing.check_queues(11, [G, F], [B, D, G], [D])
    results += check_helper_queue(12, [E, C, A], helper_id)
    results += check_call_record(13, A, helper_id)

    dequeue_4 = dequeue.dequeue(helper_id, only_local=True)
    dequeue_4_result = {
        'name': 'Test 14',
        'result': dequeue_4['status'] == 'currently no call available'
    }
    if not dequeue_4_result['result']:
        dequeue_4_result.update({'details': f'actual status = {dequeue_4}'})
    results += [dequeue_4_result]

    calls_collection.delete_many({})
    call_queue.delete_many({})
    helper_behavior_collection.delete_many({})
    helper_accounts_collection.delete_many({})

    return results
コード例 #5
0
def test_enqueue():

    results = []

    # Test Start) EMPTY all queues
    calls_collection.delete_many({})
    call_queue.delete_many({})

    call_id_A = calls_collection.insert_one({
        'timestamp_received':
        datetime.now(),
        'local':
        True,
        'zip_code':
        '80000'
    }).inserted_id

    call_id_B = calls_collection.insert_one({
        'timestamp_received':
        datetime.now(),
        'local':
        False,
        'zip_code':
        '80000'
    }).inserted_id

    call_id_C = calls_collection.insert_one({
        'timestamp_received':
        datetime.now() + timedelta(seconds=5),
        'local':
        True,
        'zip_code':
        '80000'
    }).inserted_id

    call_id_D = calls_collection.insert_one({
        'timestamp_received':
        datetime.now() + timedelta(seconds=5),
        'local':
        False,
        'zip_code':
        '80000'
    }).inserted_id

    # T1) Add [local A] and [global B]
    timestamp = datetime.now()
    status_1 = enqueue.enqueue(call_id_A)['status']
    status_2 = enqueue.enqueue(call_id_B)['status']

    results += [{
        'name': 'Test 1 (local add)',
        'result': status_1 == 'ok'
    }, {
        'name': 'Test 1 (global add)',
        'result': status_2 == 'ok'
    }]

    # .) CHECK manually if everything is set correctly -> local: [A], global: [B], urgent: []
    results += testing.check_queues(2, [call_id_A], [call_id_B], [])

    # .) Add [local A] and [global B] (both are invalid but non-breaking operations)
    timestamp = datetime.now()
    status_1 = enqueue.enqueue(call_id_A)['status']
    status_2 = enqueue.enqueue(call_id_B)['status']

    results += [{
        'name': 'Test 4 (local duplicate add)',
        'result': status_1 == 'call id already exists'
    }, {
        'name': 'Test 4 (global duplicate add)',
        'result': status_2 == 'call id already exists'
    }]

    # .) CHECK manually if everything is set correctly -> local: [A], global: [B], urgent: []
    results += testing.check_queues(5, [call_id_A], [call_id_B], [])

    # T2) sleep for (5 seconds) now at t=5
    time.sleep(5)

    # .) Add [local C] and [global D]
    timestamp = datetime.now()
    status_1 = enqueue.enqueue(call_id_C)['status']
    status_2 = enqueue.enqueue(call_id_D)['status']

    results += [{
        'name': 'Test 6 (local add)',
        'result': status_1 == 'ok'
    }, {
        'name': 'Test 6 (global add)',
        'result': status_2 == 'ok'
    }]

    # .) CHECK manually if everything is set correctly -> local: [A, C], global: [B, D], urgent: []
    results += testing.check_queues(7, [call_id_A, call_id_C],
                                    [call_id_B, call_id_D], [])

    # T3) sleep for (5 seconds) now at t=10
    time.sleep(5)

    # .) CHECK manually if everything is set correctly -> local: [A, C], global: [A, B, D], urgent: []
    results += testing.check_queues(8, [call_id_A, call_id_C],
                                    [call_id_A, call_id_B, call_id_D], [])

    # T4) sleep for (6 seconds) now at t=16
    time.sleep(6)

    # .) CHECK manually if everything is set correctly -> local: [A, C], global: [A, B, C, D], urgent: [A, B]
    results += testing.check_queues(
        9, [call_id_A, call_id_C],
        [call_id_A, call_id_B, call_id_C, call_id_D], [call_id_A, call_id_B])

    # T5) sleep for (5 seconds) now at t=21
    time.sleep(5)

    # .) CHECK manually if everything is set correctly -> local: [A, C], global: [A, B, C, D], urgent: [A, B, C, D]
    results += testing.check_queues(
        10, [call_id_A, call_id_C],
        [call_id_A, call_id_B, call_id_C, call_id_D],
        [call_id_A, call_id_B, call_id_C, call_id_D])

    # Test End) EMPTY all queues
    calls_collection.delete_many({
        '_id': {
            '$in': [
                ObjectId(call_id)
                for call_id in [call_id_A, call_id_B, call_id_C, call_id_D]
            ]
        }
    })
    call_queue.delete_many({
        '_id': {
            '$in': [
                ObjectId(call_id)
                for call_id in [call_id_A, call_id_B, call_id_C, call_id_D]
            ]
        }
    })

    return results