def test_missing_flow_data():
    missing_ranges = [support.Range(1,5,1), support.Range(8,10,1)]
    missing_resource = mr.MissingFlowData(missing_ranges)

    supplied_range1 = support.Range(3,5,1)
    supplied_range2 = support.Range(6,9,1)
    supplied_resource1 = sr.SuppliedFlowData(supplied_range1)
    supplied_resource2 = sr.SuppliedFlowData(supplied_range2)

    #Not empty
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), False, "Test empty after filled")

    #Applied first
    missing_resource.update_missing_from_supplied_info(supplied_resource1)
    now_missing_ranges1 = missing_resource.missing

    run_tests.compare_answer(now_missing_ranges1, [support.Range(1,2,1), support.Range(8,10,1)], "Test missing after first supplied")

    #Applied second
    missing_resource.update_missing_from_supplied_info(supplied_resource2)
    now_missing_ranges2 = missing_resource.missing
    run_tests.compare_answer(now_missing_ranges2, [support.Range(1,2,1), support.Range(10,10,1)], "Test missing after second supplied")

    #Dismiss all and test empty
    supplied_range_dismiss = support.Range(1,10,1)
    supplied_resource_dismiss = sr.SuppliedFlowData(supplied_range_dismiss)
    missing_resource.update_missing_from_supplied_info(supplied_resource_dismiss)

    now_missing_ranges_dismiss = missing_resource.missing

    run_tests.compare_answer(now_missing_ranges_dismiss, [], "Test if missing list is now empty")
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), True, "Test to see if missing resource is not missing anything")
def test_save_and_delete_object():
    setup_table()

    obj = setup_object()

    #delete before saving and an ID is given
    run_tests.compare_answer(obj.delete(), False, "Try to delete before saving an object")

    #save
    save_result = obj.save()
    run_tests.compare_answer(save_result, True, "See if the save of the object succeeded")

    #retrieve1
    retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve1), 1, "Sees if only one row has been inserted")

    retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve1[0], TestObject.layout)
    values1 = _dict_values_only(retrieve1_)
    _check_object_attributes(obj, values1)

    #delete
    result = obj.delete()
    run_tests.compare_answer(result, True, "Sees if the delete has succeeded")

    #retrieve2
    retrieve2 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve2), 0, "Checks to see if the table is empty")

    delete_table()
Beispiel #3
0
def test_to_unix_timestamp_ms_from_date_and_time():
    t = datetime.time(hour=12, minute=30, second=10, microsecond=6000)
    d = datetime.date(year=1991, month=10, day=17)

    unix_ms = support.to_unix_timestamp_ms_from_date_and_time(d, t)

    run_tests.compare_answer(unix_ms, 687702610006, "")
Beispiel #4
0
def test_find_all_in_list():
    l1 = [1, 5, 2, 3, None, 5]
    indices1 = support.find_all_in_list(l1, 5)
    run_tests.compare_answer(indices1, [1, 5], "indices1")

    l2 = [None, 123, "asd", None, datetime.datetime(year=1991, month=10, day=10)]
    indices2 = support.find_all_in_list(l2, None)
    run_tests.compare_answer(indices2, [0, 3], "indices2")
Beispiel #5
0
def test_to_grid():
    l1 = [1, 2, 3, 3, 4, 5, 5]
    grid1 = support.to_grid(l1, 1, lambda x: x, 1, 5)
    run_tests.compare_answer(grid1, [1,2,3,4,5], "grid1")

    l2 = [100, 130, 100, 100, 150, 130, 100]
    grid2 = support.to_grid(l2, 10, lambda x: x, 100, 150)
    run_tests.compare_answer(grid2, [100, None, None, 130, None, 150], "grid2")
Beispiel #6
0
def _check_object_attributes(obj, values):
    for name, value in _test_column_names_values(values):
        if hasattr(obj, name):
            run_tests.compare_answer(
                getattr(obj, name), value,
                "Sees if the correct attribute " + name + " is set")
        else:
            run_tests.compare_answer(
                None, value,
                "Could not find the attribute in object " + str(obj))
Beispiel #7
0
def test_reduce_to_missing_ranges():
    l1 = [1, 2, 10, 40, 41, 50]
    answer1 = [support.Range(3, 9, 1), support.Range(11, 39, 1), support.Range(42, 49, 1)]
    result1 = support.reduce_to_missing_ranges(l1, lambda x: x, 1, 1, 50)
    run_tests.compare_answer(result1, answer1, "missing_support.Ranges 1")

    #Difficult one because one value is outside of the (start value, end value) support.Range while the resolution allows it
    l2 = [9, 11]
    answer2 = [support.Range(1, 6, 3), support.Range(10, 10, 3)]
    result2 = support.reduce_to_missing_ranges(l2, lambda x: x, 3, 1, 10)
    run_tests.compare_answer(result2, answer2, "missing_ranges 2")
