Skip to content

Commit

Permalink
Merge pull request #51 from dylanmcreynolds/fix_auth
Browse files Browse the repository at this point in the history
Fix auth error in from_token, from_credentials
  • Loading branch information
dylanmcreynolds authored Oct 11, 2023
2 parents 67b0556 + 9cb11da commit 8ff172b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyscicat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
self._password is not None
), "SciCat login credentials (username, password) must be provided if token is not provided"
self._token = get_token(self._base_url, self._username, self._password)
self._headers["Authorization"] = "Bearer {}".format(self._token)
self._headers["Authorization"] = "Bearer {}".format(self._token)

def _send_to_scicat(self, cmd: str, endpoint: str, data: BaseModel = None):
"""sends a command to the SciCat API server using url and token, returns the response JSON
Expand Down
14 changes: 12 additions & 2 deletions tests/test_pyscicat/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
encode_thumbnail,
get_file_mod_time,
get_file_size,
ScicatClient,
ScicatCommError,
)

Expand Down Expand Up @@ -217,5 +218,14 @@ def test_initializers():
with requests_mock.Mocker() as mock_request:
add_mock_requests(mock_request)

client = from_token(local_url, "let me in!")
assert client._token == "let me in!"
client = from_token(local_url, "a_token")
assert client._token == "a_token"
assert client._headers['Authorization'] == "Bearer a_token"

client = from_credentials(local_url, "Zaphod", "heartofgold")
assert client._token == "a_token"
assert client._headers['Authorization'] == "Bearer a_token"

client = ScicatClient(local_url, "a_token")
assert client._token == "a_token"
assert client._headers['Authorization'] == "Bearer a_token"

0 comments on commit 8ff172b

Please sign in to comment.