-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
136 additions
and
30 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
src/python/data_factory_testing_framework/exceptions/activity_not_found_exception.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,3 @@ | ||
class ActivityNotFoundException(Exception): | ||
def __init__(self, activity_name): | ||
super().__init__(f"Activity with name {activity_name} not found") |
4 changes: 4 additions & 0 deletions
4
src/python/data_factory_testing_framework/exceptions/pipeline_not_found_exception.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,4 @@ | ||
class PipelineNotFoundException(Exception): | ||
def __init__(self, pipeline_name): | ||
super().__init__(f"Pipeline with name {pipeline_name} not found") | ||
|
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
4 changes: 2 additions & 2 deletions
4
src/python/data_factory_testing_framework/models/base/run_parameter.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,12 +1,12 @@ | ||
from typing import TypeVar, Generic | ||
|
||
from data_factory_testing_framework.models.base.parameter_type import ParameterType | ||
from data_factory_testing_framework.models.base.run_parameter_type import RunParameterType | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
class RunParameter(Generic[T]): | ||
def __init__(self, type: ParameterType, name: str, value: T): | ||
def __init__(self, type: RunParameterType, name: str, value: T): | ||
self.type = type | ||
self.name = name | ||
self.value = value |
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
31 changes: 31 additions & 0 deletions
31
src/python/data_factory_testing_framework/models/pipelines/pipeline_resource.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,31 @@ | ||
from typing import List | ||
|
||
from data_factory_testing_framework.exceptions.activity_not_found_exception import ActivityNotFoundException | ||
from data_factory_testing_framework.generated.models import PipelineResource, Activity | ||
from data_factory_testing_framework.models.base.run_parameter import RunParameter | ||
|
||
|
||
class PipelineResource: | ||
def get_activity_by_name(self: PipelineResource, name: str) -> Activity: | ||
for activity in self.activities: | ||
if activity.name == name: | ||
return activity | ||
|
||
raise ActivityNotFoundException(f"Activity with name {name} not found") | ||
|
||
def validate_parameters(self: PipelineResource, parameters: List[RunParameter]): | ||
# Check if all parameters are provided | ||
for pipeline_parameter_name, pipeline_parameter_specification in self.parameters.items(): | ||
found = False | ||
for parameter in parameters: | ||
if pipeline_parameter_name == parameter.name and pipeline_parameter_specification.type == parameter.type: | ||
found = True | ||
break | ||
|
||
if not found: | ||
raise ValueError(f"Parameter with name '{pipeline_parameter_name}' and type '{pipeline_parameter_specification.type}' not found in pipeline '{self.name}'") | ||
|
||
# Check if no duplicate parameters are provided | ||
for parameter in parameters: | ||
if sum(1 for p in parameters if p.name == parameter.name and p.type == parameter.type) > 1: | ||
raise ValueError(f"Duplicate parameter with name '{parameter.name}' and type '{parameter.type}' found in pipeline '{self.name}'") |
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
65 changes: 65 additions & 0 deletions
65
src/python/tests/models/pipelines/test_pipeline_resource.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,65 @@ | ||
import pytest | ||
|
||
from data_factory_testing_framework.generated.models import PipelineResource, ParameterSpecification | ||
from data_factory_testing_framework.models.base.run_parameter_type import RunParameterType | ||
from data_factory_testing_framework.models.base.run_parameter import RunParameter | ||
from data_factory_testing_framework.models.test_framework import TestFramework | ||
|
||
TestFramework() | ||
|
||
class TestPipeline: | ||
def test_when_validate_parameters_is_accurate_should_pass(self): | ||
# Arrange | ||
pipeline = PipelineResource( | ||
name="pipeline", | ||
parameters={ | ||
"pipelineParameterName": ParameterSpecification(type=RunParameterType.Pipeline), | ||
"pipelineParameterName2": ParameterSpecification(type=RunParameterType.Pipeline) | ||
} | ||
) | ||
|
||
# Act | ||
pipeline.validate_parameters([ | ||
RunParameter(RunParameterType.Pipeline, "pipelineParameterName", "pipelineParameterValue"), | ||
RunParameter(RunParameterType.Pipeline, "pipelineParameterName2", "pipelineParameterValue2") | ||
]) | ||
|
||
def test_when_validate_parameters_is_missing_run_parameter_should_throw_error(self): | ||
# Arrange | ||
pipeline = PipelineResource( | ||
parameters={ | ||
"pipelineParameterName": ParameterSpecification(type=RunParameterType.Pipeline), | ||
"pipelineParameterName2": ParameterSpecification(type=RunParameterType.Pipeline) | ||
} | ||
) | ||
pipeline.name = "pipeline" | ||
|
||
# Act | ||
with pytest.raises(ValueError) as exception_info: | ||
pipeline.validate_parameters([ | ||
RunParameter(RunParameterType.Pipeline, "pipelineParameterName", "pipelineParameterValue"), | ||
]) | ||
|
||
# Assert | ||
assert exception_info.value.args[0] == "Parameter with name 'pipelineParameterName2' and type 'RunParameterType.Pipeline' not found in pipeline 'pipeline'" | ||
|
||
def test_when_duplicate_parameters_supplied_should_throw_error(self): | ||
# Arrange | ||
pipeline = PipelineResource( | ||
parameters={ | ||
"pipelineParameterName": ParameterSpecification(type=RunParameterType.Pipeline), | ||
"pipelineParameterName2": ParameterSpecification(type=RunParameterType.Pipeline) | ||
} | ||
) | ||
pipeline.name = "pipeline" | ||
|
||
# Act | ||
with pytest.raises(ValueError) as exception_info: | ||
pipeline.validate_parameters([ | ||
RunParameter(RunParameterType.Pipeline, "pipelineParameterName", "pipelineParameterValue"), | ||
RunParameter(RunParameterType.Pipeline, "pipelineParameterName", "pipelineParameterValue"), | ||
RunParameter(RunParameterType.Pipeline, "pipelineParameterName2", "pipelineParameterValue2") | ||
]) | ||
|
||
# Assert | ||
assert exception_info.value.args[0] == "Duplicate parameter with name 'pipelineParameterName' and type 'RunParameterType.Pipeline' found in pipeline 'pipeline'" |