Skip to content

Commit

Permalink
Update migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Karpets committed Nov 29, 2023
1 parent 3c4c1b3 commit 39f6885
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,10 @@ def _should_migrate(cls, config: Mapping[str, Any]) -> bool:
@classmethod
def _transform_report_options(cls, config: Mapping[str, Any]) -> Mapping[str, Any]:
try:
report_options = json.loads(config.get("report_options", ""))
report_options = json.loads(config.get("report_options", "{}") or "{}")
except json.JSONDecodeError:
report_options = {}

try:
advanced_stream_options = json.loads(config.get("advanced_stream_options", ""))
except json.JSONDecodeError:
advanced_stream_options = {}

report_options.update(advanced_stream_options)
report_options_list = []
for stream_name, options in report_options.items():
options_list = [{"option_name": name, "option_value": value} for name, value in options.items()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,9 @@ class TestMigrateReportOptions:
{"report_options": "{\"GET_REPORT\": {\"reportPeriod\": \"WEEK\"}}"},
[{"stream_name": "GET_REPORT", "options_list": [{"option_name": "reportPeriod", "option_value": "WEEK"}]}],
),
(
{"advanced_stream_options": "{\"GET_REPORT\": {\"reportPeriod\": \"WEEK\"}}"},
[{"stream_name": "GET_REPORT", "options_list": [{"option_name": "reportPeriod", "option_value": "WEEK"}]}],
),
(
{
"report_options": "{\"GET_REPORT\": {\"reportPeriod\": \"WEEK\"}}",
"advanced_stream_options": "{\"GET_REPORT_2\": {\"reportPeriod_2\": \"DAY\"}}",
},
[
{"stream_name": "GET_REPORT", "options_list": [{"option_name": "reportPeriod", "option_value": "WEEK"}]},
{"stream_name": "GET_REPORT_2", "options_list": [{"option_name": "reportPeriod_2", "option_value": "DAY"}]},
],
),
(
{
"report_options": "{\"GET_REPORT\": {\"reportPeriod\": \"WEEK\"}}",
"advanced_stream_options": "{\"GET_REPORT\": {\"reportPeriod\": \"DAY\"}}",
},
[{"stream_name": "GET_REPORT", "options_list": [{"option_name": "reportPeriod", "option_value": "DAY"}]}],
),
({"report_options": None}, []),
({"report_options": "{{}"}, []),
({}, []),
),
)
def test_transform_report_options(self, input_config, expected_report_options_list):
Expand All @@ -92,7 +74,6 @@ def test_migrate_config(self, capsys):
migrated_config = control_msg["control"]["connectorConfig"]["config"]
expected_report_options_list = [
{"stream_name": "GET_REPORT", "options_list": [{"option_name": "reportPeriod", "option_value": "WEEK"}]},
{"stream_name": "GET_REPORT_2", "options_list": [{"option_name": "reportPeriod_2", "option_value": "DAY"}]},
]
assert migrated_config["report_options_list"] == expected_report_options_list

Expand Down

0 comments on commit 39f6885

Please sign in to comment.