-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #48 Co-authored-by: Frank Greguska <[email protected]>
- Loading branch information
1 parent
18a3536
commit f4aab17
Showing
4 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,3 +1,23 @@ | ||
from .queries import GranuleQuery, CollectionQuery, ToolQuery, ServiceQuery, VariableQuery, CMR_OPS, CMR_UAT, CMR_SIT | ||
from .queries import ( | ||
CMR_OPS, | ||
CMR_SIT, | ||
CMR_UAT, | ||
CollectionQuery, | ||
GranuleQuery, | ||
Query, | ||
ServiceQuery, | ||
ToolQuery, | ||
VariableQuery, | ||
) | ||
|
||
__all__ = ["GranuleQuery", "CollectionQuery", "ToolQuery", "ServiceQuery", "VariableQuery", "CMR_OPS", "CMR_UAT", "CMR_SIT"] | ||
__all__ = [ | ||
"CMR_OPS", | ||
"CMR_SIT", | ||
"CMR_UAT", | ||
"CollectionQuery", | ||
"GranuleQuery", | ||
"Query", | ||
"ServiceQuery", | ||
"ToolQuery", | ||
"VariableQuery", | ||
] |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from cmr import Query | ||
|
||
|
||
class MockQuery(Query): | ||
def _valid_state(self) -> bool: | ||
return True | ||
|
||
|
||
def test_query_headers_initially_empty(): | ||
query = MockQuery("/foo") | ||
assert query.headers == {} | ||
|
||
|
||
def test_bearer_token_adds_header(): | ||
query = MockQuery("/foo") | ||
query.headers["foo"] = "bar" | ||
query.bearer_token("bearertoken") | ||
|
||
assert query.headers["foo"] == "bar" | ||
|
||
|
||
def test_bearer_token_does_not_clobber_other_headers(): | ||
query = MockQuery("/foo") | ||
query.bearer_token("bearertoken") | ||
|
||
assert query.headers["Authorization"] == "Bearer bearertoken" | ||
|
||
|
||
def test_bearer_token_replaces_existing_auth_header(): | ||
query = MockQuery("/foo") | ||
query.token("token") | ||
query.bearer_token("bearertoken") | ||
|
||
assert query.headers["Authorization"] == "Bearer bearertoken" | ||
|
||
|
||
def test_token_adds_header(): | ||
query = MockQuery("/foo") | ||
query.token("token") | ||
|
||
assert query.headers["Authorization"] == "token" | ||
|
||
|
||
def test_token_does_not_clobber_other_headers(): | ||
query = MockQuery("/foo") | ||
query.headers["foo"] = "bar" | ||
query.token("token") | ||
|
||
assert query.headers["foo"] == "bar" | ||
|
||
|
||
def test_token_replaces_existing_auth_header(): | ||
query = MockQuery("/foo") | ||
query.bearer_token("bearertoken") | ||
query.token("token") | ||
|
||
assert query.headers["Authorization"] == "token" |