Ejemplo n.º 1
0
def test_json(client):
    """Test Pages.json() returns raw json for page one.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    assert pages.json() == TEST_DATA_PAGE_ONE
Ejemplo n.º 2
0
def test_json(client):
    """Test Pages.json() returns raw json for page one.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    assert pages.json() == TEST_DATA_PAGE_ONE
Ejemplo n.º 3
0
def test_current_page(client):
    """Test Pages.current_page() returns current page.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    assert pages.current_page() == TEST_DATA_PAGE_ONE['events']
Ejemplo n.º 4
0
def test_current_page(client):
    """Test Pages.current_page() returns current page.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    assert pages.current_page() == TEST_DATA_PAGE_ONE['events']
Ejemplo n.º 5
0
def test_fetch_next_page(client):
    """Test Pages.fetch_next_page() fetches next page.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    responses.add(**NEXT_PAGE_GET_ARGS)
    pages.fetch_next_page()
    assert pages[0]['summary'] == TEST_DATA_PAGE_TWO['events'][0]['summary']
Ejemplo n.º 6
0
def test_fetch_next_page(client):
    """Test Pages.fetch_next_page() fetches next page.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    responses.add(**NEXT_PAGE_GET_ARGS)
    pages.fetch_next_page()
    assert pages[0]['summary'] == TEST_DATA_PAGE_TWO['events'][0]['summary']
Ejemplo n.º 7
0
def test_all(client):
    """Test Pages.all() returns all pages.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    responses.add(**NEXT_PAGE_GET_ARGS)
    results = pages.all()
    assert len(results) == 2
    assert results[0]['summary'] == TEST_DATA_PAGE_ONE['events'][0]['summary']
    assert results[1]['summary'] == TEST_DATA_PAGE_TWO['events'][0]['summary']
Ejemplo n.º 8
0
def test_all(client):
    """Test Pages.all() returns all pages.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    responses.add(**NEXT_PAGE_GET_ARGS)
    results = pages.all()
    assert len(results) == 2
    assert results[0]['summary'] == TEST_DATA_PAGE_ONE['events'][0]['summary']
    assert results[1]['summary'] == TEST_DATA_PAGE_TWO['events'][0]['summary']
Ejemplo n.º 9
0
def test___len__(client):
    """Test Pages.__len__() returns the length of the current page of data.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    assert len(pages) == 1
Ejemplo n.º 10
0
def test___getitem__(client):
    """Test Pages.__getitem__() returns the item at the specified index.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    assert pages[0]['summary'] == TEST_DATA_PAGE_ONE['events'][0]['summary']
Ejemplo n.º 11
0
    def read_free_busy(self,
                       calendar_ids=(),
                       from_date=None,
                       to_date=None,
                       last_modified=None,
                       tzid=settings.DEFAULT_TIMEZONE_ID,
                       include_managed=True,
                       localized_times=False,
                       automatic_pagination=True):
        """Read free/busy blocks for linked account (optionally for the specified calendars).

        :param tuple calendar_ids: Tuple or list of calendar ids to pass to cronofy. (Optional).
        :param datetime.date from_date: Start datetime (or ISO8601 string) for query. (Optional).
        :param datetime.date to_date: End datetime (or ISO8601 string) for query. (Optional).
        :param string tzid: Timezone ID for query. (Optional, default settings.DEFAULT_TIMEZONE_ID). Should match tzinfo on datetime objects.
        :param bool include_managed: Include pages created through the API. (Optional, default True)
        :param bool localized_times: Return time values for event start/end with localization information. This varies across providers. (Optional, default False).
        :param bool automatic_pagination: Automatically fetch next page when iterating through results (Optional, default True)
        :return: Wrapped results (Containing first page of free/busy blocks).
        :rtype: ``Pages``
        """
        results = self.request_handler.get(endpoint='free_busy', params={
            'tzid': tzid,
            'calendar_ids[]': calendar_ids,
            'from': format_event_time(from_date),
            'to': format_event_time(to_date),
            'include_managed': include_managed,
            'localized_times': localized_times,
        }).json()

        return Pages(self.request_handler, results, 'free_busy', automatic_pagination)
Ejemplo n.º 12
0
def test_next(client):
    """Test Pages iterator iterates through all pages.

    :param Client client: Client instance with test data.
    """
    pages = Pages(request_handler=client.request_handler, data=deepcopy(TEST_DATA_PAGE_ONE), data_type='events')
    responses.add(**NEXT_PAGE_GET_ARGS)
    results = []
    for item in pages:
        results.append(item)
    assert len(results) == 2
    assert results[0]['summary'] == TEST_DATA_PAGE_ONE['events'][0]['summary']
    assert results[1]['summary'] == TEST_DATA_PAGE_TWO['events'][0]['summary']
Ejemplo n.º 13
0
    def read_events(self,
                    calendar_ids=(),
                    from_date=None,
                    to_date=None,
                    last_modified=None,
                    tzid=settings.DEFAULT_TIMEZONE_ID,
                    only_managed=False,
                    include_managed=True,
                    include_deleted=False,
                    include_moved=False,
                    include_geo=False,
                    localized_times=False,
                    automatic_pagination=True):
        """Read events for linked account (optionally for the specified calendars).

        :param tuple calendar_ids: Tuple or list of calendar ids to pass to cronofy. (Optional).
        :param datetime.date from_date: Start datetime (or ISO8601 string) for query. (Optional).
        :param datetime.date to_date: End datetime (or ISO8601 string) for query. (Optional).
        :param datetime.datetime last_modified: Return items modified on or after last_modified. Datetime or ISO8601 string. (Optional).
        :param string tzid: Timezone ID for query. (Optional, default settings.DEFAULT_TIMEZONE_ID). Should match tzinfo on datetime objects.
        :param bool only_managed: Only include events created through the API. (Optional, default False)
        :param bool include_managed: Include events created through the API. (Optional, default True)
        :param bool include_deleted: Include deleted events. (Optional, default False)
        :param bool include_moved: Include events that ever existed within the from_date/to_date time window. (Optional, default False)
        :param bool include_geo: Include any geo location information for events when available (Optional, default False)
        :param bool localized_times: Return time values for event start/end with localization information. This varies across providers. (Optional, default False).
        :param bool automatic_pagination: Autonatically fetch next page when iterating through results (Optional, default True)
        :return: Wrapped results (Containing first page of events).
        :rtype: ``Pages``
        """
        results = self.request_handler.get(
            endpoint='events',
            params={
                'tzid': tzid,
                'calendar_ids[]': calendar_ids,
                'from': format_event_time(from_date),
                'to': format_event_time(to_date),
                'last_modified': format_event_time(last_modified),
                'only_managed': only_managed,
                'include_managed': include_managed,
                'include_deleted': include_deleted,
                'include_moved': include_moved,
                'include_geo': include_geo,
                'localized_times': localized_times,
            }).json()

        return Pages(self.request_handler, results, 'events',
                     automatic_pagination)