def test_validate_mapping_file(): """Test operation to validate the mapping file.""" valid_mapping_file = 'tests/assets/example_csv_mapping.json' valid_config = validate_mapping_configuration(valid_mapping_file) assert valid_config is not None invalid_mapping_file = 'tests/assets/empty_file.json' invalid_config = validate_mapping_configuration(invalid_mapping_file) assert invalid_config is None
def test_build_insert_sql(): """Test the build_insert_sql function.""" table_name = 'some_table' mapping_configuration = validate_mapping_configuration( 'tests/assets/example_csv_mapping.json') list_of_tuples = [('a', 5, 4, 3.0, 2.0, 1.0), ('g', 7, 8, 9.0, 10.0, 11.0)] result = build_insert_sql(table_name, mapping_configuration, list_of_tuples) assert result == 'INSERT INTO some_table (blah,blah2,blah3,blah4,blah5,blah6) VALUES' \ ' (\'a\', 5, 4, 3.0, 2.0, 1.0), (\'g\', 7, 8, 9.0, 10.0, 11.0)'
def test_build_insert_sql_reversed_input(): """Test the build_insert_sql function and remapping process.""" table_name = 'some_table' mapping_configuration = validate_mapping_configuration( 'tests/assets/reverse_csv_mapping.json') list_of_tuples = [('f', 6, 7, 8.0, 9.0, 10.0), ('l', 20, 21, 22.0, 23.0, 24.1)] result = build_insert_sql(table_name, mapping_configuration, list_of_tuples) assert result == 'INSERT INTO some_table (blah,blah2,blah3,blah4,blah5,blah6) VALUES' \ ' (10.0, 9.0, 8.0, 7, 6, \'f\'), (24.1, 23.0, 22.0, 21, 20, \'l\')'
def test_reordered_csv_mapping(): """Test the build_insert_sql function and remapping process.""" table_name = 'some_table' # Semantically file contents are similar to the reverse file, column data was shuffled # in the JSON config # Results of test should be the same. mapping_configuration = \ validate_mapping_configuration('tests/assets/reordered_csv_mapping.json') list_of_tuples = [('f', 6, 7, 8.0, 9.0, 10.0), ('l', 20, 21, 22.0, 23.0, 24.1)] result = build_insert_sql(table_name, mapping_configuration, list_of_tuples) assert result == 'INSERT INTO some_table (blah,blah2,blah3,blah4,blah5,blah6) VALUES' \ ' (10.0, 9.0, 8.0, 7, 6, \'f\'), (24.1, 23.0, 22.0, 21, 20, \'l\')'
def test_validate_single_tuple_bad_tuple(): """Confirm function to validate a tuple fails when given a bad tuple.""" mapping_configuration = validate_mapping_configuration( 'tests/assets/mapping_one_of_each.json') single_tuple = ('2245-08-29', 'Pizza', 2.73, 888) assert not validate_single_tuple(single_tuple, mapping_configuration)
def test_validate_single_tuple(): """Test function to validate a single tuple.""" mapping_configuration = validate_mapping_configuration( 'tests/assets/mapping_one_of_each.json') single_tuple = ('Pizza', 6667, '2245-08-29', 2.73) assert validate_single_tuple(single_tuple, mapping_configuration)
def test_validate_tuple_data_with_bad_data(): """Call validate_tuple_data using bad data.""" mapping_config = validate_mapping_configuration( 'tests/assets/mapping_one_of_each.json') all_tuples = [('String', '2017-09-04', 1234, 3.1415)] assert not validate_tuple_data(all_tuples, mapping_config)
def test_validate_tuple_data(): """Test function to validate the tuple data.""" mapping_config = validate_mapping_configuration( 'tests/assets/mapping_one_of_each.json') all_tuples = [('String', 1234, '2017-09-04', 3.1415)] assert validate_tuple_data(all_tuples, mapping_config)