Beispiel #8
0
def test_execute_something():
    dbcc = setup_database_connection()
    dbcc.start_all_connections()
    setup_table(dbcc)
    con = dbcc.retrieve_connection(config.TESTDB)

    result = con.execute("SELECT * FROM " + config.TEST_TABLE + ";")
    run_tests.compare_answer(result, True, "Was able to execute something on the database")

    teardown_table(dbcc)
    dbcc.close_all_connections()
Beispiel #9
0
def test_user_info_reduce_to_time_resolution():
    user_infos = setup_user_info_list(USER_INFO_ARGS_LIST_2)

    result_1 = db_layout.UserMobilityInformation.reduce_to_time_resolution(
        user_infos, 1)
    answer_1 = user_infos
    run_tests.compare_answer(len(_set_different(result_1, answer_1)), 0,
                             "reduce_time_resolution with 1 second")

    result_10 = db_layout.UserMobilityInformation.reduce_to_time_resolution(
        user_infos, 10)
    answer_10 = user_infos
    run_tests.compare_answer(len(_set_different(result_10, answer_10)), 0,
                             "reduce_time_resolution with 10 seconds")

    result_20 = db_layout.UserMobilityInformation.reduce_to_time_resolution(
        user_infos, 20)
    answer_20 = setup_user_info_list(
        [USER_INFO_1_ARGS_2, USER_INFO_3_ARGS_2, USER_INFO_5_ARGS_2])
    run_tests.compare_answer(len(_set_different(result_20, answer_20)), 0,
                             "reduce_time_resolution with 20 seconds")

    result_60 = db_layout.UserMobilityInformation.reduce_to_time_resolution(
        user_infos, 60)
    answer_60 = setup_user_info_list([USER_INFO_3_ARGS_2, USER_INFO_5_ARGS_2])
    run_tests.compare_answer(len(_set_different(result_60, answer_60)), 0,
                             "reduce_time_resolution with 60 seconds")
Beispiel #10
0
def test_multiple_objects():
    setup_table()
    obj_1 = setup_object()
    obj_2 = setup_object()

    obj_1.save()
    obj_2.save()

    #Check to see if id matches
    run_tests.compare_answer(obj_1.oid, 0, "Check to see if first id = 0")
    run_tests.compare_answer(obj_2.oid, 1, "Check to see if second id = 1")

    #Check to see if both are in the table
    retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data(
        "*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve1), 2,
                             "Sees if both rows have been inserted")

    #Check first object values
    retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(
        retrieve1[0], TestObject.layout)
    values1 = _dict_values_only(retrieve1_)
    _check_object_attributes(obj_1, values1)

    #check second object values
    retrieve2_ = db_connections.DatabaseType.format_mysql_row_from_db(
        retrieve1[1], TestObject.layout)
    values2 = _dict_values_only(retrieve2_)
    _check_object_attributes(obj_2, values2)

    #Check if one can be deleted and one still exists
    obj_1.delete()

    retrieve2 = DBCC.retrieve_connection(config.TESTDB).retrieve_data(
        "*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve2), 1, "Sees if one row still exists")

    retrieve3_ = db_connections.DatabaseType.format_mysql_row_from_db(
        retrieve2[0], TestObject.layout)
    values3 = _dict_values_only(retrieve3_)
    _check_object_attributes(obj_2, values3)

    #delete last one
    obj_2.delete()

    retrieve3 = DBCC.retrieve_connection(config.TESTDB).retrieve_data(
        "*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve3), 0, "Sees if no rows still exists")

    delete_table()
def test_object_from_row():
    setup_table()
    obj_1 = setup_object()
    obj_1.save()

    #Retrieve from table and build object
    retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])
    obj_1_ = TestObject.object_from_mysql_row(DBCC, retrieve1[0])

    run_tests.compare_answer(obj_1 == obj_1_, True, "Compare if both objects are the same")

    obj_1.delete()

    delete_table()
Beispiel #12
0
def test_contains_complete_message():
    [
        run_tests.compare_answer(
            mobaas_protocol.contains_complete_message(msg_str), True,
            "Check contains_complete_message for " + msg_str)
        for msg_str, _ in MESSAGES
    ]
Beispiel #13
0
def test_object_from_row():
    setup_table()
    obj_1 = setup_object()
    obj_1.save()

    #Retrieve from table and build object
    retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data(
        "*", config.TEST_TABLE, [])
    obj_1_ = TestObject.object_from_mysql_row(DBCC, retrieve1[0])

    run_tests.compare_answer(obj_1 == obj_1_, True,
                             "Compare if both objects are the same")

    obj_1.delete()

    delete_table()
