Esempio n. 1
0
    def test_get_free_busy_info(self):
        tz = EWSTimeZone('Europe/Copenhagen')
        server_timezones = list(self.account.protocol.get_timezones(return_full_timezone_data=True))
        start = EWSDateTime.now(tz=tz)
        end = EWSDateTime.now(tz=tz) + datetime.timedelta(hours=6)
        accounts = [(self.account, 'Organizer', False)]

        with self.assertRaises(ValueError):
            self.account.protocol.get_free_busy_info(accounts=[(123, 'XXX', 'XXX')], start=0, end=0)
        with self.assertRaises(ValueError):
            self.account.protocol.get_free_busy_info(accounts=[(self.account, 'XXX', 'XXX')], start=0, end=0)
        with self.assertRaises(ValueError):
            self.account.protocol.get_free_busy_info(accounts=[(self.account, 'Organizer', 'XXX')], start=0, end=0)
        with self.assertRaises(ValueError):
            self.account.protocol.get_free_busy_info(accounts=accounts, start=end, end=start)
        with self.assertRaises(ValueError):
            self.account.protocol.get_free_busy_info(accounts=accounts, start=start, end=end,
                                                     merged_free_busy_interval='XXX')
        with self.assertRaises(ValueError):
            self.account.protocol.get_free_busy_info(accounts=accounts, start=start, end=end, requested_view='XXX')

        for view_info in self.account.protocol.get_free_busy_info(accounts=accounts, start=start, end=end):
            self.assertIsInstance(view_info, FreeBusyView)
            self.assertIsInstance(view_info.working_hours_timezone, TimeZone)
            ms_id = view_info.working_hours_timezone.to_server_timezone(server_timezones, start.year)
            self.assertIn(ms_id, {t[0] for t in CLDR_TO_MS_TIMEZONE_MAP.values()})

        # Test account as simple email
        for view_info in self.account.protocol.get_free_busy_info(
                accounts=[(self.account.primary_smtp_address, 'Organizer', False)], start=start, end=end
        ):
            self.assertIsInstance(view_info, FreeBusyView)
Esempio n. 2
0
    def test_get_free_busy_info(self):
        tz = self.account.default_timezone
        server_timezones = list(
            self.account.protocol.get_timezones(
                return_full_timezone_data=True))
        start = datetime.datetime.now(tz=tz)
        end = datetime.datetime.now(tz=tz) + datetime.timedelta(hours=6)
        accounts = [(self.account, "Organizer", False)]

        with self.assertRaises(TypeError) as e:
            self.account.protocol.get_free_busy_info(accounts=[(123, "XXX",
                                                                "XXX")],
                                                     start=start,
                                                     end=end)
        self.assertEqual(
            e.exception.args[0],
            "Field 'email' value 123 must be of type <class 'exchangelib.properties.Email'>"
        )
        with self.assertRaises(ValueError) as e:
            self.account.protocol.get_free_busy_info(accounts=[(self.account,
                                                                "XXX", "XXX")],
                                                     start=start,
                                                     end=end)
        self.assertEqual(
            e.exception.args[0],
            f"Invalid choice 'XXX' for field 'attendee_type'. Valid choices are {sorted(MailboxData.ATTENDEE_TYPES)}",
        )
        with self.assertRaises(TypeError) as e:
            self.account.protocol.get_free_busy_info(accounts=[
                (self.account, "Organizer", "X")
            ],
                                                     start=start,
                                                     end=end)
        self.assertEqual(
            e.exception.args[0],
            "Field 'exclude_conflicts' value 'X' must be of type <class 'bool'>"
        )
        with self.assertRaises(ValueError) as e:
            self.account.protocol.get_free_busy_info(accounts=accounts,
                                                     start=end,
                                                     end=start)
        self.assertIn("'start' must be less than 'end'", e.exception.args[0])
        with self.assertRaises(TypeError) as e:
            self.account.protocol.get_free_busy_info(
                accounts=accounts,
                start=start,
                end=end,
                merged_free_busy_interval="XXX")
        self.assertEqual(
            e.exception.args[0],
            "Field 'merged_free_busy_interval' value 'XXX' must be of type <class 'int'>"
        )
        with self.assertRaises(ValueError) as e:
            self.account.protocol.get_free_busy_info(accounts=accounts,
                                                     start=start,
                                                     end=end,
                                                     requested_view="XXX")
        self.assertEqual(
            e.exception.args[0],
            f"Invalid choice 'XXX' for field 'requested_view'. Valid choices are "
            f"{sorted(FreeBusyViewOptions.REQUESTED_VIEWS)}",
        )

        for view_info in self.account.protocol.get_free_busy_info(
                accounts=accounts, start=start, end=end):
            self.assertIsInstance(view_info, FreeBusyView)
            self.assertIsInstance(view_info.working_hours_timezone, TimeZone)
            ms_id = view_info.working_hours_timezone.to_server_timezone(
                server_timezones, start.year)
            self.assertIn(ms_id,
                          {t[0]
                           for t in CLDR_TO_MS_TIMEZONE_MAP.values()})

        # Test account as simple email
        for view_info in self.account.protocol.get_free_busy_info(accounts=[
            (self.account.primary_smtp_address, "Organizer", False)
        ],
                                                                  start=start,
                                                                  end=end):
            self.assertIsInstance(view_info, FreeBusyView)