From 225936bf48c5cd75b2ad3129d2eae91090ff4a65 Mon Sep 17 00:00:00 2001 From: slymit Date: Sun, 26 May 2024 19:34:20 +0300 Subject: [PATCH] Rename variables in tests --- test/interface/test_filters.py | 228 +++++++++++++++--------------- test/interface/test_loads.py | 50 +++---- test/interface/test_pagination.py | 84 +++++------ test/interface/test_sorting.py | 84 +++++------ 4 files changed, 223 insertions(+), 223 deletions(-) diff --git a/test/interface/test_filters.py b/test/interface/test_filters.py index 93c556c..fc0094e 100644 --- a/test/interface/test_filters.py +++ b/test/interface/test_filters.py @@ -90,9 +90,9 @@ def test_no_filters_provided(self, session): stmt = select(Bar) filters = [] - filtered_query = apply_filters(stmt, filters) + filtered_stmt = apply_filters(stmt, filters) - assert stmt == filtered_query + assert stmt == filtered_stmt @pytest.mark.parametrize('filter_', ['some text', 1, '']) def test_wrong_filters_format(self, session, filter_): @@ -121,8 +121,8 @@ def test_no_operator_provided(self, session): stmt = select(Bar) filters = [{'field': 'name', 'value': 'name_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -192,8 +192,8 @@ def test_multiple_models(self, session): {'model': 'Qux', 'field': 'name', 'op': '==', 'value': 'name_1'}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).unique().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).unique().all() assert len(result) == 4 bars, quxs = zip(*result) @@ -216,8 +216,8 @@ def test_auto_join(self, session): {'model': 'Bar', 'field': 'count', 'op': 'is_null'}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -247,8 +247,8 @@ def test_noop_if_query_contains_named_models(self, session): {'model': 'Bar', 'field': 'count', 'op': 'is_null'}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -292,8 +292,8 @@ def test_eager_load(self, session): {'model': 'Bar', 'field': 'count', 'op': 'is_null'}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -308,8 +308,8 @@ def test_filter_field_with_null_values(self, session): stmt = select(Bar) filters = [{'field': 'count', 'op': 'is_null'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -319,8 +319,8 @@ def test_filter_field_with_no_null_values(self, session): stmt = select(Bar) filters = [{'field': 'name', 'op': 'is_null'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 0 @@ -332,8 +332,8 @@ def test_filter_field_with_null_values(self, session): stmt = select(Bar) filters = [{'field': 'count', 'op': 'is_not_null'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 3 assert result[0].id == 1 @@ -345,8 +345,8 @@ def test_filter_field_with_no_null_values(self, session): stmt = select(Bar) filters = [{'field': 'name', 'op': 'is_not_null'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 4 assert result[0].id == 1 @@ -362,8 +362,8 @@ def test_concatenate_queries(self, session): stmt = select(Bar) filters = [{'field': 'name', 'op': '==', 'value': 'name_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -373,8 +373,8 @@ def test_concatenate_queries(self, session): filters = [{'field': 'id', 'op': '==', 'value': 3}] - filtered_query = apply_filters(filtered_query, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(filtered_stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -388,8 +388,8 @@ def test_a_single_dict_can_be_supplied_as_filters(self, session): stmt = select(Bar) filters = {'field': 'name', 'op': '==', 'value': 'name_1'} - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -405,8 +405,8 @@ def test_apply_filter_on_single_field_query(self, session): stmt = select(Bar.id) filters = [{'field': 'name', 'op': '==', 'value': 'name_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).all() assert len(result) == 2 assert result[0] == (1,) @@ -417,8 +417,8 @@ def test_apply_filter_on_aggregate_query(self, session): stmt = select(func.count(Bar.id)) filters = [{'field': 'name', 'op': '==', 'value': 'name_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).all() assert len(result) == 1 assert result[0] == (2,) @@ -432,8 +432,8 @@ def test_one_filter_applied_to_a_single_model(self, session, operator): stmt = select(Bar) filters = [{'field': 'name', 'op': operator, 'value': 'name_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -459,8 +459,8 @@ def test_multiple_filters_applied_to_a_single_model( ): stmt = select(Bar) - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -475,8 +475,8 @@ def test_one_filter_applied_to_a_single_model(self, session, operator): stmt = select(Bar) filters = [{'field': 'name', 'op': operator, 'value': 'name_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 2 @@ -495,8 +495,8 @@ def test_multiple_filters_applied_to_a_single_model( {'field': 'id', 'op': operator, 'value': 3} ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -513,8 +513,8 @@ def test_one_filter_applied_to_a_single_model(self, session, operator): stmt = select(Bar) filters = [{'field': 'count', 'op': operator, 'value': '5'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 2 @@ -531,8 +531,8 @@ def test_multiple_filters_applied_to_a_single_model( {'field': 'id', 'op': operator, 'value': 2}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 4 @@ -546,8 +546,8 @@ def test_one_filter_applied_to_a_single_model(self, session, operator): stmt = select(Bar) filters = [{'field': 'count', 'op': operator, 'value': '7'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 1 @@ -563,8 +563,8 @@ def test_multiple_filters_applied_to_a_single_model( {'field': 'id', 'op': operator, 'value': 1}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 0 @@ -577,8 +577,8 @@ def test_one_filter_applied_to_a_single_model(self, session, operator): stmt = select(Bar) filters = [{'field': 'count', 'op': operator, 'value': '5'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 3 assert result[0].id == 1 @@ -596,8 +596,8 @@ def test_multiple_filters_applied_to_a_single_model( {'field': 'id', 'op': operator, 'value': 4}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 4 @@ -611,8 +611,8 @@ def test_one_filter_applied_to_a_single_model(self, session, operator): stmt = select(Bar) filters = [{'field': 'count', 'op': operator, 'value': '15'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 3 assert result[0].id == 1 @@ -630,8 +630,8 @@ def test_multiple_filters_applied_to_a_single_model( {'field': 'id', 'op': operator, 'value': 1}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 1 @@ -644,8 +644,8 @@ def test_one_filter_applied_to_a_single_model(self, session): stmt = select(Bar) filters = [{'field': 'name', 'op': 'like', 'value': '%me_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -659,8 +659,8 @@ def test_one_filter_applied_to_a_single_model(self, session): stmt = select(Bar) filters = [{'field': 'name', 'op': 'ilike', 'value': '%ME_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -674,8 +674,8 @@ def test_one_filter_applied_to_a_single_model(self, session): stmt = select(Bar) filters = [{'field': 'name', 'op': 'not_ilike', 'value': '%ME_1'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 2 @@ -689,8 +689,8 @@ def test_field_not_in_value_list(self, session): stmt = select(Bar) filters = [{'field': 'count', 'op': 'in', 'value': [1, 2, 3]}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).all() assert len(result) == 0 @@ -699,8 +699,8 @@ def test_field_in_value_list(self, session): stmt = select(Bar) filters = [{'field': 'count', 'op': 'in', 'value': [15, 2, 3]}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 4 @@ -713,8 +713,8 @@ def test_field_not_in_value_list(self, session): stmt = select(Bar) filters = [{'field': 'count', 'op': 'not_in', 'value': [1, 2, 3]}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 3 assert result[0].id == 1 @@ -726,8 +726,8 @@ def test_field_in_value_list(self, session): stmt = select(Bar) filters = [{'field': 'count', 'op': 'not_in', 'value': [15, 2, 3]}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -752,8 +752,8 @@ def test_filter_date_equality(self, session, value): 'value': value }] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].created_at == datetime.date(2016, 7, 14) @@ -774,8 +774,8 @@ def test_filter_multiple_dates(self, session, value): 'value': value }] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].created_at == datetime.date(2016, 7, 13) @@ -786,8 +786,8 @@ def test_null_date(self, session): stmt = select(Qux) filters = [{'field': 'created_at', 'op': 'is_null'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].created_at is None @@ -810,8 +810,8 @@ def test_filter_time_equality(self, session, is_sqlite, value): stmt = select(Qux) filters = [{'field': 'expiration_time', 'op': '==', 'value': value}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].expiration_time == datetime.time(3, 5, 9) @@ -835,8 +835,8 @@ def test_filter_multiple_times(self, session, is_sqlite, value): 'value': value }] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].expiration_time == datetime.time(2, 5, 9) @@ -847,8 +847,8 @@ def test_null_time(self, session): stmt = select(Qux) filters = [{'field': 'expiration_time', 'op': 'is_null'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].expiration_time is None @@ -876,8 +876,8 @@ def test_filter_datetime_equality(self, session, is_sqlite, value): 'value': value }] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].execution_time == datetime.datetime( @@ -904,8 +904,8 @@ def test_filter_multiple_datetimes(self, session, is_sqlite, value): 'value': value }] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].execution_time == datetime.datetime( @@ -920,8 +920,8 @@ def test_null_datetime(self, session): stmt = select(Qux) filters = [{'field': 'execution_time', 'op': 'is_null'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].execution_time is None @@ -939,8 +939,8 @@ def test_or(self, session): ]}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -955,8 +955,8 @@ def test_or_with_one_arg(self, session): ]}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 1 @@ -972,8 +972,8 @@ def test_or_with_three_args(self, session): ]}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 3 assert result[0].id == 1 @@ -1016,8 +1016,8 @@ def test_and(self, session): ]}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 2 @@ -1031,8 +1031,8 @@ def test_and_with_one_arg(self, session): ]}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -1048,8 +1048,8 @@ def test_and_with_three_args(self, session): ]}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 1 @@ -1089,8 +1089,8 @@ def test_not(self, session): ]}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 3 assert result[0].id == 1 @@ -1149,8 +1149,8 @@ def test_complex(self, session): } ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -1176,8 +1176,8 @@ def test_complex_using_tuples(self, session): }, ) - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 @@ -1193,8 +1193,8 @@ def test_any_value_in_array(self, session, is_postgresql): stmt = select(Corge) filters = [{'field': 'tags', 'op': 'any', 'value': 'foo'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 2 @@ -1208,8 +1208,8 @@ def test_not_any_values_in_array(self, session, is_postgresql): stmt = select(Corge) filters = [{'field': 'tags', 'op': 'not_any', 'value': 'foo'}] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -1269,8 +1269,8 @@ def test_filter_by_hybrid_properties(self, session): }, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).all() assert len(result) == 2 bars, quxs = zip(*result) @@ -1302,8 +1302,8 @@ def test_filter_by_hybrid_methods(self, session): }, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).all() assert len(result) == 1 bars, quxs = zip(*result) @@ -1366,8 +1366,8 @@ def test_auto_join(self, session): {'table': 'bar', 'field': 'count', 'op': 'is_null'}, ] - filtered_query = apply_filters(stmt, filters) - result = session.execute(filtered_query).scalars().all() + filtered_stmt = apply_filters(stmt, filters) + result = session.execute(filtered_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 3 diff --git a/test/interface/test_loads.py b/test/interface/test_loads.py index 6b5f577..125cfe2 100644 --- a/test/interface/test_loads.py +++ b/test/interface/test_loads.py @@ -73,14 +73,14 @@ def test_no_load_provided(self, session): stmt = select(Bar).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) load_spec = [] - restricted_query = apply_loads(stmt, load_spec) + restricted_stmt = apply_loads(stmt, load_spec) # defers all fields expected = ( "SELECT bar.id AS bar_id \n" "FROM bar" ) - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected def test_single_value(self, session): @@ -89,13 +89,13 @@ def test_single_value(self, session): {'fields': ['name']} ] - restricted_query = apply_loads(stmt, loads) + restricted_stmt = apply_loads(stmt, loads) expected = ( "SELECT bar.id AS bar_id, bar.name AS bar_name \n" "FROM bar" ) - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected def test_multiple_values_single_model(self, session): @@ -104,14 +104,14 @@ def test_multiple_values_single_model(self, session): {'fields': ['name', 'count']} ] - restricted_query = apply_loads(stmt, loads) + restricted_stmt = apply_loads(stmt, loads) expected = ( "SELECT foo.id AS foo_id, foo.name AS foo_name, " "foo.count AS foo_count \n" "FROM foo" ) - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected def test_multiple_values_multiple_models(self, session): @@ -121,14 +121,14 @@ def test_multiple_values_multiple_models(self, session): {'model': 'Bar', 'fields': ['count']}, ] - restricted_query = apply_loads(stmt, loads) + restricted_stmt = apply_loads(stmt, loads) expected = ( "SELECT foo.id AS foo_id, foo.count AS foo_count, " "bar.id AS bar_id, bar.count AS bar_count \n" "FROM foo, bar" ) - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected def test_multiple_values_multiple_models_joined(self, session, db_uri): @@ -139,7 +139,7 @@ def test_multiple_values_multiple_models_joined(self, session, db_uri): {'model': 'Bar', 'fields': ['count']}, ] - restricted_query = apply_loads(stmt, loads) + restricted_stmt = apply_loads(stmt, loads) if "mysql" in db_uri and SQLALCHEMY_VERSION < Version("2.0.0"): join_type = "INNER JOIN" @@ -151,7 +151,7 @@ def test_multiple_values_multiple_models_joined(self, session, db_uri): "bar.id AS bar_id, bar.count AS bar_count \n" "FROM foo {join} bar ON bar.id = foo.bar_id".format(join=join_type) ) - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected def test_multiple_values_multiple_models_lazy_load(self, session, db_uri): @@ -162,7 +162,7 @@ def test_multiple_values_multiple_models_lazy_load(self, session, db_uri): {'model': 'Bar', 'fields': ['count']}, ] - restricted_query = apply_loads(stmt, loads) + restricted_stmt = apply_loads(stmt, loads) join_type = "INNER JOIN" if "mysql" in db_uri else "JOIN" @@ -173,10 +173,10 @@ def test_multiple_values_multiple_models_lazy_load(self, session, db_uri): ) if SQLALCHEMY_VERSION < Version("2.0.0"): - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected else: with pytest.raises(ArgumentError) as err: - str(restricted_query) + str(restricted_stmt) assert \ 'Mapped class Mapper[Bar(bar)] does not apply to any ' \ @@ -189,28 +189,28 @@ def test_a_single_dict_can_be_supplied_as_load_spec(self, session): stmt = select(Foo).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) load_spec = {'fields': ['name', 'count']} - restricted_query = apply_loads(stmt, load_spec) + restricted_stmt = apply_loads(stmt, load_spec) expected = ( "SELECT foo.id AS foo_id, foo.name AS foo_name, " "foo.count AS foo_count \n" "FROM foo" ) - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected def test_a_list_of_fields_can_be_supplied_as_load_spec(self, session): stmt = select(Foo).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) load_spec = ['name', 'count'] - restricted_query = apply_loads(stmt, load_spec) + restricted_stmt = apply_loads(stmt, load_spec) expected = ( "SELECT foo.id AS foo_id, foo.name AS foo_name, " "foo.count AS foo_count \n" "FROM foo" ) - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected def test_eager_load(self, session, db_uri): @@ -220,7 +220,7 @@ def test_eager_load(self, session, db_uri): {'model': 'Foo', 'fields': ['name']}, {'model': 'Bar', 'fields': ['count']} ] - restricted_query = apply_loads(stmt, load_spec) + restricted_stmt = apply_loads(stmt, load_spec) join_type = "INNER JOIN" if "mysql" in db_uri else "JOIN" @@ -238,10 +238,10 @@ def test_eager_load(self, session, db_uri): ) if SQLALCHEMY_VERSION < Version("2.0.0"): - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected else: with pytest.raises(ArgumentError) as err: - str(restricted_query) + str(restricted_stmt) assert \ 'Mapped class Mapper[Bar(bar)] does not apply to any ' \ @@ -261,7 +261,7 @@ def test_auto_join(self, session, db_uri): {'model': 'Bar', 'fields': ['count']}, ] - restricted_query = apply_loads(stmt, loads) + restricted_stmt = apply_loads(stmt, loads) join_type = "INNER JOIN" if "mysql" in db_uri else "JOIN" @@ -272,10 +272,10 @@ def test_auto_join(self, session, db_uri): ) if SQLALCHEMY_VERSION < Version("2.0.0"): - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected else: with pytest.raises(ArgumentError) as err: - str(restricted_query) + str(restricted_stmt) assert \ 'Mapped class Mapper[Bar(bar)] does not apply to any ' \ @@ -293,7 +293,7 @@ def test_noop_if_query_contains_named_models(self, session, db_uri): {'model': 'Bar', 'fields': ['count']}, ] - restricted_query = apply_loads(stmt, loads) + restricted_stmt = apply_loads(stmt, loads) if "mysql" in db_uri and SQLALCHEMY_VERSION < Version("2.0.0"): join_type = "INNER JOIN" @@ -305,7 +305,7 @@ def test_noop_if_query_contains_named_models(self, session, db_uri): "bar.id AS bar_id, bar.count AS bar_count \n" "FROM foo {join} bar ON bar.id = foo.bar_id".format(join=join_type) ) - assert str(restricted_query) == expected + assert str(restricted_stmt) == expected @pytest.mark.usefixtures('multiple_foos_inserted') def test_auto_join_to_invalid_model(self, session): diff --git a/test/interface/test_pagination.py b/test/interface/test_pagination.py index 192be80..0a85c3d 100644 --- a/test/interface/test_pagination.py +++ b/test/interface/test_pagination.py @@ -105,16 +105,16 @@ def test_no_pagination_info_provided(self, session): page_size = None page_number = None - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt == paginated_query + assert stmt == paginated_stmt assert Pagination( page_number=1, page_size=8, num_pages=1, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 8 for i in range(8): @@ -129,16 +129,16 @@ def test_page_size_greater_than_total_records(self, session): page_size = 5000 page_number = None - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=1, page_size=8, num_pages=1, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 8 for i in range(8): @@ -150,16 +150,16 @@ def test_page_size_provided(self, session): page_size = 2 page_number = None - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=1, page_size=2, num_pages=4, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -174,16 +174,16 @@ def test_first_page(self, session): page_size = None page_number = 1 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=1, page_size=8, num_pages=1, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 8 for i in range(8): @@ -195,16 +195,16 @@ def test_page_number_greater_than_one(self, session, page_number): stmt = select(Bar) page_size = None - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=page_number, page_size=8, num_pages=1, total_results=8 ) == pagination - result = session.execute(paginated_query).all() + result = session.execute(paginated_stmt).all() assert len(result) == 0 @@ -217,16 +217,16 @@ def test_page_size_zero(self, session, page_number): stmt = select(Bar) page_size = 0 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=page_number, page_size=0, num_pages=0, total_results=8 ) == pagination - result = session.execute(paginated_query).all() + result = session.execute(paginated_stmt).all() assert len(result) == 0 @@ -236,16 +236,16 @@ def test_page_size_zero_and_no_page_number_provided(self, session): page_size = 0 page_number = None - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=1, page_size=0, num_pages=0, total_results=8 ) == pagination - result = session.execute(paginated_query).all() + result = session.execute(paginated_stmt).all() assert len(result) == 0 @@ -255,15 +255,15 @@ def test_page_number_and_page_size_provided(self, session): page_size = 2 page_number = 3 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=3, page_size=2, num_pages=4, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 5 @@ -275,16 +275,16 @@ def test_get_individual_record(self, session): page_size = 1 page_number = 5 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=5, page_size=1, num_pages=8, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 1 assert result[0].id == 5 @@ -297,16 +297,16 @@ def test_page_number_greater_than_number_of_pages( stmt = select(Bar) page_size = 2 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=page_number, page_size=2, num_pages=4, total_results=8 ) == pagination - result = session.execute(paginated_query).all() + result = session.execute(paginated_stmt).all() assert len(result) == 0 @@ -316,16 +316,16 @@ def test_last_complete_page(self, session): page_size = 2 page_number = 4 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=4, page_size=2, num_pages=4, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 7 @@ -337,16 +337,16 @@ def test_last_incomplete_page(self, session): page_size = 5 page_number = 2 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=2, page_size=5, num_pages=2, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 3 assert result[0].id == 6 @@ -359,16 +359,16 @@ def test_get_first_page(self, session): page_size = 2 page_number = 1 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=1, page_size=2, num_pages=4, total_results=8 ) == pagination - result = session.execute(paginated_query).scalars().all() + result = session.execute(paginated_stmt).scalars().all() assert len(result) == 2 assert result[0].id == 1 @@ -382,16 +382,16 @@ def test_page_size_and_page_number_provided(self, session): page_size = 2 page_number = 1 - paginated_query, pagination = apply_pagination( + paginated_stmt, pagination = apply_pagination( stmt, page_number, page_size, session=session ) - assert stmt != paginated_query + assert stmt != paginated_stmt assert Pagination( page_number=1, page_size=2, num_pages=0, total_results=0 ) == pagination - result = session.execute(paginated_query).all() + result = session.execute(paginated_stmt).all() assert len(result) == 0 diff --git a/test/interface/test_sorting.py b/test/interface/test_sorting.py index 4b8f095..59cf671 100644 --- a/test/interface/test_sorting.py +++ b/test/interface/test_sorting.py @@ -70,9 +70,9 @@ def test_no_sort_provided(self, session): stmt = select(Bar) order_by = [] - filtered_query = apply_sort(stmt, order_by) + filtered_stmt = apply_sort(stmt, order_by) - assert stmt == filtered_query + assert stmt == filtered_stmt @pytest.mark.parametrize('sort', ['some text', 1, []]) def test_wrong_sort_format(self, session, sort): @@ -149,8 +149,8 @@ def test_single_sort_field_asc(self, session): stmt = select(Bar) order_by = [{'field': 'name', 'direction': 'asc'}] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.name for result in results] == [ 'name_1', 'name_1', 'name_1', 'name_1', @@ -164,8 +164,8 @@ def test_single_sort_field_desc(self, session): stmt = select(Bar) order_by = [{'field': 'name', 'direction': 'desc'}] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.name for result in results] == [ 'name_5', @@ -183,8 +183,8 @@ def test_multiple_sort_fields(self, session): {'field': 'id', 'direction': 'desc'}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [ (result.name, result.count, result.id) for result in results @@ -237,8 +237,8 @@ def test_multiple_models(self, session): {'model': 'Qux', 'field': 'count', 'direction': 'asc'}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert len(results) == 4 assert results[0].id == 3 @@ -251,8 +251,8 @@ def test_a_single_dict_can_be_supplied_as_sort_spec(self, session): stmt = select(Bar) sort_spec = {'field': 'name', 'direction': 'desc'} - sorted_query = apply_sort(stmt, sort_spec) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, sort_spec) + results = session.execute(sorted_stmt).scalars().all() assert [result.name for result in results] == [ 'name_5', @@ -276,8 +276,8 @@ def test_auto_join(self, session): {'field': 'id', 'direction': 'asc'}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [ (result.count, result.bar.name, result.id) for result in results @@ -304,8 +304,8 @@ def test_noop_if_query_contains_named_models(self, session): {'model': 'Foo', 'field': 'id', 'direction': 'asc'}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [ (result.count, result.bar.name, result.id) for result in results @@ -365,8 +365,8 @@ def test_eager_load(self, session): {'field': 'id', 'direction': 'asc'}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [ (result.count, result.bar.name, result.id) for result in results @@ -400,8 +400,8 @@ def test_single_sort_field_asc_nulls_first(self, session, is_postgresql): {'field': 'count', 'direction': 'asc', 'nullsfirst': True} ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.count for result in results] == [ None, None, 5, 10, 20, 30, 40, 50, @@ -417,8 +417,8 @@ def test_single_sort_field_desc_nulls_first(self, session, is_postgresql): {'field': 'count', 'direction': 'desc', 'nullsfirst': True} ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.count for result in results] == [ None, None, 50, 40, 30, 20, 10, 5, @@ -437,8 +437,8 @@ def test_multiple_sort_fields_asc_nulls_first( {'field': 'count', 'direction': 'asc', 'nullsfirst': True}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [(result.name, result.count) for result in results] == [ ('name_1', None), @@ -464,8 +464,8 @@ def test_multiple_sort_fields_desc_nulls_first( {'field': 'count', 'direction': 'desc', 'nullsfirst': True}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [(result.name, result.count) for result in results] == [ ('name_1', None), @@ -497,8 +497,8 @@ def test_single_sort_field_asc_nulls_last(self, session, is_postgresql): {'field': 'count', 'direction': 'asc', 'nullslast': True} ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.count for result in results] == [ 5, 10, 20, 30, 40, 50, None, None, @@ -514,8 +514,8 @@ def test_single_sort_field_desc_nulls_last(self, session, is_postgresql): {'field': 'count', 'direction': 'desc', 'nullslast': True} ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.count for result in results] == [ 50, 40, 30, 20, 10, 5, None, None, @@ -532,8 +532,8 @@ def test_multiple_sort_fields_asc_nulls_last(self, session, is_postgresql): {'field': 'count', 'direction': 'asc', 'nullslast': True}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [(result.name, result.count) for result in results] == [ ('name_1', 5), @@ -559,8 +559,8 @@ def test_multiple_sort_fields_desc_nulls_last( {'field': 'count', 'direction': 'desc', 'nullslast': True}, ] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [(result.name, result.count) for result in results] == [ ('name_1', 40), @@ -595,8 +595,8 @@ def test_single_sort_hybrid_property_asc(self, session): stmt = select(Bar) order_by = [{'field': 'count_square', 'direction': 'asc'}] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.count_square for result in results] == [ 1, 4, 4, 9, 25, 100, 144, 225 @@ -607,8 +607,8 @@ def test_single_sort_hybrid_property_desc(self, session): stmt = select(Bar) order_by = [{'field': 'count_square', 'direction': 'desc'}] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.count_square for result in results] == [ 225, 144, 100, 25, 9, 4, 4, 1 @@ -619,8 +619,8 @@ def test_single_sort_hybrid_method_asc(self, session): stmt = select(Bar) order_by = [{'field': 'three_times_count', 'direction': 'asc'}] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.three_times_count() for result in results] == [ 3, 6, 6, 9, 15, 30, 36, 45 @@ -631,8 +631,8 @@ def test_single_sort_hybrid_method_desc(self, session): stmt = select(Bar) order_by = [{'field': 'three_times_count', 'direction': 'desc'}] - sorted_query = apply_sort(stmt, order_by) - results = session.execute(sorted_query).scalars().all() + sorted_stmt = apply_sort(stmt, order_by) + results = session.execute(sorted_stmt).scalars().all() assert [result.three_times_count() for result in results] == [ 45, 36, 30, 15, 9, 6, 6, 3