Commit 342b740f authored by fabian serin's avatar fabian serin
Browse files

Bug when loading some data liberated from techlog with specific ID

parent 3c977a3f
......@@ -59,6 +59,7 @@ BSD-2-Clause
========================================================================
The following software have components provided under the terms of this license:
- colorama (from https://github.com/tartley/colorama)
- grpcio (from https://grpc.io)
- locket (from http://github.com/mwilliamson/locket.py)
- mock (from https://github.com/testing-cabal/mock)
......@@ -81,6 +82,7 @@ The following software have components provided under the terms of this license:
- asgiref (from http://github.com/django/asgiref/)
- click (from http://github.com/mitsuhiko/click)
- cloudpickle (from https://github.com/cloudpipe/cloudpickle)
- colorama (from https://github.com/tartley/colorama)
- cryptography (from https://github.com/pyca/cryptography)
- dask (from http://github.com/dask/dask/)
- decorator (from https://github.com/micheles/decorator)
......
......@@ -10,15 +10,6 @@ DELFI_SOURCE = "delfi_source_entity"
class ConverterUtils:
@staticmethod
def decode_id(osdu_id: str) -> str:
"""
decode osdu style id to delfi id
"""
if osdu_id is None:
return None
return bytes.fromhex(osdu_id.split(":")[2]).decode()
@staticmethod
def fix_id(delfi_id: str, osdu_type: str) -> str:
if delfi_id is None:
......
......@@ -10,7 +10,6 @@ OSDU_WELL_REGEX = re.compile(r'^[\w\-\.]+:master-data\-\-Well:[\w\-\.\:\%]+$')
OSDU_WELLLOG_VERSION_REGEX = re.compile(r'^([\w\-\.]+:work-product-component\-\-WellLog:[\w\-\.\:\%]+):([0-9]*)$')
OSDU_WELLBORETRAJECTORY_VERSION_REGEX = re.compile(r'^([\w\-\.]+:work-product-component\-\-WellboreTrajectory:[\w\-\.\:\%]+):([0-9]*)$')
OSDU_WELLBOREMARKERSET_VERSION_REGEX = re.compile(r'^([\w\-\.]+:work-product-component\-\-WellboreMarkerSet:[\w\-\.\:\%]+):([0-9]*)$')
DELFI_REGEX = re.compile(r'^[\w\-\.]+:[\w\-\.]+:[\w\-\.]+$')
class DMSV3RouterUtils:
@staticmethod
......@@ -47,15 +46,3 @@ class DMSV3RouterUtils:
@staticmethod
def is_osdu_versionned_well_id(entity_id: str) -> Tuple[bool, str, str]:
return DMSV3RouterUtils.is_osdu_versionned_entity_id(OSDU_WELL_VERSION_REGEX, entity_id)
@staticmethod
def is_delfi_id(entity_id: str) -> bool:
return DELFI_REGEX.match(entity_id) is not None
@staticmethod
def is_osdu_entity_fake_id(entity_id: str) -> Tuple[bool, str]:
try:
delfi_id = ConverterUtils.decode_id(entity_id)
return DMSV3RouterUtils.is_delfi_id(delfi_id), delfi_id
except (ValueError, LookupError):
return False, None
......@@ -53,9 +53,6 @@ async def get_osdu_well(wellid: str, ctx: Context) -> Well:
async def get_well_osdu(
wellid: str, ctx: Context = Depends(get_ctx)
) -> Well:
fake_id, _ = DMSV3RouterUtils.is_osdu_entity_fake_id(wellid)
if fake_id:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Id is not OSDU Well")
is_osdu_versioned, osdu_id, version = DMSV3RouterUtils.is_osdu_versionned_well_id(wellid)
if is_osdu_versioned:
return await get_osdu_well(osdu_id, ctx)
......
......@@ -54,9 +54,6 @@ async def get_osdu_wellbore(wellboreid: str, ctx: Context) -> Wellbore:
async def get_wellbore_osdu(
wellboreid: str, ctx: Context = Depends(get_ctx)
) -> Wellbore:
fake_id, _ = DMSV3RouterUtils.is_osdu_entity_fake_id(wellboreid)
if fake_id:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Id is not OSDU Wellbore")
is_osdu_versionned, osdu_id, version = DMSV3RouterUtils.is_osdu_versionned_wellbore_id(wellboreid)
if is_osdu_versionned:
return await get_osdu_wellbore(osdu_id, ctx)
......
......@@ -109,12 +109,3 @@ def test_crud_get_as_record(delfi_id, kind, with_wdms_env):
# Get it as osdu wellbore with delfi id
result = build_request(f'crud.osdu_{kind}.get_osdu_{kind}').call(with_wdms_env)
result.assert_status_code(400)
# Get it as osdu wellbore with fake osdu id
id_as_list = delfi_record_id.split(sep=":")
encoded_str = delfi_record_id.encode().hex()
res_as_list = [id_as_list[0], f"master-data--{kind.capitalize()}", encoded_str, ""]
fakeid = ":".join(res_as_list)
with_wdms_env.set(f'osdu_{kind}_record_id', fakeid) # stored the record id for the following tests
result = build_request(f'crud.osdu_{kind}.get_osdu_{kind}').call(with_wdms_env)
result.assert_status_code(400)
......@@ -142,13 +142,13 @@ getas_parameters = [
(Wellbore, "/ddms/v3/wellbores", r"../../converter/wellbore_wks.json", "opendes:wellbore:12345",
status.HTTP_400_BAD_REQUEST),
(Wellbore, "/ddms/v3/wellbores", r"../../converter/wellbore_wks.json",
"opendes:master-data--Wellbore:6f70656e6465733a646f633a3132333435:", status.HTTP_400_BAD_REQUEST),
"opendes:master-data--Wellbore:6f70656e6465733a646f633a3132333435:", status.HTTP_422_UNPROCESSABLE_ENTITY),
(Wellbore, "/ddms/v3/wellbores", r"../../../../app/model_examples/wellbore_v3.json",
"opendes:master-data--Wellbore:123", status.HTTP_200_OK),
(Well, "/ddms/v3/wells", r"../../converter/well_wks.json", "opendes:well:12345",
status.HTTP_400_BAD_REQUEST),
(Well, "/ddms/v3/wells", r"../../converter/well_wks.json",
"opendes:master-data--Well:6f70656e6465733a646f633a3132333435:", status.HTTP_400_BAD_REQUEST),
"opendes:master-data--Well:6f70656e6465733a646f633a3132333435:", status.HTTP_422_UNPROCESSABLE_ENTITY),
(Well, "/ddms/v3/wells", r"../../../../app/model_examples/well_v3.json", "opendes:master-data--Well:12345:456",
status.HTTP_200_OK),
]
......
Markdown is supported
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