Skip to content

Commit

Permalink
Merge pull request #92 from hammem/better_login_error_handling
Browse files Browse the repository at this point in the history
Improve input handling on interactive_login() and login()
  • Loading branch information
hammem authored Apr 14, 2024
2 parents 49d508f + caed232 commit d240da0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion monarchmoney/monarchmoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def login(
self.load_session(self._session_file)
return

if email is None or password is None:
if (email is None) or (password is None) or (email == "") or (password == ""):
raise LoginFailedException(
"Email and password are required to login when not using a saved session."
)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_monarchmoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
from gql import Client
from monarchmoney import MonarchMoney
from monarchmoney.monarchmoney import LoginFailedException


class TestMonarchMoney(unittest.IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -199,6 +200,26 @@ async def test_get_account_holdings(self, mock_execute_async):
"Expected third holding name to be 'U S Dollar'",
)

async def test_login(self):
"""
Test the login method with empty values for email and password.
"""
with self.assertRaises(LoginFailedException):
await self.monarch_money.login(use_saved_session=False)
with self.assertRaises(LoginFailedException):
await self.monarch_money.login(
email="", password="", use_saved_session=False
)

@patch("builtins.input", return_value="")
@patch("getpass.getpass", return_value="")
async def test_interactive_login(self, _input_mock, _getpass_mock):
"""
Test the interactive_login method with empty values for email and password.
"""
with self.assertRaises(LoginFailedException):
await self.monarch_money.interactive_login(use_saved_session=False)

@classmethod
def loadTestData(cls, filename) -> dict:
filename = f"{os.path.dirname(os.path.realpath(__file__))}/{filename}"
Expand Down

0 comments on commit d240da0

Please sign in to comment.