Beispiel #14
0
def test_first_complete_message_ends_at():
    [
        run_tests.compare_answer(
            mobaas_protocol.first_complete_message_ends_at(msg_str),
            len(msg_str) - 1,
            "Check first_complete_message_ends_at for " + msg_str)
        for msg_str, _ in MESSAGES
    ]
Beispiel #15
0
def test_missing_flow_data():
    missing_ranges = [support.Range(1, 5, 1), support.Range(8, 10, 1)]
    missing_resource = mr.MissingFlowData(missing_ranges)

    supplied_range1 = support.Range(3, 5, 1)
    supplied_range2 = support.Range(6, 9, 1)
    supplied_resource1 = sr.SuppliedFlowData(supplied_range1)
    supplied_resource2 = sr.SuppliedFlowData(supplied_range2)

    #Not empty
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), False,
                             "Test empty after filled")

    #Applied first
    missing_resource.update_missing_from_supplied_info(supplied_resource1)
    now_missing_ranges1 = missing_resource.missing

    run_tests.compare_answer(now_missing_ranges1,
                             [support.Range(1, 2, 1),
                              support.Range(8, 10, 1)],
                             "Test missing after first supplied")

    #Applied second
    missing_resource.update_missing_from_supplied_info(supplied_resource2)
    now_missing_ranges2 = missing_resource.missing
    run_tests.compare_answer(
        now_missing_ranges2,
        [support.Range(1, 2, 1),
         support.Range(10, 10, 1)], "Test missing after second supplied")

    #Dismiss all and test empty
    supplied_range_dismiss = support.Range(1, 10, 1)
    supplied_resource_dismiss = sr.SuppliedFlowData(supplied_range_dismiss)
    missing_resource.update_missing_from_supplied_info(
        supplied_resource_dismiss)

    now_missing_ranges_dismiss = missing_resource.missing

    run_tests.compare_answer(now_missing_ranges_dismiss, [],
                             "Test if missing list is now empty")
    run_tests.compare_answer(
        missing_resource.is_not_missing_anything(), True,
        "Test to see if missing resource is not missing anything")
def test_multiple_objects():
    setup_table()
    obj_1 = setup_object()
    obj_2 = setup_object()

    obj_1.save()
    obj_2.save()

    #Check to see if id matches
    run_tests.compare_answer(obj_1.oid, 0, "Check to see if first id = 0")
    run_tests.compare_answer(obj_2.oid, 1, "Check to see if second id = 1")

    #Check to see if both are in the table
    retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve1), 2, "Sees if both rows have been inserted")

    #Check first object values
    retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve1[0], TestObject.layout)
    values1 = _dict_values_only(retrieve1_)
    _check_object_attributes(obj_1, values1)

    #check second object values
    retrieve2_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve1[1], TestObject.layout)
    values2 = _dict_values_only(retrieve2_)
    _check_object_attributes(obj_2, values2)

    #Check if one can be deleted and one still exists
    obj_1.delete()

    retrieve2 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve2), 1, "Sees if one row still exists")

    retrieve3_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve2[0], TestObject.layout)
    values3 = _dict_values_only(retrieve3_)
    _check_object_attributes(obj_2, values3)

    #delete last one
    obj_2.delete()

    retrieve3 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve3), 0, "Sees if no rows still exists")

    delete_table()
Beispiel #17
0
def test_create_and_delete_table():
    dbcc = setup_database_connection()
    dbcc.start_all_connections()

    con = dbcc.retrieve_connection(config.TESTDB)
    result = con.create_table(config.TEST_TABLE, config.TEST_TABLE_LAYOUT)
    run_tests.compare_answer(result, True, "Check if table was created")
    run_tests.compare_answer(con.table_exists(config.TEST_TABLE), True, "Does the table exist")
    run_tests.compare_answer(con.delete_table(config.TEST_TABLE), True, "Has the table been deleted")
    run_tests.compare_answer(con.table_exists(config.TEST_TABLE), False, "Has the table actually been deleted?")

    dbcc.close_all_connections()
def test_update():
    setup_table()
    obj = setup_object()

    obj.save()
    id_1 = obj.oid

    obj.double_c = DOUBLE2
    obj.text_c = TEXT2
    obj.int_c = INT2
    obj.time_c = TIME2
    obj.date_c = DATE2
    obj.unix_c = UNIX2

    #Update
    update_result = obj.save()
    run_tests.compare_answer(update_result, True, "Check to see if update succeeded")

    #Retrieve1
    retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve1), 1, "Sees if only one row has been inserted")

    retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve1[0], TestObject.layout)
    values2 = _dict_values_only(retrieve1_)
    _check_object_attributes(obj, values2)
    run_tests.compare_answer(retrieve1_["oid"], id_1, "Check to see if the id still matches")

    obj.delete()

    delete_table()
