Ejemplo n.º 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')
Ejemplo n.º 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"
Ejemplo n.º 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
Ejemplo n.º 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)'
Ejemplo n.º 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)
Ejemplo n.º 6
0
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'
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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)
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 15
0
def test_property():
    my_function = Lower(property=Property(name='users.name'))

    assert str(my_function) == 'lower(users.name)'
Ejemplo n.º 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'
Ejemplo n.º 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'
Ejemplo n.º 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'
Ejemplo n.º 19
0
def test_parse_error():
    with pytest.raises(ParseError):
        Count(
            property=Property(name='users.name', alias='name')
        )
Ejemplo n.º 20
0
def test_property():
    my_avg = Avg(property=Property(name='users.name'))

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

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

    assert str(my_function) == 'initcap(users.name) AS capitalized'
Ejemplo n.º 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'
Ejemplo n.º 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'
Ejemplo n.º 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'
Ejemplo n.º 26
0
def test_property():
    my_function = Unaccent(property=Property(name='users.name'))

    assert str(my_function) == 'unaccent(users.name)'
Ejemplo n.º 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'
Ejemplo n.º 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'