|
72 | 72 | ExtractOwnersFromTagsTransformer, |
73 | 73 | ) |
74 | 74 | from datahub.ingestion.transformer.mark_dataset_status import MarkDatasetStatus |
| 75 | +from datahub.ingestion.transformer.pattern_cleanup_ownership import ( |
| 76 | + PatternCleanUpOwnership, |
| 77 | +) |
75 | 78 | from datahub.ingestion.transformer.remove_dataset_ownership import ( |
76 | 79 | SimpleRemoveDatasetOwnership, |
77 | 80 | ) |
| 81 | +from datahub.ingestion.transformer.replace_external_url import ReplaceExternalUrl |
78 | 82 | from datahub.metadata.schema_classes import ( |
79 | 83 | BrowsePathsClass, |
80 | 84 | DatasetPropertiesClass, |
|
87 | 91 | ) |
88 | 92 | from datahub.utilities.urns.dataset_urn import DatasetUrn |
89 | 93 | from datahub.utilities.urns.urn import Urn |
90 | | -from src.datahub.ingestion.transformer.pattern_cleanup_ownership import ( |
91 | | - PatternCleanUpOwnership, |
92 | | -) |
93 | 94 |
|
94 | 95 |
|
95 | 96 | def make_generic_dataset( |
@@ -3209,3 +3210,84 @@ def test_clean_owner_urn_transformation_should_not_remove_system_identifier( |
3209 | 3210 | config: List[Union[re.Pattern, str]] = ["urn:li:corpuser:"] |
3210 | 3211 |
|
3211 | 3212 | _test_clean_owner_urns(pipeline_context, in_owner_urns, config, in_owner_urns) |
| 3213 | + |
| 3214 | + |
| 3215 | +def test_replace_external_url_word_replace( |
| 3216 | + mock_datahub_graph, |
| 3217 | +): |
| 3218 | + pipeline_context: PipelineContext = PipelineContext( |
| 3219 | + run_id="test_replace_external_url" |
| 3220 | + ) |
| 3221 | + pipeline_context.graph = mock_datahub_graph(DatahubClientConfig) |
| 3222 | + |
| 3223 | + output = run_dataset_transformer_pipeline( |
| 3224 | + transformer_type=ReplaceExternalUrl, |
| 3225 | + aspect=models.DatasetPropertiesClass( |
| 3226 | + externalUrl="https://github.com/datahub/looker-demo/blob/master/foo.view.lkml", |
| 3227 | + customProperties=EXISTING_PROPERTIES.copy(), |
| 3228 | + ), |
| 3229 | + config={"input_pattern": "datahub", "replacement": "starhub"}, |
| 3230 | + pipeline_context=pipeline_context, |
| 3231 | + ) |
| 3232 | + |
| 3233 | + assert len(output) == 2 |
| 3234 | + assert output[0].record |
| 3235 | + assert output[0].record.aspect |
| 3236 | + assert ( |
| 3237 | + output[0].record.aspect.externalUrl |
| 3238 | + == "https://github.com/starhub/looker-demo/blob/master/foo.view.lkml" |
| 3239 | + ) |
| 3240 | + |
| 3241 | + |
| 3242 | +def test_replace_external_regex_replace_1( |
| 3243 | + mock_datahub_graph, |
| 3244 | +): |
| 3245 | + pipeline_context: PipelineContext = PipelineContext( |
| 3246 | + run_id="test_replace_external_url" |
| 3247 | + ) |
| 3248 | + pipeline_context.graph = mock_datahub_graph(DatahubClientConfig) |
| 3249 | + |
| 3250 | + output = run_dataset_transformer_pipeline( |
| 3251 | + transformer_type=ReplaceExternalUrl, |
| 3252 | + aspect=models.DatasetPropertiesClass( |
| 3253 | + externalUrl="https://github.com/datahub/looker-demo/blob/master/foo.view.lkml", |
| 3254 | + customProperties=EXISTING_PROPERTIES.copy(), |
| 3255 | + ), |
| 3256 | + config={"input_pattern": r"datahub/.*/", "replacement": "starhub/test/"}, |
| 3257 | + pipeline_context=pipeline_context, |
| 3258 | + ) |
| 3259 | + |
| 3260 | + assert len(output) == 2 |
| 3261 | + assert output[0].record |
| 3262 | + assert output[0].record.aspect |
| 3263 | + assert ( |
| 3264 | + output[0].record.aspect.externalUrl |
| 3265 | + == "https://github.com/starhub/test/foo.view.lkml" |
| 3266 | + ) |
| 3267 | + |
| 3268 | + |
| 3269 | +def test_replace_external_regex_replace_2( |
| 3270 | + mock_datahub_graph, |
| 3271 | +): |
| 3272 | + pipeline_context: PipelineContext = PipelineContext( |
| 3273 | + run_id="test_replace_external_url" |
| 3274 | + ) |
| 3275 | + pipeline_context.graph = mock_datahub_graph(DatahubClientConfig) |
| 3276 | + |
| 3277 | + output = run_dataset_transformer_pipeline( |
| 3278 | + transformer_type=ReplaceExternalUrl, |
| 3279 | + aspect=models.DatasetPropertiesClass( |
| 3280 | + externalUrl="https://github.com/datahub/looker-demo/blob/master/foo.view.lkml", |
| 3281 | + customProperties=EXISTING_PROPERTIES.copy(), |
| 3282 | + ), |
| 3283 | + config={"input_pattern": r"\b\w*hub\b", "replacement": "test"}, |
| 3284 | + pipeline_context=pipeline_context, |
| 3285 | + ) |
| 3286 | + |
| 3287 | + assert len(output) == 2 |
| 3288 | + assert output[0].record |
| 3289 | + assert output[0].record.aspect |
| 3290 | + assert ( |
| 3291 | + output[0].record.aspect.externalUrl |
| 3292 | + == "https://test.com/test/looker-demo/blob/master/foo.view.lkml" |
| 3293 | + ) |
0 commit comments