Beispiel #19
0
def test_update():
    setup_table()
    obj = setup_object()

    obj.save()
    id_1 = obj.oid

    obj.double_c = DOUBLE2
    obj.text_c = TEXT2
    obj.int_c = INT2
    obj.time_c = TIME2
    obj.date_c = DATE2
    obj.unix_c = UNIX2

    #Update
    update_result = obj.save()
    run_tests.compare_answer(update_result, True,
                             "Check to see if update succeeded")

    #Retrieve1
    retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data(
        "*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve1), 1,
                             "Sees if only one row has been inserted")

    retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(
        retrieve1[0], TestObject.layout)
    values2 = _dict_values_only(retrieve1_)
    _check_object_attributes(obj, values2)
    run_tests.compare_answer(retrieve1_["oid"], id_1,
                             "Check to see if the id still matches")

    obj.delete()

    delete_table()
Beispiel #20
0
def test_calc_minute_of_day():
    time1 = datetime.time(hour=0, minute=1, second=1)
    time2 = datetime.time(hour=1, minute=0, second=1)
    time3 = datetime.time(hour=0, minute=0, second=0)
    time4 = datetime.time(hour=23, minute=59, second=59)

    value1 = support.calc_minute_of_day(time1)
    value2 = support.calc_minute_of_day(time2)
    value3 = support.calc_minute_of_day(time3)
    value4 = support.calc_minute_of_day(time4)

    run_tests.compare_answer(value1, 1, "minute of day = 1")
    run_tests.compare_answer(value2, 60, "minute of day = 2")
    run_tests.compare_answer(value3, 0, "minute of day = 3")
    run_tests.compare_answer(value4, 1439, "minute of day = 4")
Beispiel #21
0
def test_save_and_delete_object():
    setup_table()

    obj = setup_object()

    #delete before saving and an ID is given
    run_tests.compare_answer(obj.delete(), False,
                             "Try to delete before saving an object")

    #save
    save_result = obj.save()
    run_tests.compare_answer(save_result, True,
                             "See if the save of the object succeeded")

    #retrieve1
    retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data(
        "*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve1), 1,
                             "Sees if only one row has been inserted")

    retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(
        retrieve1[0], TestObject.layout)
    values1 = _dict_values_only(retrieve1_)
    _check_object_attributes(obj, values1)

    #delete
    result = obj.delete()
    run_tests.compare_answer(result, True, "Sees if the delete has succeeded")

    #retrieve2
    retrieve2 = DBCC.retrieve_connection(config.TESTDB).retrieve_data(
        "*", config.TEST_TABLE, [])
    run_tests.compare_answer(len(retrieve2), 0,
                             "Checks to see if the table is empty")

    delete_table()
def test_user_info_reduce_to_time_resolution():
    user_infos = setup_user_info_list(USER_INFO_ARGS_LIST_2)

    result_1 = db_layout.UserMobilityInformation.reduce_to_time_resolution(user_infos, 1)
    answer_1 = user_infos
    run_tests.compare_answer(len(_set_different(result_1, answer_1)), 0, "reduce_time_resolution with 1 second")

    result_10 = db_layout.UserMobilityInformation.reduce_to_time_resolution(user_infos, 10)
    answer_10 = user_infos
    run_tests.compare_answer(len(_set_different(result_10, answer_10)), 0, "reduce_time_resolution with 10 seconds")

    result_20 = db_layout.UserMobilityInformation.reduce_to_time_resolution(user_infos, 20)
    answer_20 = setup_user_info_list([USER_INFO_1_ARGS_2, USER_INFO_3_ARGS_2, USER_INFO_5_ARGS_2])
    run_tests.compare_answer(len(_set_different(result_20, answer_20)), 0, "reduce_time_resolution with 20 seconds")

    result_60 = db_layout.UserMobilityInformation.reduce_to_time_resolution(user_infos, 60)
    answer_60 = setup_user_info_list([USER_INFO_3_ARGS_2, USER_INFO_5_ARGS_2])
    run_tests.compare_answer(len(_set_different(result_60, answer_60)), 0, "reduce_time_resolution with 60 seconds")
