Пример #1
0
    def test_set_username_and_password(self, logger):
        """Test setting user name and password.

        This doesn't do much, since set_user_name_and_password has no failure
        conditions.  We could test that it actually does what it's supposed to
        do, except that means checking the implementation.
        """
        calendar_data = CalendarData(logger, CALENDAR_NAME, TEST_URL,
                                     timedelta(minutes=5))
        calendar_data.set_user_name_password("username", "password")
Пример #2
0
    def test_download_calendar(self, logger):
        """Test download_calendar sets cache from the mocked HTTPHandler.

        This test relies on the success of test_get!
        """
        calendar_data = CalendarData(logger, CALENDAR_NAME, TEST_URL,
                                     timedelta(minutes=5))
        opener = build_opener(MockHTTPHandler)
        install_opener(opener)
        calendar_data.download_calendar()
        assert calendar_data.get() == CALENDAR_DATA
Пример #3
0
    def test_download_calendar_Error(self, logger):
        """Test that None is cached for BaseException.

        This test relies on the success of test_get!
        """
        calendar_data = CalendarData(logger, CALENDAR_NAME, TEST_URL,
                                     timedelta(minutes=5))
        opener = build_opener(MockHTTPHandlerError)
        install_opener(opener)
        calendar_data.download_calendar()
        assert calendar_data.get() is None
Пример #4
0
    def test_download_too_quickly_returns_old_data(self, mock_hanow, logger):
        """Test that get does not download if not enough time has passed."""
        mock_hanow.side_effect = [
            dtparser.parse("2022-01-01T00:00:00"),
            dtparser.parse("2022-01-01T00:04:59"),
        ]
        calendar_data = CalendarData(logger, CALENDAR_NAME, TEST_URL,
                                     timedelta(minutes=5))
        opener = build_opener(MockHTTPHandler)
        install_opener(opener)
        assert calendar_data.download_calendar()
        assert calendar_data.get() == CALENDAR_DATA

        opener = build_opener(MockHTTPHandler2)
        install_opener(opener)
        assert not calendar_data.download_calendar()
        assert calendar_data.get() == CALENDAR_DATA
Пример #5
0
 def test_get(self, logger):
     """Test get method retrieves cached data."""
     calendar_data = CalendarData(logger, CALENDAR_NAME, TEST_URL,
                                  timedelta(minutes=5))
     set_calendar_data(calendar_data, CALENDAR_DATA)
     assert calendar_data.get() == CALENDAR_DATA
Пример #6
0
def set_calendar_data(calendar_data: CalendarData, data: str):
    """Set _calendarData for the passed CalendarData object."""
    calendar_data._calendar_data = data  # pylint: disable=W0212