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')
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"
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
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)'
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'
def test_simple(): my_count = Count( property=Property(name='users.id'), alias='user"_count' ) assert str(my_count) == "COUNT(users.id) AS user_count"
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"
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"
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"
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)
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"
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"
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"
def test_property(): my_function = Lower(property=Property(name='users.name')) assert str(my_function) == 'lower(users.name)'
def test_alias(): my_function = Lower(property=Property(name='users.name'), alias='"lower_name') assert str(my_function) == 'lower(users.name) AS lower_name'
def test_simple(): my_function = Sum(property=Property(name='transactions.amount'), alias='total_amount') assert str(my_function) == 'SUM(transactions.amount) AS total_amount'
def test_alias(): my_avg = Avg(property=Property(name='users.name'), alias='"avg_name') assert str(my_avg) == 'AVG(users.name) AS avg_name'
def test_parse_error(): with pytest.raises(ParseError): Count( property=Property(name='users.name', alias='name') )
def test_property(): my_avg = Avg(property=Property(name='users.name')) assert str(my_avg) == 'AVG(users.name)'
def test_property(): my_function = InitCap(property=Property(name='users.name')) assert str(my_function) == 'initcap(users.name)'
def test_alias(): my_function = InitCap(property=Property(name='users.name'), alias='"capitalized') assert str(my_function) == 'initcap(users.name) AS capitalized'
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'
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'
def test_alias(): my_function = Unaccent(property=Property(name='users.name'), alias='"avg_name') assert str(my_function) == 'unaccent(users.name) AS avg_name'
def test_property(): my_function = Unaccent(property=Property(name='users.name')) assert str(my_function) == 'unaccent(users.name)'
def test_alias(): my_function = Upper(property=Property(name='users.name'), alias='"upper_name') assert str(my_function) == 'upper(users.name) AS upper_name'
def test_simple(): my_function = Weekday(property=Property(name='users.birthday'), alias='special_day') assert str(my_function) == 'WEEKDAY(users.birthday) AS special_day'