Skip to content

Commit

Permalink
Merge pull request #33 from NASA-PDS/version_140
Browse files Browse the repository at this point in the history
Version 1.5.0
  • Loading branch information
tloubrieu-jpl authored Mar 4, 2024
2 parents 07cb521 + ec99e54 commit 5fb4e0d
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 24 deletions.
28 changes: 15 additions & 13 deletions docs/source/developer/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,33 @@ The reference OpenAPI specifications for PDS can be found on `PDS API`_.

Then, install OpenAPI Generator 6.5.0 (e.g. on macos with brew, see https://github.com/OpenAPITools/openapi-generator#1---installation), and run::

pip install pyyaml
python src/pds/api_client/preprocess_openapi.py /Users/loubrieu/PycharmProjects/pds-api/specs/PDS_APIs-search-1.1.1-swagger.yaml --version 1.3.0

Manual step, add lines in the setup.py file:

Installation
~~~~~~~~~~~~
from setuptools import find_namespace_packages

Do the following commands in a Python virtual environment::
packages=find_namespace_packages(where='src/', exclude=["test", "tests"]),
package_dir={"": "src"},

pip install --requirement requirements.txt
python setup.py install

Installation & Testing
~~~~~~~~~~~~~~~~~~~~~~~
For integration testing you need an Registry API local server deployed on http://localhost:8080

Testing
~~~~~~~
Use the docker compose deployment, see https://nasa-pds.github.io/registry/install/docker-compose.html

For testing you need an Registry API local server deployed on http://localhost:8080
Do the following commands in a Python virtual environment::

Use the docker compose deployment, see https://nasa-pds.github.io/registry/install/docker-compose.html
tox

To test it, try the virtual environment's Python::

python client-demo.py
python setup.py test
Run demo
~~~~~~~~~

python src/pds/api_client/demo/client-demo.py

Note that you need an API server to test on.

PyPI Publication
~~~~~~~~~~~~~~~~
Expand All @@ -75,6 +76,7 @@ Try::

pip install wheel
python setup.py sdist bdist_wheel
pip install twine
twine upload --repository testpypi dist/*


Expand Down
9 changes: 3 additions & 6 deletions docs/source/quickstart/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Prerequisites
-------------

Python 3 (tested with 3.9).
<<<<<<< HEAD
=======

Issues with SSL certificate verification seen with python 3.9.

Expand All @@ -19,9 +17,6 @@ If it occurs to you, try:

However, we have not been able to solve that with conda python 3.9.

>>>>>>> 94a82f3 (wip: add test on properties, add new version compliance line)



Installation
------------
Expand All @@ -38,6 +33,8 @@ The package releases match with the `Search API specification <https://nasa-pds.

* - pds.api-client
- pds search api specification
* - 1.5.X
- 1.4
* - 1.4.X
- 1.3
* - 1.3.X
Expand All @@ -51,7 +48,7 @@ The package releases match with the `Search API specification <https://nasa-pds.

To install a specific version of this package, run, for example::

pip install pds.api-client==1.3.0
pip install pds.api-client==1.4.0


You can also include it as a dependency in another package, for example, in
Expand Down
Empty file removed src/__init__.py
Empty file.
Empty file removed src/pds/__init__.py
Empty file.
Empty file removed src/pds/api_client/__init__.py
Empty file.
4 changes: 3 additions & 1 deletion src/pds/api_client/preprocess_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ def run_openapi_gen(input, version):
'generate',
'--skip-validate-spec',
'-g',
'python-nextgen',
'python',
'-i',
file.name,
'--package-name',
'pds.api_client',
f'--additional-properties=packageVersion={version}'
])
subprocess.run(openapi_generator_cmd)
# move the generated classes with the static code
shutil.copytree('./pds/api_client', './src/pds/api_client', dirs_exist_ok=True)


def main():
Expand Down
8 changes: 4 additions & 4 deletions src/pds/api_client/test/integration/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_all_collections(self):

api_response = self.product_by_class.class_list(
'collections',
start=0,
limit=10
)

Expand All @@ -40,14 +39,13 @@ def test_all_collections(self):
def test_all_collections_one_property(self):
api_response = self.product_by_class.class_list(
'collections',
start=0,
limit=20,
fields=['ops:Label_File_Info.ops:file_ref']
)

assert hasattr(api_response, "data")

collections_expected_labels = iter([
collections_expected_labels = set([
"http://localhost:81/archive/custom-datasets/naif3/spice_kernels/collection_spice_kernels_v003.xml",
"http://localhost:81/archive/custom-datasets/urn-nasa-pds-insight_rad/data_calibrated/collection_data_rad_calibrated.xml",
"http://localhost:81/archive/custom-datasets/urn-nasa-pds-insight_rad/data_derived/collection_data_rad_derived.xml",
Expand All @@ -56,7 +54,9 @@ def test_all_collections_one_property(self):

for collection in api_response.data:
urls = collection.properties['ops:Label_File_Info.ops:file_ref']
assert next(collections_expected_labels) in urls[0]
assert urls[0] in collections_expected_labels
collections_expected_labels.discard(urls[0])


def test_collection_by_lidvid_all(self):
collections = self.all_products.select_by_lidvid_all('urn:nasa:pds:mars2020.spice:spice_kernels')
Expand Down
68 changes: 68 additions & 0 deletions src/pds/api_client/test/integration/test_collections_of_bundle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import unittest
from pds.api_client import Configuration
from pds.api_client import ApiClient
from pds.api_client.api.product_references_api import ProductReferencesApi


class CollectionsOfBundleTestCase(unittest.TestCase):
def setUp(self):
# create an instance of the API class
configuration = Configuration()
configuration.host = 'http://localhost:8080'
api_client = ApiClient(configuration)
self.product_reference = ProductReferencesApi(api_client)

def test_collections_of_a_bundle_default(self):

results = self.product_reference.product_members(
'urn:nasa:pds:mars2020.spice::3.0',
fields=['ops:Data_File_Info.ops:file_ref']
)
for collection in results.data:
urls = collection.properties['ops:Data_File_Info.ops:file_ref']
for url in urls:
print(url)

def test_all_collections_of_a_bundle_as_deep_archive_does(self):

def get_collections(bundle_lidvid):
_apiquerylimit = 50
_propdataurl = "ops:Data_File_Info.ops:file_ref"
_propdatamd5 = "ops:Data_File_Info.ops:md5_checksum"
_proplabelurl = "ops:Label_File_Info.ops:file_ref"
_proplabelmd5 = "ops:Label_File_Info.ops:md5_checksum"
_proplabelharvesttime = "ops:Harvest_Info.ops:harvest_date_time"
_fields = [_propdataurl, _propdatamd5, _proplabelurl, _proplabelmd5, _proplabelharvesttime]

full_page = True

kwargs = dict(
sort=['ops:Harvest_Info.ops:harvest_date_time'],
limit=_apiquerylimit,
fields=_fields
)

while full_page:
page = self.product_reference.product_members(bundle_lidvid, **kwargs)
full_page = len(page.data) == _apiquerylimit
for c in page.data:
yield c
kwargs['search_after'] = page.data[-1].properties['ops:Harvest_Info.ops:harvest_date_time'][0]

n = 0
for collection in get_collections("urn:nasa:pds:mars2020.spice::3.0"):
print(collection.id)
n += 1

assert n == 1

def test_collection_members(self):
results = self.product_reference.product_members(
'urn:nasa:pds:mars2020.spice:spice_kernels::3.0'
)

self.assertEqual(len(results.data), 11) # add assertion here


if __name__ == '__main__':
unittest.main()
38 changes: 38 additions & 0 deletions src/pds/api_client/test/integration/test_pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import unittest
from pds.api_client import Configuration
from pds.api_client import ApiClient

from pds.api_client.api.all_products_api import AllProductsApi


class PaginationTestCase(unittest.TestCase):
def setUp(self):
# create an instance of the API class
configuration = Configuration()
configuration.host = 'http://localhost:8080'
api_client = ApiClient(configuration)
self.products = AllProductsApi(api_client)

def test_pages(self):
results_1 = self.products.product_list(
keywords=['kernel'],
sort=['ops:Harvest_Info.ops:harvest_date_time'],
limit=2
)

self.assertEqual(len(results_1.data), 2) # add assertion here

latest_harvest_date_time = results_1.data[-1].properties['ops:Harvest_Info.ops:harvest_date_time'][0]

results_2 = self.products.product_list(
keywords=['kernel'],
sort=['ops:Harvest_Info.ops:harvest_date_time'],
search_after=[latest_harvest_date_time],
limit=2
)

self.assertEqual(len(results_2.data), 1)


if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions src/pds/api_client/test/integration/test_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def setUp(self):
def test_get_properties(self):

properties = self.products.product_properties_list()
properties_dict = {p.var_property:{"type": p.type} for p in properties}
assert '_package_id' in properties_dict.keys()
assert 'alternate_ids' in properties_dict.keys()
assert 'insight:Observation_Information/insight:software_version_id' in properties_dict.keys()
assert properties_dict['_package_id']['type'] == 'string'
assert properties_dict['alternate_ids']['type'] == 'string'
assert properties_dict['insight:Observation_Information/insight:software_version_id']['type'] == 'string'


def test_products_by_keywords(self):
Expand Down

0 comments on commit 5fb4e0d

Please sign in to comment.