def test_should_use_view__get_queryset__and_filter_it_with__filter_queryset( self): expected = ( u'SELECT "tests_app_bittestmodel"."id", "tests_app_bittestmodel"."is_active" ' u'FROM "tests_app_bittestmodel" ' u'WHERE "tests_app_bittestmodel"."is_active" = True ') response = ListSqlQueryKeyBit().get_data(**self.kwargs) self.assertEqual(response, expected)
class CustomListKeyConstructor(DefaultKeyConstructor): list_sql = ListSqlQueryKeyBit() pagination = PaginationKeyBit() updated_at = UpdatedAtKeyBit() print("List SQL", list_sql) print("pagination", pagination) print("updated_at", updated_at)
def test_should_use_view__get_queryset__and_filter_it_with__filter_queryset(self): expected = (u'SELECT "unit_bittestmodel"."id", "unit_bittestmodel"."is_active" ' u'FROM "unit_bittestmodel" ' u'WHERE "unit_bittestmodel"."is_active" = True{space}') space = '' expected = expected.format(space=space) response = ListSqlQueryKeyBit().get_data(**self.kwargs) self.assertEqual(response, expected)
class CustomListKeyConstructor(DefaultKeyConstructor): """ Used to compute cache key for a list of objects. """ list_sql = ListSqlQueryKeyBit() pagination = PaginationKeyBit() updated_at = UpdatedAtKeyBit() user = UserKeyBit() all_query_params = QueryParamsKeyBit()
def test_should_use_view__get_queryset__and_filter_it_with__filter_queryset(self): expected = (u'SELECT "tests_app_bittestmodel"."id", "tests_app_bittestmodel"."is_active" ' u'FROM "tests_app_bittestmodel" ' u'WHERE "tests_app_bittestmodel"."is_active" = True{space}') if get_django_features()['has_odd_space_in_sql_query']: space = ' ' else: space = '' expected = expected.format(space=space) response = ListSqlQueryKeyBit().get_data(**self.kwargs) self.assertEqual(response, expected)
def test_should_use_view__get_queryset__and_filter_it_with__filter_queryset( self): if django.VERSION >= (3, 1): expected = ( 'SELECT "unit_bittestmodel"."id", "unit_bittestmodel"."is_active" ' 'FROM "unit_bittestmodel" ' 'WHERE "unit_bittestmodel"."is_active"') else: expected = ( 'SELECT "unit_bittestmodel"."id", "unit_bittestmodel"."is_active" ' 'FROM "unit_bittestmodel" ' 'WHERE "unit_bittestmodel"."is_active" = True') response = ListSqlQueryKeyBit().get_data(**self.kwargs) self.assertEqual(response, expected)
def test_should_return_none_if_empty_result_set_raised(self): self.kwargs['view_instance'].filter_queryset = lambda x: x.filter(pk__in=[]) response = ListSqlQueryKeyBit().get_data(**self.kwargs) self.assertEqual(response, None)
class CustomListKeyConstructor(DefaultKeyConstructor): list_sql = ListSqlQueryKeyBit() pagination = PaginationKeyBit() updated_at = UpdatedAtKeyBit()