def test_missing_link_capacity():
    missing_link_id = 2
    missing_resource = mr.MissingLinkCapacity(missing_link_id)

    supplied_link_id1 = 1
    supplied_link_id2 = 2
    supplied_resource1 = sr.SuppliedLinkCapacity(supplied_link_id1)
    supplied_resource2 = sr.SuppliedLinkCapacity(supplied_link_id2)

    #Not empty
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), False, "Test empty after filled")

    #Applied first
    missing_resource.update_missing_from_supplied_info(supplied_resource1)
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), False, "Test after first supplied")
    run_tests.compare_answer(missing_resource.missing, missing_link_id, "Test to see if missing stayed the same")

    #Applied second
    missing_resource.update_missing_from_supplied_info(supplied_resource2)
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), True, "Test to see if empty after link id is supplied")
Beispiel #24
0
def test_missing_link_capacity():
    missing_link_id = 2
    missing_resource = mr.MissingLinkCapacity(missing_link_id)

    supplied_link_id1 = 1
    supplied_link_id2 = 2
    supplied_resource1 = sr.SuppliedLinkCapacity(supplied_link_id1)
    supplied_resource2 = sr.SuppliedLinkCapacity(supplied_link_id2)

    #Not empty
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), False,
                             "Test empty after filled")

    #Applied first
    missing_resource.update_missing_from_supplied_info(supplied_resource1)
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), False,
                             "Test after first supplied")
    run_tests.compare_answer(missing_resource.missing, missing_link_id,
                             "Test to see if missing stayed the same")

    #Applied second
    missing_resource.update_missing_from_supplied_info(supplied_resource2)
    run_tests.compare_answer(missing_resource.is_not_missing_anything(), True,
                             "Test to see if empty after link id is supplied")
def test_retrieve_objects():
    setup_table()
    obj_1 = setup_object()
    obj_2 = setup_object_2()
    obj_2.double_c = DOUBLE1

    obj_1.save()
    obj_2.save()

    objects = TestObject.retrieve_objects(DBCC, [("double_c", "=", DOUBLE1)])

    obj_1_ = [obj for obj in objects if obj.oid == 0][0]
    obj_2_ = [obj for obj in objects if obj.oid == 1][0]

    run_tests.compare_answer(obj_1 == obj_1_, True, "Test to see if first object matches")
    run_tests.compare_answer(obj_2 == obj_2_, True, "Test to see if second object matches")
    run_tests.compare_answer(len(objects), 2, "Test to see if only 2 objects are created")

    delete_table()
Beispiel #26
0
def test_retrieve_objects():
    setup_table()
    obj_1 = setup_object()
    obj_2 = setup_object_2()
    obj_2.double_c = DOUBLE1

    obj_1.save()
    obj_2.save()

    objects = TestObject.retrieve_objects(DBCC, [("double_c", "=", DOUBLE1)])

    obj_1_ = [obj for obj in objects if obj.oid == 0][0]
    obj_2_ = [obj for obj in objects if obj.oid == 1][0]

    run_tests.compare_answer(obj_1 == obj_1_, True,
                             "Test to see if first object matches")
    run_tests.compare_answer(obj_2 == obj_2_, True,
                             "Test to see if second object matches")
    run_tests.compare_answer(len(objects), 2,
                             "Test to see if only 2 objects are created")

    delete_table()
Beispiel #27
0
def test_create_time_str():
    t = datetime.time(hour=12, minute=30, second=31)
    run_tests.compare_answer(support.create_time_str(t), "12:30:31", "")
Beispiel #28
0
def test_time_total_seconds():
    t1 = datetime.time(hour=0, minute=0, second=0)
    t2 = datetime.time(hour=10, minute=10, second=10)

    run_tests.compare_answer(support.time_total_seconds(t1), 0, "total seconds 0")
    run_tests.compare_answer(support.time_total_seconds(t2), 36610, "total seconds 36610")
def test_pending_request_queue():
    missing_resource_1 = mr.MissingLinkCapacity(1)
    supplied_resource_1 = sr.SuppliedLinkCapacity(1)

    missing_resource_2 = mr.MissingFlowData([support.Range(1, 3, 1)])
    supplied_resource_2_1 = sr.SuppliedFlowData(support.Range(3, 5, 1))
    supplied_resource_2_2 = sr.SuppliedFlowData(support.Range(1, 3, 1))

    pending_request_queue = pending_requests.PendingRequestQueue()
    pending_request_queue.add_pending_request(None, "req_msg1", [missing_resource_1, missing_resource_2])
    pending_request_queue.add_pending_request(None, "req_msg2", [missing_resource_1])

    #Not empty
    run_tests.compare_answer(pending_request_queue.get_ready_to_be_handled_requests()
                            , []
                            , "Check to see if no requests initially are ready"
                            )
    run_tests.compare_answer(len(pending_request_queue.pending_requests)
                            , 2
                            , "Check to see if both requests are still there initially"
                            )

    #Supply 1
    pending_request_queue.process_supplied_resource(supplied_resource_1)
    requests = pending_request_queue.get_ready_to_be_handled_requests()
    run_tests.compare_answer(len(requests)
                            , 1
                            , "Check to see one request is ready after first supply"
                            )
    run_tests.compare_answer( requests[0].request_message
                            , "req_msg2"
                            , "Check to see if correct message is ready req1"
                            )
    run_tests.compare_answer(len(pending_request_queue.pending_requests)
                            , 1
                            , "Check to see if last request is still there after first supply"
                            )

    #Supply 2_1
    pending_request_queue.process_supplied_resource(supplied_resource_2_1)
    requests = pending_request_queue.get_ready_to_be_handled_requests()
    run_tests.compare_answer( len(requests)
                            , 0
                            , "Check to see if zero requests are ready after second supply"
                            )
    run_tests.compare_answer(len(pending_request_queue.pending_requests)
                            , 1
                            , "Check to see if last request is still there after second supply"
                            )

    #Supply 2_2
    pending_request_queue.process_supplied_resource(supplied_resource_2_2)
    requests = pending_request_queue.get_ready_to_be_handled_requests()
    run_tests.compare_answer(len(requests)
                            , 1
                            , "Check to see one request is ready after third supply"
                            )
    run_tests.compare_answer( requests[0].request_message
                            , "req_msg1"
                            , "Check to see if correct message is ready req2"
                            )
    run_tests.compare_answer(len(pending_request_queue.pending_requests)
                            , 0
                            , "Check to see if no request is still there after third supply"
                            )
