2
2
3
3
import pytest
4
4
from sqlalchemy import types
5
- from airbyte_lib .types import SQLTypeConverter
5
+ from airbyte_lib .types import SQLTypeConverter , _get_airbyte_type
6
+
6
7
7
8
@pytest .mark .parametrize (
8
9
"json_schema_property_def, expected_sql_type" ,
9
10
[
10
11
({"type" : "string" }, types .VARCHAR ),
12
+ ({"type" : ["boolean" , "null" ]}, types .BOOLEAN ),
13
+ ({"type" : ["null" , "boolean" ]}, types .BOOLEAN ),
14
+ ({"type" : "string" }, types .VARCHAR ),
15
+ ({"type" : ["null" , "string" ]}, types .VARCHAR ),
11
16
({"type" : "boolean" }, types .BOOLEAN ),
12
17
({"type" : "string" , "format" : "date" }, types .DATE ),
13
18
({"type" : "string" , "format" : "date-time" , "airbyte_type" : "timestamp_without_timezone" }, types .TIMESTAMP ),
@@ -25,3 +30,50 @@ def test_to_sql_type(json_schema_property_def, expected_sql_type):
25
30
converter = SQLTypeConverter ()
26
31
sql_type = converter .to_sql_type (json_schema_property_def )
27
32
assert isinstance (sql_type , expected_sql_type )
33
+
34
+
35
+ @pytest .mark .parametrize (
36
+ "json_schema_property_def, expected_airbyte_type" ,
37
+ [
38
+ ({"type" : "string" }, "string" ),
39
+ ({"type" : ["boolean" , "null" ]}, "boolean" ),
40
+ ({"type" : ["null" , "boolean" ]}, "boolean" ),
41
+ ({"type" : "string" }, "string" ),
42
+ ({"type" : ["null" , "string" ]}, "string" ),
43
+ ({"type" : "boolean" }, "boolean" ),
44
+ ({"type" : "string" , "format" : "date" }, "date" ),
45
+ ({"type" : "string" , "format" : "date-time" , "airbyte_type" : "timestamp_without_timezone" }, "timestamp_without_timezone" ),
46
+ ({"type" : "string" , "format" : "date-time" , "airbyte_type" : "timestamp_with_timezone" }, "timestamp_with_timezone" ),
47
+ ({"type" : "string" , "format" : "time" , "airbyte_type" : "time_without_timezone" }, "time_without_timezone" ),
48
+ ({"type" : "string" , "format" : "time" , "airbyte_type" : "time_with_timezone" }, "time_with_timezone" ),
49
+ ({"type" : "integer" }, "integer" ),
50
+ ({"type" : "number" , "airbyte_type" : "integer" }, "integer" ),
51
+ ({"type" : "number" }, "number" ),
52
+ ({"type" : "array" }, "array" ),
53
+ ({"type" : "object" }, "object" ),
54
+ ],
55
+ )
56
+ def test_to_airbyte_type (json_schema_property_def , expected_airbyte_type ):
57
+ airbyte_type , _ = _get_airbyte_type (json_schema_property_def )
58
+ assert airbyte_type == expected_airbyte_type
59
+
60
+
61
+ @pytest .mark .parametrize (
62
+ "json_schema_property_def, expected_airbyte_type, expected_airbyte_subtype" ,
63
+ [
64
+ ({"type" : "string" }, "string" , None ),
65
+ ({"type" : "number" }, "number" , None ),
66
+ ({"type" : "array" }, "array" , None ),
67
+ ({"type" : "object" }, "object" , None ),
68
+ ({"type" : "array" , "items" : {"type" : ["null" , "string" ]}}, "array" , "string" ),
69
+ ({"type" : "array" , "items" : {"type" : ["boolean" ]}}, "array" , "boolean" ),
70
+ ],
71
+ )
72
+ def test_to_airbyte_subtype (
73
+ json_schema_property_def ,
74
+ expected_airbyte_type ,
75
+ expected_airbyte_subtype ,
76
+ ):
77
+ airbyte_type , subtype = _get_airbyte_type (json_schema_property_def )
78
+ assert airbyte_type == expected_airbyte_type
79
+ assert subtype == expected_airbyte_subtype
0 commit comments