Skip to content

Commit 9d8f76f

Browse files
Merge pull request #14 from DeputyApp/INTS-1482-invalid-json-data-type
INTS-1482 - Support for JSON data types
2 parents c5d368d + 7b4b705 commit 9d8f76f

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

tap_deputy/discover.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
'VarChar': 'string',
6868
'Blob': 'string',
6969
'Bit': 'boolean',
70-
'Time': 'string'
70+
'Time': 'string',
71+
'Json': 'string',
7172
}
7273

7374

tests/test_discover.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import pytest
2+
from unittest.mock import Mock
3+
4+
from tap_deputy.discover import discover, RESOURCES
5+
6+
7+
@pytest.mark.parametrize(
8+
"deputy_type, expected_jsonschema_type",
9+
[
10+
("Integer", ["null", "integer"]),
11+
("Float", ["null", "number"]),
12+
("VarChar", ["null", "string"]),
13+
("Blob", ["null", "string"]),
14+
("Bit", ["null", "boolean"]),
15+
("Time", ["null", "string"]),
16+
("Json", ["null", "string"]),
17+
],
18+
)
19+
def test_discover_simple_type_mappings(deputy_type, expected_jsonschema_type):
20+
"""
21+
Verify that Deputy API field types are correctly mapped to simple
22+
JSON schema types in the generated catalog.
23+
"""
24+
client = Mock()
25+
resource_name = "Employee"
26+
stream_name = RESOURCES[resource_name]
27+
28+
client.get.return_value = {
29+
"fields": {"Id": "Integer", "SomeTestField": deputy_type}
30+
}
31+
32+
catalog = discover(client)
33+
employees_stream = None
34+
for s in catalog.streams:
35+
if s.tap_stream_id == stream_name:
36+
employees_stream = s
37+
38+
assert employees_stream is not None
39+
schema_dict = employees_stream.schema.to_dict()
40+
schema_properties = schema_dict["properties"]
41+
42+
assert "SomeTestField" in schema_properties
43+
field_schema = schema_properties["SomeTestField"]
44+
assert field_schema["type"] == expected_jsonschema_type
45+
46+
47+
@pytest.mark.parametrize("deputy_type", ["Date", "DateTime"])
48+
def test_discover_datetime_type_mapping(deputy_type):
49+
"""
50+
Verify that Deputy API 'Date' and 'DateTime' field types are correctly
51+
mapped to a 'string' with 'date-time' format in the catalog schema.
52+
"""
53+
client = Mock()
54+
resource_name = "Employee"
55+
stream_name = RESOURCES[resource_name]
56+
57+
client.get.return_value = {
58+
"fields": {"Id": "Integer", "SomeDateField": deputy_type}
59+
}
60+
61+
catalog = discover(client)
62+
employees_stream = None
63+
for s in catalog.streams:
64+
if s.tap_stream_id == stream_name:
65+
employees_stream = s
66+
67+
assert employees_stream is not None
68+
schema_dict = employees_stream.schema.to_dict()
69+
schema_properties = schema_dict["properties"]
70+
71+
assert "SomeDateField" in schema_properties
72+
field_schema = schema_properties["SomeDateField"]
73+
assert field_schema["type"] == ["null", "string"]
74+
assert field_schema["format"] == "date-time"

0 commit comments

Comments
 (0)