def _check_object_attributes(obj, values):
    for name, value in _test_column_names_values(values):
        if hasattr(obj, name):
            run_tests.compare_answer(getattr(obj, name), value, "Sees if the correct attribute " + name + " is set")
        else:
            run_tests.compare_answer(None, value, "Could not find the attribute in object " + str(obj))
def test_equals():
    obj_1 = setup_object()
    obj_2 = setup_object()

    run_tests.compare_answer(obj_1 == obj_2, True, "Testing two same objects")
Beispiel #32
0
def test_parse_message():
    [
        run_tests.compare_answer(mobaas_protocol.parse_message(msg_str),
                                 msg_obj, "Check parse_message for " + msg_str)
        for msg_str, msg_obj in MESSAGES
    ]
def test_parse_message():
    [run_tests.compare_answer( mobaas_protocol.parse_message(msg_str)
                             , msg_obj
                             , "Check parse_message for " + msg_str
                             ) for msg_str, msg_obj in MESSAGES]
def test_contains_complete_message():
    [run_tests.compare_answer( mobaas_protocol.contains_complete_message(msg_str)
                             , True
                             , "Check contains_complete_message for " + msg_str
                             ) for msg_str, _ in MESSAGES]
Beispiel #35
0
def test_retrieve_connection():
    dbcc = setup_database_connection()

    run_tests.compare_answer(dbcc.retrieve_connection(config.TESTDB).db_name, config.TESTDB, "Retrieve connection")
Beispiel #36
0
def test_open_and_close_database_connection():
    dbcc = setup_database_connection()

    run_tests.compare_answer(dbcc.start_all_connections(), True, "Start all connections")
    run_tests.compare_answer(dbcc.close_all_connections(), True, "Close all connections")
Beispiel #37
0
def test_insert_retrieve_update_retrieve_delete_data():
    dbcc = setup_database_connection()
    dbcc.start_all_connections()
    setup_table(dbcc)
    con = dbcc.retrieve_connection(config.TESTDB)

    #insert
    result_insert1 = con.insert_data(config.TEST_TABLE, config.TEST_TABLE_LAYOUT, [DATA1])
    run_tests.compare_answer(result_insert1, True, "Has the data been inserted succesfully?")

    #retrieve1
    data1 = _test_column_names_values_types(list(DATA1))
    retrieve1 = con.retrieve_data_eq("*", config.TEST_TABLE, data1)
    run_tests.compare_answer(len(retrieve1), 1, "Check if there is only 1 row inserted")
    retrieve1_ = d.DatabaseType.format_mysql_row_from_db(retrieve1[0], config.TEST_TABLE_LAYOUT)
    run_tests.compare_answer(retrieve1_["double_c"], DOUBLE1, "Check double 1 value")
    run_tests.compare_answer(retrieve1_["text_c"], TEXT1, "Check text 1 value")
    run_tests.compare_answer(retrieve1_["int_c"], INT1, "Check int 1 value")
    run_tests.compare_answer(retrieve1_["time_c"], TIME1, "Check time 1 value")
    run_tests.compare_answer(retrieve1_["date_c"], DATE1, "Check date 1 value")
    run_tests.compare_answer(retrieve1_["unix_c"], UNIX1, "Check unix 1 value")

    #update
    data2 = _test_column_names_values_types(list(DATA2))
    update1 = con.update_data_eq(config.TEST_TABLE, data2, data1)
    run_tests.compare_answer(update1, True, "Did the update succesfully happen?")
    
    #retrieve2
    retrieve2 = con.retrieve_data_eq("*", config.TEST_TABLE, data2)
    run_tests.compare_answer(len(retrieve2), 1, "Check if there is still only 1 row")
    retrieve2_ = d.DatabaseType.format_mysql_row_from_db(retrieve2[0], config.TEST_TABLE_LAYOUT)
    run_tests.compare_answer(retrieve2_["double_c"], DOUBLE2, "Check double 2 value")
    run_tests.compare_answer(retrieve2_["text_c"], TEXT2, "Check text 2 value")
    run_tests.compare_answer(retrieve2_["int_c"], INT2, "Check int 2 value")
    run_tests.compare_answer(retrieve2_["time_c"], TIME2, "Check time 2 value")
    run_tests.compare_answer(retrieve2_["date_c"], DATE2, "Check date 2 value")
    run_tests.compare_answer(retrieve2_["unix_c"], UNIX2, "Check unix 2 value")

    #delete
    delete1 = con.delete_data_eq(config.TEST_TABLE, data2)
    run_tests.compare_answer(delete1, True, "Could we delete the data?")
    retrieve3 = con.retrieve_data_eq("*", config.TEST_TABLE, data2)
    run_tests.compare_answer(len(retrieve3), 0, "Has the data actually been deleted?")

    teardown_table(dbcc)
    dbcc.close_all_connections()
