Commit 36a8a534 authored by Niall McDaid's avatar Niall McDaid
Browse files

Fix 405 error - now functional

No tests have been added yet
parent b5197359
......@@ -26,6 +26,6 @@ def welllog(welllog_id: str, url: str, token: str, config_path: str, curve_famil
if curve_families:
logger.info("Recognizing curve families and updating well log record.")
service.update_log_family(welllog_id, config.data_partition_id)
logger.warning("Curve families recognized and updated.")
logger.warning(f"Curve families recognized and updated for well log: {welllog_id}")
else:
logger.warning("No updates made - set command option 'curve_families' to True to update curve families.")
......@@ -61,29 +61,19 @@ class OsduClient:
record = wellbore_record.to_record() if isinstance(wellbore_record, WellboreRecord) else wellbore_record
return self._post_data_with_id_response("/api/os-wellbore-ddms/ddms/v3/wellbores", record)
def create_welllog(self, welllog_record: Union[Record, WellLogRecord]) -> list[any]:
def post_welllog(self, welllog_record: Union[Record, WellLogRecord]) -> list[any]:
"""
Make a post request to OSDU to create a new well log record.
Make a post request to OSDU to create a new or update an existing well log record.
If the `welllog_record` contains an `id` attribute, the well log with that ID shall be updated.
If the `welllog_record` does not contain an `id` attribute, a new record will be created.
:param Union[Record, WellLogRecord] welllog_record: The welllog record to be uploaded
:return: the id of the new well log
:param Union[Record, WellLogRecord] welllog_record: The well log record to be uploaded.
:return: The ID of the created/updated well log
:rtype: list[any]
"""
record = welllog_record.to_record() if isinstance(welllog_record, WellLogRecord) else welllog_record
return self._post_data_with_id_response("/api/os-wellbore-ddms/ddms/v3/welllogs", record)
def update_welllog(self, welllog_id: str, welllog_record: Union[Record, WellLogRecord]) -> list[any]:
"""
Make a post request to OSDU to update an existing well log record.
:param str welllog_id: The ID of the well log to be updated
:param Union[Record, WellLogRecord] welllog_record: The welllog record to overwrite the existing one
:return: The ID of the well log
:rtype: list[any]
"""
record = welllog_record.to_record() if isinstance(welllog_record, WellLogRecord) else welllog_record
return self._post_data_with_id_response(f"/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}", record)
def get_wellbore_record(self, wellbore_id: str) -> WellboreRecord:
"""
Make a get request to OSDU to retreive an existing wellbore record.
......
from dataclasses import dataclass
from typing import Union
from typing import Union, Optional
import urllib
import lasio
from knack.log import get_logger
......@@ -17,6 +17,7 @@ class Record:
acl: dict[str, list[str]]
legal: dict[str, Union[list[str], str]]
data: dict[str, any]
id: Optional[str] = None
class WellboreRecord(Record):
......@@ -27,6 +28,7 @@ class WellboreRecord(Record):
self.data = data.get("data", {})
self.acl = data.get("acl", {})
self.legal = data.get("legal", {})
self.id = data.get("id", None)
self._raw_data = data
......@@ -44,7 +46,7 @@ class WellboreRecord(Record):
:returns: A new instance of Record populated with data from this object
:rtype: Record
"""
return Record(self.kind, self.acl, self.legal, self.data)
return Record(self.kind, self.acl, self.legal, self.data, self.id)
class WellLogRecord(Record):
......@@ -55,6 +57,7 @@ class WellLogRecord(Record):
self.data = data.get("data", {})
self.acl = data.get("acl", {})
self.legal = data.get("legal", {})
self.id = data.get("id", None)
self._raw_data = data
......@@ -81,7 +84,7 @@ class WellLogRecord(Record):
:returns: A new instance of Record populated with data from this object
:rtype: Record
"""
return Record(self.kind, self.acl, self.legal, self.data)
return Record(self.kind, self.acl, self.legal, self.data, self.id)
class AttributeBuilder:
......
......@@ -91,7 +91,7 @@ class WellLogService:
enriched_welllog_record = self.recognize_log_family(welllog_record.to_record(), data_partition_id)
logger.info("Updating existing well log record with recognized curve families.")
self._client.update_welllog(welllog_id, enriched_welllog_record)
self._client.post_welllog(enriched_welllog_record)
def ingest_welllog_data(self, input_path: str, welllog_id: str) -> None:
"""
......@@ -215,7 +215,7 @@ class WellBoreService:
logger.warning("Recognizing the curve families")
enriched_welllog_record = self._well_log_service.recognize_log_family(welllog_record, data_partition_id)
welllog_ids = self._client.create_welllog(enriched_welllog_record)
welllog_ids = self._client.post_welllog(enriched_welllog_record)
logger.warning(f"New welllog IDs: {welllog_ids}")
welllog_id = self._safe_get_first_record(welllog_ids)
......
......@@ -105,7 +105,7 @@ class TestOsduClient:
client = OsduClient(base_url, self._access_token, self._data_partition_id)
# Act
response = client.create_welllog(record)
response = client.post_welllog(record)
# Assert
assert response == self._expected_ids
......@@ -123,7 +123,7 @@ class TestOsduClient:
# Act
with pytest.raises(LasLoaderWebResponseError) as ex:
client.create_welllog(record)
client.post_welllog(record)
# Assert
assert "500" in str(ex.value)
......
......@@ -126,7 +126,7 @@ class TestWellLogService:
{"CurveID": "ABC", "CurveUnit": "opendes:reference-data--UnitOfMeasure:M:"},
{"CurveID": "LMN", "CurveUnit": "opendes:reference-data--UnitOfMeasure:Ft:"},
{"CurveID": "XYZ", "CurveUnit": "opendes:reference-data--UnitOfMeasure:GAPI:"}]
}
}
welllog = Record("LogKind", {}, {}, logdata)
wellbore = WellboreRecord({"data": {"FacilityName": "Well name", "NameAliases": [{"AliasName": "Some Name"}]}})
......@@ -173,7 +173,7 @@ class TestWellLogService:
{"CurveID": "ABC", "CurveUnit": "opendes:reference-data--UnitOfMeasure:M:"},
{"CurveID": "LMN", "CurveUnit": "opendes:reference-data--UnitOfMeasure:Ft:"},
{"CurveID": "XYZ", "CurveUnit": "opendes:reference-data--UnitOfMeasure:GAPI:"}]
}
}
welllog = Record("LogKind", {}, {}, logdata)
data = DataFrame({"ABC": [1, 2, 3], "XYZ": [9, 8, 7], "IJK": [-1, -2, -3]})
......@@ -236,7 +236,7 @@ class TestWellBoreService:
mock_client.create_wellbore.return_value = well_bore_ids
mock_client.get_wellbore_record.return_value = well_bore_record
mock_client.create_welllog.return_value = well_log_ids
mock_client.post_welllog.return_value = well_log_ids
mock_client.get_welllog_record.return_value = well_log_record_returned
mock_well_log_service.recognize_log_family.return_value = well_log_record_recognized
......@@ -254,10 +254,10 @@ class TestWellBoreService:
if no_recognize:
mock_well_log_service.recognize_log_family.assert_not_called()
mock_client.create_welllog.called_once_with(well_log_record)
mock_client.post_welllog.called_once_with(well_log_record)
else:
mock_well_log_service.recognize_log_family.called_once_with(well_log_record, data_partition_id)
mock_client.create_welllog.called_once_with(well_log_record_recognized)
mock_client.post_welllog.called_once_with(well_log_record_recognized)
mock_client.get_welllog_record.called_once_with(well_log_ids[0])
mock_mapper.extract_log_data.called_once()
......
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