File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 1414 CredentialError ,
1515 InvalidInput ,
1616 InvalidSector ,
17+ InvalidToken ,
1718 LockError ,
1819 ParseError ,
1920 QueryNotValid ,
@@ -172,10 +173,12 @@ def lock(self, code):
172173 try :
173174 response .raise_for_status ()
174175 except HTTPError as err :
175- # 403: Not possible to obtain the lock, probably because of a race condition
176- # with another application
176+ # 403: Unable obtain the lock (race condition with another application)
177177 if err .response .status_code == 403 :
178178 raise LockError
179+ # 401: The token has expired
180+ if err .response .status_code == 401 :
181+ raise InvalidToken
179182 raise err
180183
181184 # A wrong code returns 200 with a fail state
Original file line number Diff line number Diff line change @@ -601,6 +601,19 @@ def test_client_lock_called_twice(server, mocker):
601601 assert len (server .calls ) == 1
602602
603603
604+ def test_client_lock_invalid_token (server , mocker ):
605+ """Should raise a CodeError if the token is expired while calling Lock()."""
606+ server .add (responses .POST , "https://example.com/api/panel/syncLogin" , status = 401 )
607+ client = ElmoClient (base_url = "https://example.com" , domain = "domain" )
608+ client ._session_id = "test"
609+ mocker .patch .object (client , "unlock" )
610+ # Test
611+ with pytest .raises (InvalidToken ):
612+ with client .lock ("test" ):
613+ pass
614+ assert len (server .calls ) == 1
615+
616+
604617def test_client_lock_unknown_error (server , mocker ):
605618 """Should raise an Exception for unknown status code."""
606619 server .add (
You can’t perform that action at this time.
0 commit comments