-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: deserializers to follow dry
- Loading branch information
Showing
5 changed files
with
42 additions
and
42 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/azure_data_factory_testing_framework/deserializers/_deserializer_base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from azure_data_factory_testing_framework.deserializers.shared._activity_deserializer import ( | ||
_get_activity_from_activity_data, | ||
) | ||
from azure_data_factory_testing_framework.deserializers.shared._data_factory_element_replacer import ( | ||
_find_and_replace_expressions_in_dict, | ||
) | ||
from azure_data_factory_testing_framework.models.pipeline import Pipeline | ||
|
||
|
||
def _parse_pipeline_from_json(name: str, json_data: dict) -> Pipeline: | ||
properties = json_data.get("properties", {}) | ||
activities = properties.get("activities", []) | ||
|
||
for activity_data in activities: | ||
activities[activities.index(activity_data)] = _get_activity_from_activity_data(activity_data) | ||
|
||
pipeline = Pipeline(name, **properties) | ||
|
||
_find_and_replace_expressions_in_dict(pipeline) | ||
|
||
return pipeline |
24 changes: 4 additions & 20 deletions
24
src/azure_data_factory_testing_framework/deserializers/_deserializer_data_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,10 @@ | ||
import json | ||
|
||
from azure_data_factory_testing_framework.deserializers.shared._activity_deserializer import ( | ||
_get_activity_from_activity_data, | ||
) | ||
from azure_data_factory_testing_framework.deserializers.shared._data_factory_element_replacer import ( | ||
_find_and_replace_expressions_in_dict, | ||
) | ||
from azure_data_factory_testing_framework.deserializers._deserializer_base import _parse_pipeline_from_json | ||
from azure_data_factory_testing_framework.models.pipeline import Pipeline | ||
|
||
|
||
def parse_pipeline_from_json(json_str: str) -> Pipeline: | ||
json_data = json.loads(json_str) | ||
|
||
def parse_data_factory_pipeline_from_pipeline_json(pipeline_json: str) -> Pipeline: | ||
json_data = json.loads(pipeline_json) | ||
name = json_data["name"] | ||
properties = json_data.get("properties", {}) | ||
activities = properties.get("activities", []) | ||
|
||
for activity_data in activities: | ||
activities[activities.index(activity_data)] = _get_activity_from_activity_data(activity_data) | ||
|
||
pipeline = Pipeline(name, **properties) | ||
|
||
_find_and_replace_expressions_in_dict(pipeline) | ||
|
||
return pipeline | ||
return _parse_pipeline_from_json(name, json_data) |
25 changes: 7 additions & 18 deletions
25
src/azure_data_factory_testing_framework/deserializers/_deserializer_fabric.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,15 @@ | ||
import json | ||
|
||
from azure_data_factory_testing_framework.deserializers.shared._activity_deserializer import ( | ||
_get_activity_from_activity_data, | ||
) | ||
from azure_data_factory_testing_framework.deserializers.shared._data_factory_element_replacer import ( | ||
_find_and_replace_expressions_in_dict, | ||
) | ||
from azure_data_factory_testing_framework.deserializers._deserializer_base import _parse_pipeline_from_json | ||
from azure_data_factory_testing_framework.models.pipeline import Pipeline | ||
|
||
|
||
def parse_pipeline_from_json(metadata_json: str, pipeline_json: str) -> Pipeline: | ||
metadata_json = json.loads(metadata_json) | ||
def parse_fabric_pipeline_from_pipeline_json_files(metadata_json: str, pipeline_json: str) -> Pipeline: | ||
pipeline_name = _get_pipeline_name_from_metadata_json(metadata_json) | ||
pipeline_json = json.loads(pipeline_json) | ||
return _parse_pipeline_from_json(pipeline_name, pipeline_json) | ||
|
||
properties = pipeline_json.get("properties", {}) | ||
activities = properties.get("activities", []) | ||
|
||
for activity_data in activities: | ||
activities[activities.index(activity_data)] = _get_activity_from_activity_data(activity_data) | ||
|
||
pipeline_json = Pipeline(metadata_json["displayName"], **properties) | ||
|
||
_find_and_replace_expressions_in_dict(pipeline_json) | ||
|
||
return pipeline_json | ||
def _get_pipeline_name_from_metadata_json(metadata_json: str) -> str: | ||
metadata_json = json.loads(metadata_json) | ||
return metadata_json["displayName"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters