Beispiel #1
0
def test_parse_error():
    with pytest.raises(ParseError):
        Concat(properties=[
            Property(name='users.name'),
            Constant(value=' '),
            Property(name='users.surname', alias='al')
        ],
               alias='full_name')
Beispiel #2
0
def test_simple():
    my_concat = Concat(properties=[
        Property(name='users.name'),
        Constant(value=' '),
        Property(name='users.surname')
    ],
                       alias='"full_name')

    assert str(
        my_concat) == "CONCAT(users.name, ' ', users.surname) AS full_name"
Beispiel #3
0
def test_simple():
    my_structure = Case(conditions=[
        Case.Condition(when=Comparision(properties=[
            Property(name='transactions.direction'),
            Constant(value='in')
        ],
                                        operation=Comparision.Operation.EQUAL),
                       then=Property(name='transactions.direction'))
    ],
                        alternative=Constant(value=0),
                        alias='test_case')

    sql = "(CASE WHEN (transactions.direction = 'in') THEN transactions.direction ELSE 0 END) AS test_case"
    assert str(my_structure) == sql
Beispiel #4
0
def test_simple():
    my_function = Extract(
        property=Property(name='users.created_at'),
        unit=Extract.Unit.CENTURY,
    )

    assert str(my_function) == 'EXTRACT(CENTURY FROM users.created_at)'
Beispiel #5
0
def test_simple():
    my_function = StringAgg(property=Property(name='transactions.amount'),
                            separator=', ',
                            alias='amounts')

    assert "STRING_AGG(transactions.amount, ', ') AS amounts" == str(
        my_function)
def test_simple():
    my_function = GroupConcat(
        property=Property(name='users.id'),
        alias='my_ids'
    )

    assert str(my_function) == 'GROUP_CONCAT(users.id) AS my_ids'
Beispiel #7
0
def test_simple():
    my_count = Count(
        property=Property(name='users.id'),
        alias='user"_count'
    )

    assert str(my_count) == "COUNT(users.id) AS user_count"
Beispiel #8
0
def test_property():
    my_function = ToChar(property=Property(name='users.created_at'),
                         format='HH12:MI:SS',
                         alias="formatted'_datetime")

    assert str(
        my_function
    ) == "to_char(users.created_at, 'HH12:MI:SS') AS formatted_datetime"
Beispiel #9
0
def test_simple():
    my_function = DateSub(
        property=Property(name='users.created_at'),
        interval=Interval(value=5, unit=Interval.Unit.DAY_MINUTE),
        alias="sub_dated"
    )

    assert str(my_function) == "DATE_SUB(users.created_at, INTERVAL 5 DAY_MINUTE) AS sub_dated"
Beispiel #10
0
def test_simple():
    my_function = DateFormat(property=Property(name='users.created_at'),
                             format='%Y-%m-%d %H:%i:%s',
                             alias="formatted'_datetime")

    assert str(
        my_function
    ) == "DATE_FORMAT(users.created_at, '%Y-%m-%d %H:%i:%s') AS formatted_datetime"
Beispiel #11
0
def test_advanced():
    my_function = StringAgg(property=CastOperator(
        property=Property(name='transactions.amount'),
        to=CastOperator.DataType.VARCHAR),
                            separator=', ',
                            alias='amounts')

    assert "STRING_AGG(transactions.amount::varchar, ', ') AS amounts" == str(
        my_function)
Beispiel #12
0
def test_simple():
    my_function = DateAdd(property=Property(name='users.created_at'),
                          interval=Interval(value=4,
                                            unit=Interval.Unit.YEAR_MONTH),
                          alias="add_dated")

    assert str(
        my_function
    ) == "DATE_ADD(users.created_at, INTERVAL 4 YEAR_MONTH) AS add_dated"
Beispiel #13
0
def test_simple():
    my_function = ConvertTimezone(
        property=Property(name='users.name'),
        date_from=Constant(value='+00:00'),
        date_to=Constant(value='Europe/Bratislava'),
        alias="'my_time"
    )

    assert str(my_function) == "CONVERT_TZ(users.name, '+00:00', 'Europe/Bratislava') AS my_time"
Beispiel #14
0
def test_distinct():
    my_count = Count(property=Distinct(property=Property(name='users.id')),
                     alias='distinct_count')
    assert str(my_count) == "COUNT(DISTINCT users.id) AS distinct_count"
Beispiel #15
0
def test_property():
    my_function = Lower(property=Property(name='users.name'))

    assert str(my_function) == 'lower(users.name)'
Beispiel #16
0
def test_alias():
    my_function = Lower(property=Property(name='users.name'), alias='"lower_name')

    assert str(my_function) == 'lower(users.name) AS lower_name'
Beispiel #17
0
def test_simple():
    my_function = Sum(property=Property(name='transactions.amount'),
                      alias='total_amount')

    assert str(my_function) == 'SUM(transactions.amount) AS total_amount'
Beispiel #18
0
def test_alias():
    my_avg = Avg(property=Property(name='users.name'), alias='"avg_name')

    assert str(my_avg) == 'AVG(users.name) AS avg_name'
Beispiel #19
0
def test_parse_error():
    with pytest.raises(ParseError):
        Count(
            property=Property(name='users.name', alias='name')
        )
Beispiel #20
0
def test_property():
    my_avg = Avg(property=Property(name='users.name'))

    assert str(my_avg) == 'AVG(users.name)'
Beispiel #21
0
def test_property():
    my_function = InitCap(property=Property(name='users.name'))

    assert str(my_function) == 'initcap(users.name)'
Beispiel #22
0
def test_alias():
    my_function = InitCap(property=Property(name='users.name'),
                          alias='"capitalized')

    assert str(my_function) == 'initcap(users.name) AS capitalized'
Beispiel #23
0
def test_min_simple():
    my_function = Min(property=Property(name='users.age'), alias='minimum_age')

    assert str(my_function) == 'MIN(users.age) AS minimum_age'
Beispiel #24
0
def test_max_simple():
    my_function = Max(property=Property(name='users.age'), alias='maximum_age')

    assert str(my_function) == 'MAX(users.age) AS maximum_age'
Beispiel #25
0
def test_alias():
    my_function = Unaccent(property=Property(name='users.name'), alias='"avg_name')

    assert str(my_function) == 'unaccent(users.name) AS avg_name'
Beispiel #26
0
def test_property():
    my_function = Unaccent(property=Property(name='users.name'))

    assert str(my_function) == 'unaccent(users.name)'
Beispiel #27
0
def test_alias():
    my_function = Upper(property=Property(name='users.name'),
                        alias='"upper_name')

    assert str(my_function) == 'upper(users.name) AS upper_name'
Beispiel #28
0
def test_simple():
    my_function = Weekday(property=Property(name='users.birthday'),
                          alias='special_day')

    assert str(my_function) == 'WEEKDAY(users.birthday) AS special_day'