Debian Codegraph @

azure-kusto-ingest/tests/test_ingestion_properties.py

raw
1 import pytest
2
3 from azure.kusto.data.data_format import IngestionMappingKind, DataFormat
4 from azure.kusto.ingest import IngestionProperties, ColumnMapping, TransformationMethod
5 from azure.kusto.ingest.exceptions import KustoDuplicateMappingError, KustoMissingMappingError, KustoMappingError
6
7
8 def test_duplicate_reference_and_column_mappings_raises():
9 """Tests invalid ingestion properties."""
10 with pytest.raises(KustoDuplicateMappingError):
11 IngestionProperties(
12 database="database", table="table", column_mappings=[ColumnMapping("test", "int")], ingestion_mapping_reference="ingestionMappingReference"
13 )
14
15
16 def test_mapping_kind_without_mapping_raises():
17 with pytest.raises(KustoMissingMappingError):
18 IngestionProperties(database="database", table="table", ingestion_mapping_kind=IngestionMappingKind.CSV)
19
20
21 def test_mapping_kind_data_format_mismatch():
22 with pytest.raises(KustoMappingError):
23 IngestionProperties(
24 database="database",
25 table="table",
26 ingestion_mapping_reference="ingestionMappingReference",
27 data_format=DataFormat.JSON,
28 ingestion_mapping_kind=IngestionMappingKind.CSV,
29 )
30
31
32 def test_mapping_kind_data_format_invalid_no_name():
33 with pytest.raises(KustoMappingError):
34 IngestionProperties(
35 database="database",
36 table="table",
37 column_mappings=[ColumnMapping("", "int")],
38 data_format=DataFormat.JSON,
39 ingestion_mapping_kind=IngestionMappingKind.JSON,
40 )
41
42
43 def test_mapping_kind_data_format_invalid_no_path():
44 with pytest.raises(KustoMappingError):
45 IngestionProperties(
46 database="database",
47 table="table",
48 column_mappings=[ColumnMapping("test", "int")],
49 data_format=DataFormat.JSON,
50 ingestion_mapping_kind=IngestionMappingKind.JSON,
51 )
52
53
54 def test_mapping_kind_data_format_with_path():
55 IngestionProperties(
56 database="database",
57 table="table",
58 column_mappings=[ColumnMapping("test", "int", "path")],
59 data_format=DataFormat.JSON,
60 ingestion_mapping_kind=IngestionMappingKind.JSON,
61 )
62
63
64 def test_mapping_kind_data_format_with_transform():
65 IngestionProperties(
66 database="database",
67 table="table",
68 column_mappings=[ColumnMapping("test", "int", transform=TransformationMethod.SOURCE_LINE_NUMBER)],
69 data_format=DataFormat.JSON,
70 ingestion_mapping_kind=IngestionMappingKind.JSON,
71 )
72
73
74 def test_mapping_kind_data_format_with_no_properties():
75 with pytest.raises(KustoMappingError):
76 IngestionProperties(
77 database="database",
78 table="table",
79 column_mappings=[ColumnMapping("test", "int")],
80 data_format=DataFormat.AVRO,
81 ingestion_mapping_kind=IngestionMappingKind.AVRO,
82 )
83
84
85 def test_with_constant_value():
86 IngestionProperties(
87 database="database",
88 table="table",
89 column_mappings=[ColumnMapping("test", "int", const_value="1")],
90 data_format=DataFormat.PARQUET,
91 ingestion_mapping_kind=IngestionMappingKind.PARQUET,
92 )