Commit 2e64dc73 authored by Yan Sushchynski (EPAM)'s avatar Yan Sushchynski (EPAM)
Browse files

GONRG-2147: Fix double colon in refs

parent 4ec0892f
Pipeline #36435 passed with stages
in 9 minutes and 10 seconds
......@@ -97,8 +97,11 @@ class EntityNode(object):
content = json.dumps(self.content)
for parent in self.parents:
if parent.system_srn:
# ':' at the end is for showing that it is reference.
content = content.replace(parent.srn, f"{parent.system_srn}:")
# ':' at the end is for showing that it is reference if parent srn was surrogate-key.
if "surrogate-key" in parent.system_srn:
content = content.replace(parent.srn, f"{parent.system_srn}:")
else:
content = content.replace(parent.srn, f"{parent.system_srn}")
self.content = json.loads(content)
......
......@@ -86,7 +86,10 @@ class TestManifestAnalyzer(object):
return manifest_analyzer
def process_entity(self, entity: EntityNode) -> str:
return f"system_srn: {entity.srn}"
if "surrogate-key" in entity.srn:
return f"system_srn: {entity.srn}"
else:
return entity.srn
def index_in_queue_by_srn(
self,
......@@ -200,3 +203,50 @@ class TestManifestAnalyzer(object):
logger.info(f"Processed entities: {manifest_analyzer.processed_entities}")
logger.info(f"Unprocessed entities {manifest_analyzer.unprocessed_entities}")
assert "surrogate-key:wpc-1" in (e.srn for e in manifest_analyzer.unprocessed_entities)
@pytest.mark.parametrize(
"manifest,expected_replaced_srns",
[
pytest.param(
[
{
"id": "surrogate-key:wpc",
"ref": "surrogate-key:wpc2"
},
{
"id": "surrogate-key:wpc2"
}
],
"system_srn: surrogate-key:wpc2:",
id="Surrogate key"
),
pytest.param(
[
{
"id": "surrogate-key:wpc",
"ref": "osdu:reference-data--ResourceSecurityClassification:RESTRICTED:test:"
},
{
"id": "osdu:reference-data--ResourceSecurityClassification:RESTRICTED:test"
}
],
"osdu:reference-data--ResourceSecurityClassification:RESTRICTED:test:",
id="Real Ids"
)
]
)
def test_update_parent_srn_with_system_srn(self, manifest, expected_replaced_srns):
data = [ManifestEntity(entity=e, schema="") for e in manifest]
token_refresher = AirflowTokenRefresher()
manifest_analyzer = ManifestAnalyzer(
data,
token_refresher
)
for entity in manifest_analyzer.entity_queue():
entity.replace_parents_surrogate_srns()
entity.system_srn = self.process_entity(entity)
if entity.content.get("ref"):
assert entity.content["ref"] == expected_replaced_srns
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment