Exemplo n.º 1
0
def test_create_csv_file(data_object: Data, descending, army_time, start_date,
                         expected_file_to_match):
    """
    Test create CSV file functionality.
    :param data_object: Data object to leverage to test this function.
    :param descending: Boolean that decides whether values in CSV are in descending format or not.
    :param army_time: Boolean that dictates whether dates will be written in army-time format or not.
    :param start_date: Date to have CSV data from.
    """
    remove_test_data()
    data_object.create_table()

    insert_test_data_to_database()
    data_object.data = data_object.get_data_from_database()

    start_date = parser.parse(start_date).date()

    path = data_object.create_csv_file(descending=descending,
                                       army_time=army_time,
                                       start_date=start_date)
    path_to_equal = os.path.join(ROOT_DIR, 'tests', 'data',
                                 'test_create_csv_file_data',
                                 expected_file_to_match)

    assert filecmp.cmp(path, path_to_equal)
Exemplo n.º 2
0
def test_get_data_from_database(data_object: Data):
    """
    Test to ensure get data from database works appropriately.
    :param data_object: Data object to leverage to test this function.
    """
    normalized_csv_data = get_normalized_csv_data()

    remove_test_data()
    data_object.create_table()
    data_object.dump_to_table(normalized_csv_data)
    result = data_object.get_data_from_database()

    # Reverse because data is in ascending order whereas CSV data is not.
    assert normalized_csv_data == result, "Expected data to equal."