def test_load_account_new_account(self): ews_api = EWSApi('user1', 'pass1') ews_api.load_account('*****@*****.**', account_class=self.account_class) self.assertEqual('*****@*****.**', ews_api._account.primary_smtp_address) self.assertIsInstance(ews_api._account, self.account_class)
def test_initialize_password_is_good(self): ews_api = EWSApi('user1', 'pass1') try: ews_api.initialize() except Exception as e: self.fail( f"Should not have raised exception but raised {e.__class__}: '{e}'" )
def test_get_account(self): ews_api = EWSApi('user1', 'pass1') ews_api._account = 'expected' def stub(*args, **kwargs): pass result = ews_api.get_account('*****@*****.**', load=stub) self.assertEqual('expected', result)
def test_load_account_existing_account_but_requesting_new_email(self): ews_api = EWSApi('user1', 'pass1') ews_api._account = self.account_class( '*****@*****.**', access_type=ews_api.access_type, credentials=ews_api.credentials, config=ews_api.config, ) class Expected(self.account_class): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) ews_api.load_account('*****@*****.**', account_class=Expected) self.assertEqual('*****@*****.**', ews_api._account.primary_smtp_address) self.assertIsInstance(ews_api._account, Expected)
def test_load_account_existing_account_same_smtp_address(self): ews_api = EWSApi('user1', 'pass1') ews_api._account = self.account_class( '*****@*****.**', access_type=ews_api.access_type, credentials=ews_api.credentials, config=ews_api.config, ) class NotExpected: def __init__(self, *args, **kwargs): pass ews_api.load_account(' [email protected] ', account_class=NotExpected) self.assertEqual('*****@*****.**', ews_api._account.primary_smtp_address) self.assertIsInstance(ews_api._account, self.account_class) self.assertNotIsInstance(ews_api._account, NotExpected)
def test_api_init_custom_adapter(self): class FakeAdapter: def __init__(self): pass adapter = FakeAdapter() import exchangelib _ = EWSApi('user1', 'pass1', adapter=adapter) self.assertIsInstance( exchangelib.protocol.BaseProtocol.HTTP_ADAPTER_CLS, FakeAdapter)
def test_account_property(self): ews_api = EWSApi('user1', 'pass1') ews_api._account = 'expected' self.assertEqual('expected', ews_api.account)
def test_initialize_no_password_raise_value_error(self): ews_api = EWSApi('user1', '') self.assertRaises(ValueError, ews_api.initialize)