Skip to content

Commit 8ff172b

Browse files
Merge pull request #51 from dylanmcreynolds/fix_auth
Fix auth error in from_token, from_credentials
2 parents 67b0556 + 9cb11da commit 8ff172b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pyscicat/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(
8585
self._password is not None
8686
), "SciCat login credentials (username, password) must be provided if token is not provided"
8787
self._token = get_token(self._base_url, self._username, self._password)
88-
self._headers["Authorization"] = "Bearer {}".format(self._token)
88+
self._headers["Authorization"] = "Bearer {}".format(self._token)
8989

9090
def _send_to_scicat(self, cmd: str, endpoint: str, data: BaseModel = None):
9191
"""sends a command to the SciCat API server using url and token, returns the response JSON

tests/test_pyscicat/test_client.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
encode_thumbnail,
1010
get_file_mod_time,
1111
get_file_size,
12+
ScicatClient,
1213
ScicatCommError,
1314
)
1415

@@ -217,5 +218,14 @@ def test_initializers():
217218
with requests_mock.Mocker() as mock_request:
218219
add_mock_requests(mock_request)
219220

220-
client = from_token(local_url, "let me in!")
221-
assert client._token == "let me in!"
221+
client = from_token(local_url, "a_token")
222+
assert client._token == "a_token"
223+
assert client._headers['Authorization'] == "Bearer a_token"
224+
225+
client = from_credentials(local_url, "Zaphod", "heartofgold")
226+
assert client._token == "a_token"
227+
assert client._headers['Authorization'] == "Bearer a_token"
228+
229+
client = ScicatClient(local_url, "a_token")
230+
assert client._token == "a_token"
231+
assert client._headers['Authorization'] == "Bearer a_token"

0 commit comments

Comments
 (0)