Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to datapi #224

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cads_processing_api_service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@

logger: structlog.stdlib.BoundLogger = structlog.get_logger(__name__)

API_REQUEST_TEMPLATE = """import cdsapi
API_REQUEST_TEMPLATE = """\
import logging

dataset = "{process_id}"
import datapi

logging.basicConfig(level="INFO")

collection_id = "{process_id}"
request = {api_request_kwargs}

client = cdsapi.Client()
client.retrieve(dataset, request).download()
client = datapi.ApiClient()
client.retrieve(collection_id, request)
"""

API_REQUEST_MAX_LIST_LENGTH: dict[str, int] = {
Expand Down
10 changes: 6 additions & 4 deletions tests/test_10_translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,17 @@ def test_format_api_request() -> None:
}
}
exp_output = (
"import cdsapi\n\n"
'dataset = "test_process_id"\n'
"import logging\n\n"
"import datapi\n\n"
'logging.basicConfig(level="INFO")\n\n'
'collection_id = "test_process_id"\n'
"request = {\n"
' "variable_1": "value_1",\n'
' "variable_2": [\n "value_1",\n "value_2"\n ],\n'
' "variable_3": 1\n'
"}\n\n"
"client = cdsapi.Client()\n"
"client.retrieve(dataset, request).download()\n"
"client = datapi.ApiClient()\n"
"client.retrieve(collection_id, request)\n"
)
res_output = translators.format_api_request(
test_api_request_template, test_process_id, test_request
Expand Down