diff --git a/monarchmoney/monarchmoney.py b/monarchmoney/monarchmoney.py index cc2d9f1..219b6b1 100644 --- a/monarchmoney/monarchmoney.py +++ b/monarchmoney/monarchmoney.py @@ -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." ) diff --git a/tests/test_monarchmoney.py b/tests/test_monarchmoney.py index 875f22d..d746f47 100644 --- a/tests/test_monarchmoney.py +++ b/tests/test_monarchmoney.py @@ -6,6 +6,7 @@ import json from gql import Client from monarchmoney import MonarchMoney +from monarchmoney.monarchmoney import LoginFailedException class TestMonarchMoney(unittest.IsolatedAsyncioTestCase): @@ -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}"