Skip to content

Commit

Permalink
check genome handle ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangs18 committed Apr 24, 2024
1 parent cc2a609 commit 13733c2
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions test/supplemental_genbank_tests/genbank_upload_full_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
import os
import pytest
import re
import requests
import shutil
import time
import unittest
from configparser import ConfigParser
from copy import deepcopy
from datetime import datetime

from installed_clients.DataFileUtilClient import DataFileUtil
from GenomeFileUtil.GenomeFileUtilImpl import GenomeFileUtil
from GenomeFileUtil.GenomeFileUtilServer import MethodContext
from installed_clients.AbstractHandleClient import AbstractHandle as HandleService
from installed_clients.DataFileUtilClient import DataFileUtil
from installed_clients.WorkspaceClient import Workspace as workspaceService
from conftest import assert_exception_correct

Expand Down Expand Up @@ -84,6 +86,8 @@ def setUpClass(cls):
cls.wsID = cls.wsClient.create_workspace({'workspace': cls.wsName})[0]
cls.serviceImpl = GenomeFileUtil(cls.cfg)
cls.dfuClient = DataFileUtil(os.environ['SDK_CALLBACK_URL'])
cls.hs = HandleService(cls.cfg['handle-service-url'], token=token)
cls.kbase_endpoint = cls.cfg['kbase-endpoint']

@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -219,6 +223,28 @@ def _dump_retrieved_data(self, json_path, dictionary):
with open(json_path, "w") as outfile:
json.dump(dictionary, outfile)

def _get_shock_id(self, handle_id):
handles = self.hs.hids_to_handles([handle_id])
shock_id = handles[0]['id']
return shock_id

def _get_blobstore(self, shock_id):
blob_url = self.kbase_endpoint + "/blobstore/node/" + shock_id
response = requests.get(blob_url)
if response.status_code == 200:
data = response.json()
return data
else:
try:
error_data = response.json()
error_message = error_data.get('error')
if error_message:
raise ValueError(
f"Error message: {error_message}; Error status: {error_data.get('status')}"
)
except Exception as e:
raise ValueError(f"Unable to parse error message") from e

def _retrieve_provenance(self, provenance):
# make a deep copy to avoid modifying the original provenance
provs = [prov.copy() for prov in provenance]
Expand Down Expand Up @@ -251,8 +277,15 @@ def _retrieve_genome_data(self, data):
if dist.get("aliases"):
dist["aliases"] = sorted(dist["aliases"])

for key in ["assembly_ref", "genbank_handle_ref"]:
data.pop(key)
assembly_ref = data.pop("assembly_ref")
assert _UPA_PATTERN.match(assembly_ref)

# check handle ref
handle_id = data.pop("genbank_handle_ref")
shock_id = self._get_shock_id(handle_id)
blob_info = self._get_blobstore(shock_id)
assert blob_info["data"]["file"]["checksum"]["md5"] == data["md5"]
assert blob_info["data"]["file"]["name"] == data["id"]

for ontology_event in data.get("ontology_events", []):
ontology_event.pop("timestamp")
Expand All @@ -266,7 +299,7 @@ def _retrieve_assembly_data(self, data):
data = deepcopy(data)

handle_id = data.pop("fasta_handle_ref")
assert handle_id.split("-")[0] == "KBH"
assert handle_id.split("_")[0] == "KBH"

handle_info = data["fasta_handle_info"]
blob_id = handle_info.pop("shock_id")
Expand Down

0 comments on commit 13733c2

Please sign in to comment.