Commit 3a2bcda3 authored by Niall McDaid's avatar Niall McDaid
Browse files

Add test and fix bugs

parent 844a8f37
from knack.log import get_logger
from lasloader.configuration import Configuration
from lasloader.file_loader import LocalFileLoader
from lasloader.osdu_client import OsduClient
from lasloader.osdu_client import LasLoaderWebResponseError, OsduClient
from lasloader.well_service import WellLogService
......@@ -25,7 +25,11 @@ 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)
try:
service.update_log_family(welllog_id, config.data_partition_id)
except LasLoaderWebResponseError as ex:
logger.error(f"Error - record not updated: {str(ex)}")
return
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.")
......@@ -93,7 +93,8 @@ class WellLogService:
logger.info("Updating existing well log record with recognized curve families.")
welllog_ids = self._client.post_welllog(enriched_welllog_record)
wellbore_service = WellBoreService()
# Print out updated record in logging for user to see.
wellbore_service = WellBoreService(self._client, self)
welllog_id = wellbore_service._safe_get_first_record(welllog_ids)
welllog_record = self._client.get_welllog_record(welllog_id)
logger.info(json.dumps(welllog_record.get_raw_data(), indent=4, sort_keys=True))
......
......@@ -320,6 +320,7 @@ class TestWellboreRecord:
assert record.acl == {}
assert record.kind is None
assert record.legal == {}
assert record.id is None
assert record.get_raw_data() == {}
def test_construct_with_populated_dict(self):
......@@ -332,6 +333,7 @@ class TestWellboreRecord:
'acl': {'some': 'acl'},
'kind': 'A Kind',
'legal': {'some': 'legal'},
'id': 'WBID-123'
}
record = WellLogRecord(wellbore)
......@@ -340,6 +342,7 @@ class TestWellboreRecord:
assert record.acl == wellbore['acl']
assert record.kind == wellbore['kind']
assert record.legal == wellbore['legal']
assert record.id == wellbore['id']
assert record.get_raw_data() == wellbore
......@@ -351,6 +354,7 @@ class TestWellLogRecord:
assert record.acl == {}
assert record.kind is None
assert record.legal == {}
assert record.id is None
assert record.get_raw_data() == {}
assert record.get_curveids() == []
......@@ -364,6 +368,7 @@ class TestWellLogRecord:
'acl': {'some': 'acl'},
'kind': 'A Kind',
'legal': {'some': 'legal'},
'id': 'WLID-123'
}
record = WellLogRecord(welllog)
......@@ -372,6 +377,7 @@ class TestWellLogRecord:
assert record.acl == welllog['acl']
assert record.kind == welllog['kind']
assert record.legal == welllog['legal']
assert record.id == welllog['id']
assert record.get_raw_data() == welllog
assert record.get_curveids() == ['abc', 'xyz']
......@@ -407,7 +413,7 @@ class TestMapWellLogToLas:
{"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 = Record("BoreKind", {}, {}, {"FacilityName": "Well name", "NameAliases": [{"AliasName": "Some Name"}]})
......@@ -442,7 +448,7 @@ class TestMapWellLogToLas:
{"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 = Record("BoreKind", {}, {}, {"FacilityName": "Well name", "NameAliases": [{"AliasName": "Some Name"}]})
......
......@@ -89,6 +89,59 @@ class TestWellLogService:
client.post_log_recognition.assert_called_once_with(mnemonic, unit)
assert result == expected
def test_update_log_family(self):
# Arrange
welllog_id = "WL-ID-123"
data_partition_id = "dp-123"
curves = [
{"Mnemonic": "DEPT", "CurveUnit": "::Unit1"},
{"Mnemonic": "BWV", "CurveUnit": "::Unit2"},
{"Mnemonic": "DT", "CurveUnit": "::Unit3"}
]
welllog_record = WellLogRecord({
"kind": "a kind",
"data": {
"ReferenceCurveID": "DEPT",
"Curves": curves,
"WellboreID": "WB-ID-123",
},
"id": welllog_id
})
family_id_prefix = "dp-123:reference-data--LogCurveFamily"
enriched_curves = [
{"Mnemonic": "DEPT", "CurveUnit": "::Unit1", "LogCurveFamilyID": f"{family_id_prefix}:Fam-ID-1:"},
{"Mnemonic": "BWV", "CurveUnit": "::Unit2", "LogCurveFamilyID": f"{family_id_prefix}:Fam-ID-1:"},
{"Mnemonic": "DT", "CurveUnit": "::Unit3", "LogCurveFamilyID": f"{family_id_prefix}:Fam-ID-1:"}
]
enriched_welllog_record = WellLogRecord({
"kind": "a kind",
"data": {
"ReferenceCurveID": "DEPT",
"Curves": enriched_curves,
"WellboreID": "WB-ID-123",
},
"id": welllog_id
})
client = Mock(spec=OsduClient)
client.get_welllog_record.return_value = welllog_record
client.post_log_recognition.return_value = {"family": "Fam ID 1"}
client.post_welllog.return_value = [welllog_id]
subject = WellLogService(client)
# Act
subject.update_log_family(welllog_id, data_partition_id)
# Assert
assert client.get_welllog_record.call_count == 2
client.get_welllog_record.assert_called_with(welllog_id)
assert client.post_log_recognition.call_count == 3
client.post_log_recognition.assert_called_with("DT", "Unit3")
client.post_welllog.assert_called_once_with(enriched_welllog_record.to_record())
def test_get_data_ingest_validation_variables(self):
# Assemble
client = Mock(spec=OsduClient)
......
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