Implemented convenience method for client id#97
Implemented convenience method for client id#97Sharvin-M wants to merge 7 commits intonasa:developfrom
Conversation
frankinspace
left a comment
There was a problem hiding this comment.
Thank you for the contribution! I added a couple suggestions.
cmr/queries.py
Outdated
| """ | ||
|
|
||
| if not client_id: | ||
| self.headers.update({"Client-Id: python_cmr-v0.13.0"}) |
There was a problem hiding this comment.
| self.headers.update({"Client-Id: python_cmr-v0.13.0"}) | |
| self.headers.update({"Client-Id": "python_cmr-v0.13.0"}) |
cmr/queries.py
Outdated
|
|
||
| return self | ||
|
|
||
| def client_id(self, client_id: str) -> Self: |
There was a problem hiding this comment.
Should be able to use https://docs.python.org/3/library/importlib.metadata.html#importlib.metadata.version to dynamically replace the version of python_cmr in use instead of hard-coding it in the string.
|
I'd also suggest adding a quick test function in https://github.com/nasa/python_cmr/blob/35b8bdafa655c9a95edc41659ccb867df9e86c18/tests/test_queries.py to test that the custom string is appended as expected to the header. I'd also suggest calling the function from the |
chuckwondo
left a comment
There was a problem hiding this comment.
@Sharvin-M, thanks for your first contribution!
cmr/queries.py
Outdated
|
|
||
| return self | ||
|
|
||
| def client_id(self, client_id: str) -> Self: |
There was a problem hiding this comment.
To avoid confusion, I suggest that you do not name the function parameter the same as the function itself. I suggest changing the function parameter name to id_ instead of client_id. Note the trailing underscore on id_ because there is a global function named id, so the trailing underscore is a convention used to avoid name collisions with global variables.
cmr/queries.py
Outdated
|
|
||
| def client_id(self, client_id: str) -> Self: | ||
| """ | ||
| Set the value of this query's 'Client ID' header according to User's input. |
There was a problem hiding this comment.
| Set the value of this query's 'Client ID' header according to User's input. | |
| Set the value of this query's `Client-Id` header. |
cmr/queries.py
Outdated
| Otherwise, set the specified paramter option to the value along with | ||
| the suffix (python_cmr-vX.Y.Z) and a space character between the specified paramter and the suffix. |
There was a problem hiding this comment.
| Otherwise, set the specified paramter option to the value along with | |
| the suffix (python_cmr-vX.Y.Z) and a space character between the specified paramter and the suffix. | |
| Otherwise, set the header value to the specified value along with | |
| the suffix `(python_cmr-vX.Y.Z)`, separated by a space character. |
|
I attempted to add the requested changes, let me know your thoughts! @frankinspace @chuckwondo |
cmr/queries.py
Outdated
| if not id_: | ||
| return self | ||
|
|
||
| self.headers.update( | ||
| {"Client-Id": f"{id_} python_cmr-v{version('python_cmr')}"} | ||
| ) |
There was a problem hiding this comment.
| 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 |
cmr/queries.py
Outdated
| 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')}"}) |
There was a problem hiding this comment.
| self.headers.update({"Client-Id": f"python_cmr-v{version('python_cmr')}"}) | |
| self.client_id() |
tests/test_queries.py
Outdated
| query.token("token") | ||
|
|
||
| expected_version = version("python_cmr") | ||
| assert query.headers["Client-Id"] == f"test_client python_cmr-v{expected_version}" |
There was a problem hiding this comment.
| 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})" |
|
For some reason the VCR tests in multiple queries are failing. I would have expected failure due to unexpected new header but they seem to be failing in a way that is causing twice the number of requests to be sent |
I can dig into it, if you like. |
Co-authored-by: Chuck Daniels <cjdaniels4@gmail.com>
|
I looked into it a bit, Please let me know if any of this is useful info @frankinspace @chuckwondo 1. There was a type error because no arg is provided to the client_id method in the init function. To temporarily bypass this, I passed in the default argument manually (on line 72). I don't entirely understand how optional arguments work in Python.# line 72
self.client_id(f"python_cmr-v{version('python_cmr')}") 2. I was then able to run the tests, which had one failing related to the get_all method:
3. There were many deprecation warnings related to not using the results method in all of the tests being run. |
Co-authored-by: Chuck Daniels <cjdaniels4@gmail.com>

Wrote the method for a user to specify the 'Client-Id' header in the Query class. By default, the method should return the Client-Id of the request as follows: "Client-Id: python_cmr-v0.13.0". If a client-id parameter is specified by the user, it should return: "Client-Id": f"{client_id} python_cmr-v0.13."
This is my first time contributing to open source, so I will appreciate any and all feedback! @chuckwondo @frankinspace