-
Notifications
You must be signed in to change notification settings - Fork 25
Implemented convenience method for client id #97
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
Open
Sharvin-M
wants to merge
7
commits into
nasa:develop
Choose a base branch
from
Sharvin-M:client_id-method
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c720dcc
added client id method
Sharvin-M 9f9d247
updated client_id method
Sharvin-M d92aa64
updated tests for client_id method
Sharvin-M 10ec673
Update cmr/queries.py
frankinspace 12f11b1
Update cmr/queries.py
Sharvin-M 132ab4e
added requested changes
Sharvin-M 38e723b
Update cmr/queries.py
Sharvin-M File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |||||||||||||||||
| from inspect import getmembers, ismethod | ||||||||||||||||||
| from re import search | ||||||||||||||||||
| from typing import Iterator | ||||||||||||||||||
| from importlib.metadata import version | ||||||||||||||||||
|
|
||||||||||||||||||
| from typing_extensions import ( | ||||||||||||||||||
| Any, | ||||||||||||||||||
|
|
@@ -59,6 +60,7 @@ def __init__(self, route: str, mode: str = CMR_OPS): | |||||||||||||||||
| self.mode(mode) | ||||||||||||||||||
| self.concept_id_chars: Set[str] = set() | ||||||||||||||||||
| self.headers: MutableMapping[str, str] = {} | ||||||||||||||||||
| self.headers.update({"Client-Id": f"python_cmr-v{version('python_cmr')}"}) | ||||||||||||||||||
|
|
||||||||||||||||||
| @deprecated("Use the 'results' method instead, but note that it produces an iterator.") | ||||||||||||||||||
| def get(self, limit: int = 2000) -> Sequence[Any]: | ||||||||||||||||||
|
|
@@ -365,6 +367,26 @@ def bearer_token(self, bearer_token: str) -> Self: | |||||||||||||||||
|
|
||||||||||||||||||
| return self | ||||||||||||||||||
|
|
||||||||||||||||||
| def client_id(self, id_: str) -> Self: | ||||||||||||||||||
Sharvin-M marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
| """ | ||||||||||||||||||
| Set the value of this query's `Client-Id` header. | ||||||||||||||||||
|
|
||||||||||||||||||
| Otherwise, set the header value to the specified value along with | ||||||||||||||||||
| the suffix `(python_cmr-vX.Y.Z)`, separated by a space character. | ||||||||||||||||||
frankinspace marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
|
|
||||||||||||||||||
| :param client_id | ||||||||||||||||||
| :returns self | ||||||||||||||||||
| """ | ||||||||||||||||||
|
|
||||||||||||||||||
| if not id_: | ||||||||||||||||||
| return self | ||||||||||||||||||
|
|
||||||||||||||||||
| self.headers.update( | ||||||||||||||||||
| {"Client-Id": f"{id_} python_cmr-v{version('python_cmr')}"} | ||||||||||||||||||
| ) | ||||||||||||||||||
|
||||||||||||||||||
| if not id_: | |
| return self | |
| self.headers.update( | |
| {"Client-Id": f"{id_} python_cmr-v{version('python_cmr')}"} | |
| ) | |
| python_cmr_id = f"python_cmr-v{version('python_cmr')}" | |
| self.headers["Client-Id"] = f"{id_} ({python_cmr_id})" if id_ else python_cmr_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||
| from cmr import Query | ||||||
|
|
||||||
| from importlib.metadata import version | ||||||
|
|
||||||
| class MockQuery(Query): | ||||||
| def _valid_state(self) -> bool: | ||||||
|
|
@@ -8,7 +8,8 @@ def _valid_state(self) -> bool: | |||||
|
|
||||||
| def test_query_headers_initially_empty(): | ||||||
| query = MockQuery("/foo") | ||||||
| assert query.headers == {} | ||||||
| expected_version = version("python_cmr") | ||||||
| assert query.headers == {"Client-Id": f"python_cmr-v{expected_version}"} | ||||||
|
|
||||||
|
|
||||||
| def test_bearer_token_adds_header(): | ||||||
|
|
@@ -55,3 +56,11 @@ def test_token_replaces_existing_auth_header(): | |||||
| query.token("token") | ||||||
|
|
||||||
| assert query.headers["Authorization"] == "token" | ||||||
|
|
||||||
| def test_client_id_sets_header(): | ||||||
| query = MockQuery("/foo") | ||||||
| query.client_id("test_client") | ||||||
| query.token("token") | ||||||
|
|
||||||
| expected_version = version("python_cmr") | ||||||
| assert query.headers["Client-Id"] == f"test_client python_cmr-v{expected_version}" | ||||||
|
||||||
| assert query.headers["Client-Id"] == f"test_client python_cmr-v{expected_version}" | |
| assert query.headers["Client-Id"] == f"test_client (python_cmr-v{expected_version})" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.