def test_pending_request():
    missing_resource_1 = mr.MissingLinkCapacity(1)
    supplied_resource_1 = sr.SuppliedLinkCapacity(1)

    missing_resource_2 = mr.MissingFlowData([support.Range(1, 3, 1)])
    supplied_resource_2_1 = sr.SuppliedFlowData(support.Range(3, 5, 1))
    supplied_resource_2_2 = sr.SuppliedFlowData(support.Range(1, 3, 1))

    pending_request = pending_requests.PendingRequest( None
                                                     , "req_msg"
                                                     , [ missing_resource_1
                                                       , missing_resource_2
                                                       ]
                                                     )

    #Not empty
    run_tests.compare_answer(pending_request.ready_to_be_handled(), False, "Check if request not be handled after filled")
    run_tests.compare_answer(len(pending_request.missing_resources.items()), 2, "Check to see if both are added")

    #Supply 1
    pending_request.process_supplied_resource(supplied_resource_1)

    run_tests.compare_answer(pending_request.ready_to_be_handled(), False, "Check if request not be handled after first supply")
    run_tests.compare_answer(len(pending_request.missing_resources.items()), 1, "Check to see if one still exists")

    #Supply 2_1
    pending_request.process_supplied_resource(supplied_resource_2_1)
    run_tests.compare_answer(pending_request.ready_to_be_handled(), False, "Check if request not be handled after second supply")
    run_tests.compare_answer(len(pending_request.missing_resources.items()), 1, "Check to see if one still exists")

    #Supply 2_2
    pending_request.process_supplied_resource(supplied_resource_2_2)
    run_tests.compare_answer(pending_request.ready_to_be_handled(), True, "Check if request be handled after third supply")
    run_tests.compare_answer(len(pending_request.missing_resources.items()), 0, "Check to see if none still exist")
Beispiel #39
0
def test_create_date_str():
    d = datetime.date(year=2014, month=10, day=17)
    run_tests.compare_answer(support.create_date_str(d), "2014-10-17", "")
Beispiel #40
0
def test_create_date_time():
    time_str = "14:30:31"
    date_str = "2014-10-17"

    dt = support.create_date_time(date_str, time_str)

    run_tests.compare_answer(dt.second, 31,"second")
    run_tests.compare_answer(dt.minute, 30,"minute")
    run_tests.compare_answer(dt.hour, 14,"hour")
    run_tests.compare_answer(dt.day, 17,"day")
    run_tests.compare_answer(dt.month, 10,"month")
    run_tests.compare_answer(dt.year, 2014,"year")
def test_pending_request():
    missing_resource_1 = mr.MissingLinkCapacity(1)
    supplied_resource_1 = sr.SuppliedLinkCapacity(1)

    missing_resource_2 = mr.MissingFlowData([support.Range(1, 3, 1)])
    supplied_resource_2_1 = sr.SuppliedFlowData(support.Range(3, 5, 1))
    supplied_resource_2_2 = sr.SuppliedFlowData(support.Range(1, 3, 1))

    pending_request = pending_requests.PendingRequest(
        None, "req_msg", [missing_resource_1, missing_resource_2])

    #Not empty
    run_tests.compare_answer(pending_request.ready_to_be_handled(), False,
                             "Check if request not be handled after filled")
    run_tests.compare_answer(len(pending_request.missing_resources.items()), 2,
                             "Check to see if both are added")

    #Supply 1
    pending_request.process_supplied_resource(supplied_resource_1)

    run_tests.compare_answer(
        pending_request.ready_to_be_handled(), False,
        "Check if request not be handled after first supply")
    run_tests.compare_answer(len(pending_request.missing_resources.items()), 1,
                             "Check to see if one still exists")

    #Supply 2_1
    pending_request.process_supplied_resource(supplied_resource_2_1)
    run_tests.compare_answer(
        pending_request.ready_to_be_handled(), False,
        "Check if request not be handled after second supply")
    run_tests.compare_answer(len(pending_request.missing_resources.items()), 1,
                             "Check to see if one still exists")

    #Supply 2_2
    pending_request.process_supplied_resource(supplied_resource_2_2)
    run_tests.compare_answer(pending_request.ready_to_be_handled(), True,
                             "Check if request be handled after third supply")
    run_tests.compare_answer(len(pending_request.missing_resources.items()), 0,
                             "Check to see if none still exist")
