Example #1
0
 def __as_utc(dt):
     if hasattr(dt, "tzinfo"):
         if dt.tzinfo:
             return dt.astimezone(utc_timezone())
         else:
             return dt.replace(tzinfo=utc_timezone())
     return dt
Example #2
0
 def __as_utc(dt):
     if hasattr(dt, 'tzinfo'):
         if dt.tzinfo:
             return dt.astimezone(utc_timezone())
         else:
             return dt.replace(tzinfo=utc_timezone())
     return dt
Example #3
0
def test_can_fetch_page_of_pledges_with_custom_options_with_tzinfo():
    PAGE_COUNT = 25
    MOCK_CURSOR = datetime.datetime.now().replace(tzinfo=utc_timezone())
    MOCK_FIELDS = {'field': ['value']}
    MOCK_INCLUDES = ['mock includes']

    EXPECTED_CURSOR = MOCK_CURSOR.isoformat()

    response = client.fetch_page_of_pledges(
        MOCK_CAMPAIGN_ID,
        PAGE_COUNT,
        cursor=MOCK_CURSOR,
        includes=MOCK_INCLUDES,
        fields=MOCK_FIELDS,
    )

    query_params = {
        'page[count]': PAGE_COUNT,
        'page[cursor]': EXPECTED_CURSOR,
        'includes': MOCK_INCLUDES,
        'fields': MOCK_FIELDS,
    }

    expected_url = api_url('campaigns', MOCK_CAMPAIGN_ID, 'pledges',
                           **query_params)

    return expected_url, response
Example #4
0
def test_get_webhooks_with_custom_options_without_tzinfo():
    MOCK_CURSOR = datetime.datetime.now()
    MOCK_FIELDS = {'field': ['value']}
    MOCK_INCLUDES = ['mock includes']

    EXPECTED_CURSOR = MOCK_CURSOR.replace(tzinfo=utc_timezone()).isoformat()
    url = 'webhooks'
    query_params = {
        'page[count]': PAGE_COUNT,
        'page[cursor]': MOCK_CURSOR,
        'includes': MOCK_INCLUDES,
        'fields': MOCK_FIELDS,
    }
    expected_url = api_url(url, **query_params)
    response = client.get_webhooks(
        PAGE_COUNT,
        cursor=MOCK_CURSOR,
        includes=MOCK_INCLUDES,
        fields=MOCK_FIELDS,
    )

    return expected_url, response
Example #5
0
def test_utc_timezone_returns_timezone_with_expected_tzname():
    assert utc_timezone.utc_timezone().tzname(None) in ['UTC', 'UTC+00:00']