Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • osdu/platform/domain-data-mgmt-services/wellbore/wellbore-domain-services
  • Vkamani/vkamani-wellbore-domain-services
  • Yan_Sushchynski/wellbore-domain-services-comm-impl
3 results
Show changes
......@@ -18,7 +18,7 @@ import os
from typing import Type
from pydantic import BaseModel, ValidationError
from app.model.osdu_model import Wellbore, Well, WellLog, WellboreTrajectory, WellboreMarkerSet, \
WellLog110, WellboreTrajectory110
WellLog110, WellboreTrajectory110, WellboreMarkerSet110
test_parameters = [
......@@ -34,6 +34,7 @@ test_parameters = [
(WellboreTrajectory110, "WellboreTrajectory_unit.json", None),
(WellboreTrajectory110, "WellboreTrajectory110_unit.json", None),
(WellboreMarkerSet, "WellboreMarkerSet_unit.json", None),
(WellboreMarkerSet110, "WellboreMarkerSet110_unit.json", None),
]
......
import pytest
import json
from fastapi import Header, status
from fastapi.testclient import TestClient
from app.clients import SearchServiceClient, StorageRecordServiceClient
from app.helper import traces
from app.middleware import require_data_partition_id
from app.auth.auth import require_opendes_authorized_user
from app.utils import Context
from app.wdms_app import wdms_app, app_injector
from tests.unit.test_utils import create_mock_class, nope_logger_fixture
StorageRecordServiceClientMock = create_mock_class(StorageRecordServiceClient)
SearchServiceClientMock = create_mock_class(SearchServiceClient)
@pytest.fixture
def client(nope_logger_fixture):
async def bypass_authorization():
# empty method
pass
async def set_default_partition(data_partition_id: str = Header("opendes")):
Context.set_current_with_value(partition_id=data_partition_id)
async def build_mock_storage():
return StorageRecordServiceClientMock()
async def build_mock_search():
return SearchServiceClientMock()
app_injector.register(StorageRecordServiceClient, build_mock_storage)
app_injector.register(SearchServiceClient, build_mock_search)
# override authentication dependency
previous_overrides = wdms_app.dependency_overrides
try:
wdms_app.dependency_overrides[
require_opendes_authorized_user
] = bypass_authorization
wdms_app.dependency_overrides[require_data_partition_id] = set_default_partition
client = TestClient(wdms_app)
yield client
finally:
wdms_app.dependency_overrides = previous_overrides # clean up
# Initialize traces exporter in app, like it is in app's startup decorator
wdms_app.trace_exporter = traces.CombinedExporter(service_name="tested-ddms")
@pytest.mark.parametrize("data", [
[
{"ReferenceCurveID": "MD", "Curves": [{"CurveID": "GR"}, {"CurveID": "MD"}]},
{"ReferenceCurveID": "TVD", "Curves": [{"CurveID": "TVD"}, {"CurveID": "INCL"}]},
],
[
{"Curves": [{"CurveID": "MD"}, {"CurveID": "GR"}]},
{"Curves": [{"CurveID": "A"}, {"CurveID": "B"}]}
],
[
{"Curves": []}
],
[
{"TopMeasuredDepth": "1000"},
{"Curves": [{"CurveID": "MD"}, {"CurveID": "GR"}]},
{"Curves": []}
]
])
def test_post_consistent_welllog(client, data):
response = client.post(
url="/ddms/v3/welllogs",
json=[{
"kind": "osdu:wks:work-product-component--WellLog:1.0.0",
"legal": {
"legaltags": ["foo"],
"otherRelevantDataCountries": ["FR"]},
"acl": {
"owners": ["foo@bar.com"],
"viewers": ["foo@bar.com"]},
"data": d} for d in data],
headers={'content-type': 'application/json'})
assert response.status_code == status.HTTP_200_OK
@pytest.mark.parametrize("well_log_data, expected", [
(
[
{"ReferenceCurveID": "MD", "Curves": [{"CurveID": "MD"}, {"CurveID": "GR"}]},
{"ReferenceCurveID": "MD", "Curves": [{"CurveID": "MD"}, {"CurveID": "A"}, {"CurveID": "A"}]}
],
(
status.HTTP_400_BAD_REQUEST,
"All CurveID in WellLog[1] should be unique"
)
),
(
[
{"ReferenceCurveID": "MD", "Curves": [{"CurveID": "MD"}, {"CurveID": "GR"}]},
{"ReferenceCurveID": "MD", "Curves": [{"CurveID": "A"}, {"CurveID": "B"}]}
],
(
status.HTTP_400_BAD_REQUEST,
"WellLog[1] should have a curve with a curveID value equal to the ReferenceCurveID value: 'MD'"
)
),
(
[
{"ReferenceCurveID": "MD", "Curves": [{"CurveID": "MD"}, {"CurveID": "GR"}]},
{"ReferenceCurveID": "MD","Curves": []}
],
(
status.HTTP_400_BAD_REQUEST,
"WellLog[1] should have a curve with a curveID value equal to the ReferenceCurveID value: 'MD'"
)
),
(
[
{"ReferenceCurveID": "MD", "Curves": [{"CurveID": "MD"}, {"CurveID": "GR"}]},
{"ReferenceCurveID": "MD"}
],
(
status.HTTP_400_BAD_REQUEST,
"WellLog[1] should have a curve with a curveID value equal to the ReferenceCurveID value: 'MD'"
)
)
])
def test_post_inconsistent_welllog(client, well_log_data, expected):
response = client.post(
url="/ddms/v3/welllogs",
json=[{
"kind": "osdu:wks:work-product-component--WellLog:1.0.0",
"legal": {
"legaltags": ["foo"],
"otherRelevantDataCountries": ["FR"]},
"acl": {
"owners": ["foo@bar.com"],
"viewers": ["foo@bar.com"]},
"data": data} for data in well_log_data],
headers={'content-type': 'application/json'})
assert response.status_code == expected[0]
assert expected[1] in response.json().get("detail")
......@@ -75,7 +75,12 @@ def build_request_get_versions_of_osdu_wellboremarkerset() -> RequestRunner:
return RequestRunner(rq_proto)
def build_request_create_osdu_wellboremarkerset() -> RequestRunner:
def build_request_create_osdu_wellboremarkerset(b_use_fixed_id=True) -> RequestRunner:
if b_use_fixed_id:
id_field = '"id": "{{data_partition}}:work-product-component--WellboreMarkerSet:c7c421a7-f496-5aef-8093-298c32bfdea9",'
else:
id_field = ''
rq_proto = Request(
name="Create OSDU wellboremarkerset",
method="POST",
......@@ -87,9 +92,8 @@ def build_request_create_osdu_wellboremarkerset() -> RequestRunner:
"Connection": "{{header_connection}}",
"Authorization": "Bearer {{token}}",
},
payload=r"""[{
payload='[{' + id_field + r"""
"acl": {{record_acl}}, "legal": {{record_legal}},
"id": "{{data_partition}}:work-product-component--WellboreMarkerSet:c7c421a7-f496-5aef-8093-298c32bfdea9",
"kind": "{{osduWellboreMarkerSetKind}}",
"tags": {
"NameOfKey": "String value"
......@@ -349,6 +353,13 @@ def build_request_create_osdu_wellboremarkerset() -> RequestRunner:
"VerticalReferenceID": "Example VerticalReferenceID",
"VerticalMeasurementDescription": "Example VerticalMeasurementDescription"
},
"AvailableMarkerProperties": [
{
"MarkerPropertyTypeID": "partition-id:reference-data--MarkerPropertyType:MissingThickness:",
"MarkerPropertyUnitID": "partition-id:reference-data--UnitOfMeasure:ft:",
"Name": "MissingThickness"
}
],
"Markers": [
{
"MarkerName": "Example MarkerName",
......@@ -653,6 +664,13 @@ def get_cleaned_ref_and_res(res: dict) -> (dict, dict):
"VerticalReferenceID": "Example VerticalReferenceID",
"VerticalMeasurementDescription": "Example VerticalMeasurementDescription"
},
"AvailableMarkerProperties": [
{
"MarkerPropertyTypeID": "partition-id:reference-data--MarkerPropertyType:MissingThickness:",
"MarkerPropertyUnitID": "partition-id:reference-data--UnitOfMeasure:ft:",
"Name": "MissingThickness"
}
],
"Markers": [
{
"MarkerName": "Example MarkerName",
......
# Copyright 2021 Schlumberger
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from wdms_client.request_runner import RequestRunner, Request
def build_request_delete_purge_record(record_id: str, v3_entity: str, purge: str) -> RequestRunner:
rq_proto = Request(
name='Delete log',
method='DELETE',
url='{{base_url}}/ddms/v3/' + f'{v3_entity}/' + f'{record_id}?purge=' + f'{purge}',
headers={
'accept': 'application/json',
'data-partition-id': '{{data_partition}}',
'Connection': '{{header_connection}}',
'Authorization': 'Bearer {{token}}',
},
)
return RequestRunner(rq_proto)
def build_request_get_record(base_url_v3_record: str, record_id: str) -> RequestRunner:
rq_proto = Request(
name="Get record",
method="GET",
url=f'{base_url_v3_record}/' + f'{record_id}',
headers={
"accept": "application/json",
"data-partition-id": "{{data_partition}}",
"Connection": "{{header_connection}}",
"Authorization": "Bearer {{token}}",
},
)
return RequestRunner(rq_proto)
\ No newline at end of file
# Copyright 2021 Schlumberger
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from wdms_client.request_runner import RequestRunner, Request
def build_request_delete_osdu_records() -> RequestRunner:
rq_proto = Request(
name="Delete Records",
method="POST",
url="{{base_url}}/ddms/v3/records/delete",
headers={
"accept": "application/json",
"data-partition-id": "{{data_partition}}",
"Connection": "{{header_connection}}",
"Authorization": "Bearer {{token}}",
},
payload=r""" {{record_ids}} """,
)
return RequestRunner(rq_proto)
......@@ -32,7 +32,7 @@ variables_dict = {
"osduWellKind": "osdu:wks:master-data--Well:1.0.0",
"osduWellLogKind": "osdu:wks:work-product-component--WellLog:1.1.0",
"osduWellboreTrajectoryKind": "osdu:wks:work-product-component--WellboreTrajectory:1.1.0",
"osduWellboreMarkerSetKind": "osdu:wks:work-product-component--WellboreMarkerSet:1.0.0",
"osduWellboreMarkerSetKind": "osdu:wks:work-product-component--WellboreMarkerSet:1.1.0",
"acl_domain": "p4d.cloud.slb-ds.com",
"acl_owner": "data.default.owners@{{data_partition}}.{{acl_domain}}",
"acl_viewer": "data.default.viewers@{{data_partition}}.{{acl_domain}}",
......