Skip to content

Commit d1d753d

Browse files
authored
fix: don't call api.login() when using api_tokens [publish]
fix: don't call api.login() when using api_tokens [publish]
2 parents 50c4dbd + 215ffc2 commit d1d753d

2 files changed

Lines changed: 4 additions & 20 deletions

File tree

‎src/quads_lib/quads.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ def register(self) -> dict:
2222
return json_response
2323

2424
def login(self) -> dict:
25-
if self.token and self.token.startswith("qat_"):
26-
return {
27-
"status_code": 201,
28-
"status": "success",
29-
"message": "Authenticated via API token",
30-
"auth_token": self.token,
31-
}
3225
endpoint = urljoin(self.base_url, "login")
3326
_response = self.session.post(endpoint, auth=self.auth, verify=self.verify)
3427
json_response = _response.json()

‎tests/test_quads.py‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,20 +2083,11 @@ def test_init_without_api_token(self):
20832083
assert api.token is None
20842084
assert api.auth is not None
20852085

2086-
def test_login_noop_with_qat_token(self):
2087-
"""Test that login() returns synthetic success for qat_ tokens"""
2086+
def test_api_token_skips_login(self):
2087+
"""Test that api_token users should not call login() - token is already on the session"""
20882088
api = QuadsApi("", "", "http://example.com/", api_token="qat_abc123")
2089-
result = api.login()
2090-
assert result["status_code"] == 201
2091-
assert result["status"] == "success"
2092-
assert result["auth_token"] == "qat_abc123"
2093-
2094-
def test_login_noop_does_not_make_request(self):
2095-
"""Test that login() with qat_ token makes no HTTP request"""
2096-
api = QuadsApi("", "", "http://example.com/", api_token="qat_abc123")
2097-
api.session.post = Mock(side_effect=AssertionError("should not be called"))
2098-
result = api.login()
2099-
assert result["status"] == "success"
2089+
assert api.token == "qat_abc123"
2090+
assert api.session.headers.get("Authorization") == "Bearer qat_abc123"
21002091

21012092
@patch("requests.Session.request")
21022093
def test_get_user(self, mock_request):

0 commit comments

Comments
 (0)