Esempio n. 1
0
def test_generate_date_series_start_date_none(end_date, interval, granularity):
    (interval_param, interval, interval_str) = interval
    (end_date_param, end_date, end_date_str) = end_date
    (granularity_param, granularity, granularity_str) = granularity
    start_date_str = end_date.strftime('%Y-%m-%d %H:%M:%S.%f')

    query = generate_date_series(None, end_date_param, interval_param, granularity_param)
    expression = query.compile(dialect=postgresql.dialect())
    expected = 'generate_series(DATE {} - INTERVAL {}, {}, {})'.format(
        start_date_str, interval_str, end_date_str, granularity_str)
    actual = str(expression) % expression.params
    assert expected == actual
Esempio n. 2
0
def test_generate_date_series_interval_none(start_date, end_date, granularity):
    interval_str = '1 month'
    (end_date_param, end_date, end_date_str) = end_date
    (start_date_param, start_date, start_date_str) = start_date
    (granularity_param, granularity, granularity_str) = granularity

    if not start_date_param:
        expected = 'generate_series(DATE {} - INTERVAL {}, {}, {})'.format(
            end_date_str, interval_str, end_date_str, granularity_str)
    else:
        expected = 'generate_series({}, {}, {})'.format(start_date_str, end_date_str, granularity_str)

    query = generate_date_series(
        start_date_param, end_date_param, None, granularity_param)
    expression = query.compile(dialect=postgresql.dialect())
    actual = str(expression) % expression.params
    assert expected == actual
Esempio n. 3
0
def test_generate_date_series_end_date_none(start_date, interval, granularity):
    (interval_param, interval, interval_str) = interval
    (start_date_param, start_date, start_date_str) = start_date
    (granularity_param, granularity, granularity_str) = granularity
    if start_date_param and interval_param:
        end_date_str = start_date.strftime('%Y-%m-%d %H:%M:%S.%f')
    else:
        end_date_str = UTCNOW.strftime('%Y-%m-%d %H:%M:%S.%f')

    if not start_date_param:
        expected = 'generate_series(DATE {} - INTERVAL {}, {}, {})'.format(
            end_date_str, interval_str, end_date_str, granularity_str)
    elif not interval_param:
        expected = 'generate_series({}, {}, {})'.format(start_date_str, end_date_str, granularity_str)
    else:
        expected = 'generate_series({}, DATE {} + INTERVAL {}, {})'.format(
            start_date_str, end_date_str, interval_str, granularity_str)

    query = generate_date_series(start_date_param, None, interval_param, granularity_param)
    expression = query.compile(dialect=postgresql.dialect())
    actual = str(expression) % expression.params
    assert expected == actual