Commit 4f5111e1 authored by Luc Yriarte's avatar Luc Yriarte
Browse files

Merge branch 'test-no-data-fix' into 'master'

Properly raise bulk not found exception on get data version with no bulk urn

See merge request !144
parents 5c24a872 0a989851
Pipeline #48873 failed with stages
in 12 minutes and 57 seconds
......@@ -13,7 +13,7 @@
# limitations under the License.
import uuid
from typing import Tuple
from typing import Tuple, Optional
class BulkId:
......@@ -30,7 +30,9 @@ class BulkId:
# Returns a tuple (<uuid> : str, <prefix> : str)
@classmethod
def bulk_urn_decode(cls, urn: str) -> Tuple[str, str]:
def bulk_urn_decode(cls, urn: str) -> Tuple[str, Optional[str]]:
if urn is None:
raise ValueError('attempted to decode empty urn')
parts = urn.split(":")
if len(parts) < 4:
return str(uuid.UUID(urn)), None
......
......@@ -270,8 +270,11 @@ async def get_data_version(
dask_blob_storage: DaskBulkStorage = Depends(with_dask_blob_storage),
):
record = await fetch_record(ctx, record_id, version)
bulk_id, prefix = BulkId.bulk_urn_decode(get_bulk_uri(record))
bulk_uri = get_bulk_uri(record)
try:
if bulk_uri is None:
raise BulkNotFound(record_id=record_id, bulk_id=None)
bulk_id, prefix = BulkId.bulk_urn_decode(bulk_uri)
if prefix != BULK_URN_PREFIX_VERSION:
raise BulkNotFound(record_id=record_id, bulk_id=bulk_id)
df = await dask_blob_storage.load_bulk(record_id, bulk_id)
......
......@@ -11,6 +11,7 @@
# 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.
import pytest
from app.bulk_persistence import BulkId
import uuid
......@@ -19,3 +20,17 @@ import uuid
def test_bulk_id_is_an_uuid():
uuid.UUID(BulkId.new_bulk_id())
# urn decode test
def test_decode_urn_no_prefix():
uuid, prefix = BulkId.bulk_urn_decode("urn:uuid:489768d2-eee1-4a8f-ae95-7b0c30b0dcd8")
assert uuid == "489768d2-eee1-4a8f-ae95-7b0c30b0dcd8"
assert prefix is None
def test_decode_urn_with_prefix():
uuid, prefix = BulkId.bulk_urn_decode("urn:myprefix:uuid:489768d2-eee1-4a8f-ae95-7b0c30b0dcd8")
assert uuid == "489768d2-eee1-4a8f-ae95-7b0c30b0dcd8"
assert prefix == 'myprefix'
def test_decode_urn_none():
with pytest.raises(ValueError):
uuid, prefix = BulkId.bulk_urn_decode(None)
......@@ -22,6 +22,7 @@ from fastapi.testclient import TestClient
from fastapi import Header, status
from odes_storage.models import CreateUpdateRecordsResponse, Record
from app.model.osdu_model import Wellbore, Well
from app.clients import SearchServiceClient, StorageRecordServiceClient
......
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