Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions oligo/asyncio/asynciber.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(self) -> None:
self.__session = None

async def close(self):
await self.__session.close()
if self.__session:
await self.__session.close()

async def __request(
self, path: str, data: Optional[Union[list, dict]] = None
Expand Down Expand Up @@ -73,8 +74,9 @@ async def login(self, user: str, password: str) -> bool:
]
data = await self.__request(LOGIN_URL, data=payload)
if data["success"] != "true":
await self.__session.close()
self.__session = None
raise LoginException()
raise LoginException(user)
return True

async def measurement(self) -> dict:
Expand Down
4 changes: 2 additions & 2 deletions oligo/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def __init__(self, status_code):


class LoginException(IberException):
def __init__(self):
super().__init__('Login error, bad login')
def __init__(self, username):
super().__init__(f'Unable to log in with user {username}')


class SessionException(IberException):
Expand Down
2 changes: 1 addition & 1 deletion oligo/requests/iber.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def login(self, user, password, session=Session()):
json_response = response.json()
if json_response["success"] != "true":
self.__session = None
raise LoginException()
raise LoginException(user)

def __check_session(self):
if not self.__session:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def test_message(self):
class TestLoginException(unittest.TestCase):

def test_message(self):
login_exception = LoginException()
self.assertEqual('Login error, bad login', login_exception.args[0])
login_exception = LoginException("pepe")
self.assertEqual('Unable to log in with user pepe', login_exception.args[0])


class TestSessionException(unittest.TestCase):
Expand Down