def test_pending_request_queue():
    missing_resource_1 = mr.MissingLinkCapacity(1)
    supplied_resource_1 = sr.SuppliedLinkCapacity(1)

    missing_resource_2 = mr.MissingFlowData([support.Range(1, 3, 1)])
    supplied_resource_2_1 = sr.SuppliedFlowData(support.Range(3, 5, 1))
    supplied_resource_2_2 = sr.SuppliedFlowData(support.Range(1, 3, 1))

    pending_request_queue = pending_requests.PendingRequestQueue()
    pending_request_queue.add_pending_request(
        None, "req_msg1", [missing_resource_1, missing_resource_2])
    pending_request_queue.add_pending_request(None, "req_msg2",
                                              [missing_resource_1])

    #Not empty
    run_tests.compare_answer(
        pending_request_queue.get_ready_to_be_handled_requests(), [],
        "Check to see if no requests initially are ready")
    run_tests.compare_answer(
        len(pending_request_queue.pending_requests), 2,
        "Check to see if both requests are still there initially")

    #Supply 1
    pending_request_queue.process_supplied_resource(supplied_resource_1)
    requests = pending_request_queue.get_ready_to_be_handled_requests()
    run_tests.compare_answer(
        len(requests), 1,
        "Check to see one request is ready after first supply")
    run_tests.compare_answer(requests[0].request_message, "req_msg2",
                             "Check to see if correct message is ready req1")
    run_tests.compare_answer(
        len(pending_request_queue.pending_requests), 1,
        "Check to see if last request is still there after first supply")

    #Supply 2_1
    pending_request_queue.process_supplied_resource(supplied_resource_2_1)
    requests = pending_request_queue.get_ready_to_be_handled_requests()
    run_tests.compare_answer(
        len(requests), 0,
        "Check to see if zero requests are ready after second supply")
    run_tests.compare_answer(
        len(pending_request_queue.pending_requests), 1,
        "Check to see if last request is still there after second supply")

    #Supply 2_2
    pending_request_queue.process_supplied_resource(supplied_resource_2_2)
    requests = pending_request_queue.get_ready_to_be_handled_requests()
    run_tests.compare_answer(
        len(requests), 1,
        "Check to see one request is ready after third supply")
    run_tests.compare_answer(requests[0].request_message, "req_msg1",
                             "Check to see if correct message is ready req2")
    run_tests.compare_answer(
        len(pending_request_queue.pending_requests), 0,
        "Check to see if no request is still there after third supply")
Beispiel #43
0
def test_to_string():
    [
        run_tests.compare_answer(str(msg_obj), msg_str,
                                 "Check __str__ for " + msg_str)
        for msg_str, msg_obj in MESSAGES
    ]
def test_create_and_delete_object_table():
    run_tests.compare_answer(TestObject.create_table(DBCC), True, "Was able to create the table")
    run_tests.compare_answer(TestObject.delete_table(DBCC), True, "Was able to delete the table")
Beispiel #45
0
def test_from_unix_timestamp_to_datetime():
    unix_ts = 687702610010
    dt = support.from_unix_timestamp_ms_to_datetime(unix_ts)

    run_tests.compare_answer(dt.microsecond, 10000, "microsecond")
    run_tests.compare_answer(dt.second, 10,"second")
    run_tests.compare_answer(dt.minute, 30,"minute")
    run_tests.compare_answer(dt.hour, 12,"hour")
    run_tests.compare_answer(dt.day, 17,"day")
    run_tests.compare_answer(dt.month, 10,"month")
    run_tests.compare_answer(dt.year, 1991,"year")
def test_to_string():
    [run_tests.compare_answer( str(msg_obj)
                             , msg_str
                             , "Check __str__ for " + msg_str
                             ) for msg_str, msg_obj in MESSAGES]
def test_first_complete_message_ends_at():
    [run_tests.compare_answer( mobaas_protocol.first_complete_message_ends_at(msg_str)
                             , len(msg_str) - 1
                             , "Check first_complete_message_ends_at for " + msg_str
                             ) for msg_str, _ in MESSAGES]