Skip to content

Commit d0b5a09

Browse files
authored
feat: using single Collection endpoint to retrieve the collection details (#104)
* feat: add AUDIT log level for upload * chore: update outdated tests * fix: allow empty str as RESULT_PATH_PREFIX & replace w/ default val * fix: allowing optional original stac item * fix: use single collection endpoint * fix: add test case
1 parent 7d8439e commit d0b5a09

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

mdps_ds_lib/stage_in_out/dapa_client.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,13 @@ def get_collection(self, collection_id: str):
4848
LOGGER.debug(f'getting collection details for: {collection_id}')
4949
self.__get_token()
5050
header = {'Authorization': f'Bearer {self.__token}'}
51-
dapa_collection_url = f'{self.__dapa_base_api}/{self.__api_base_prefix}/collections?limit=1000'
51+
dapa_collection_url = f'{self.__dapa_base_api}/{self.__api_base_prefix}/collections/{collection_id}'
5252
response = requests.get(url=dapa_collection_url, headers=header, verify=self.__verify_ssl)
5353
if response.status_code > 400:
5454
raise RuntimeError(
5555
f'querying collections ends in error. status_code: {response.status_code}. url: {dapa_collection_url}. details: {response.text}')
5656
collections_result = json.loads(response.text)
57-
if 'features' not in collections_result:
58-
raise RuntimeError(f'missing features in response. invalid response: response: {collections_result}')
59-
collection_details = [each_collection for each_collection in collections_result['features'] if
60-
collection_id == each_collection["id"]]
61-
if len(collection_details) < 1:
62-
raise RuntimeError(f'unable to find collection in DAPA')
63-
return collection_details[0]
57+
return collections_result
6458

6559
def get_all_granules(self, collection_id='*', limit=-1, date_from='', date_to=''):
6660
results = []
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from unittest import TestCase
2+
3+
from mdps_ds_lib.stage_in_out.dapa_client import DapaClient
4+
from dotenv import load_dotenv
5+
6+
7+
class TestDapaClient(TestCase):
8+
def setUp(self) -> None:
9+
super().setUp()
10+
load_dotenv()
11+
12+
def test_get_collection_01(self):
13+
dapa_client = DapaClient().with_verify_ssl(False)
14+
my_collection = 'urn:nasa:unity:unity:dev:SBG-L1B_PRE___1'
15+
collection = dapa_client.get_collection(my_collection)
16+
print(collection)
17+
self.assertEqual(collection['id'], my_collection)
18+
return

0 commit comments

Comments
 (0)