Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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}'"
         )
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 def test_account_property(self):
     ews_api = EWSApi('user1', 'pass1')
     ews_api._account = 'expected'
     self.assertEqual('expected', ews_api.account)
Exemplo n.º 8
0
 def test_initialize_no_password_raise_value_error(self):
     ews_api = EWSApi('user1', '')
     self.assertRaises(ValueError, ews_api.initialize)