예제 #1
0
class CustomObjectKeyConstructor(DefaultKeyConstructor):
    """
    Used to compute cache key for a single object.
    """
    retrieve_sql = RetrieveSqlQueryKeyBit()
    updated_at = UpdatedAtKeyBit()
    user = UserKeyBit()
예제 #2
0
    def test_should_use_view__get_queryset__and_filter_it_with__filter_queryset__and_filter_by__lookup_field(self):
        expected = (u'SELECT "unit_bittestmodel"."id", "unit_bittestmodel"."is_active" '
                    u'FROM "unit_bittestmodel" '
                    u'WHERE ("unit_bittestmodel"."is_active" = True {space}AND "unit_bittestmodel"."id" = 123{space})')
        space = ''
        expected = expected.format(space=space)

        response = RetrieveSqlQueryKeyBit().get_data(**self.kwargs)
        self.assertEqual(response, expected)
예제 #3
0
 def test_should_use_view__get_queryset__and_filter_it_with__filter_queryset__and_filter_by__lookup_field(
         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  AND "tests_app_bittestmodel"."id" = 123 )'
     )
     response = RetrieveSqlQueryKeyBit().get_data(**self.kwargs)
     self.assertEqual(response, expected)
예제 #4
0
    def test_should_use_view__get_queryset__and_filter_it_with__filter_queryset__and_filter_by__lookup_field(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}AND "tests_app_bittestmodel"."id" = 123{space})')
        if get_django_features()['has_odd_space_in_sql_query']:
            space = ' '
        else:
            space = ''
        expected = expected.format(space=space)

        response = RetrieveSqlQueryKeyBit().get_data(**self.kwargs)
        self.assertEqual(response, expected)
예제 #5
0
    def test_should_use_view__get_queryset__and_filter_it_with__filter_queryset__and_filter_by__lookup_field(
            self):
        if django.VERSION >= (3, 1):
            expected = (
                'SELECT "unit_bittestmodel"."id", "unit_bittestmodel"."is_active" '
                'FROM "unit_bittestmodel" '
                'WHERE ("unit_bittestmodel"."is_active" AND "unit_bittestmodel"."id" = 123)'
            )
        else:
            expected = (
                'SELECT "unit_bittestmodel"."id", "unit_bittestmodel"."is_active" '
                'FROM "unit_bittestmodel" '
                'WHERE ("unit_bittestmodel"."is_active" = True AND "unit_bittestmodel"."id" = 123)'
            )

        response = RetrieveSqlQueryKeyBit().get_data(**self.kwargs)
        self.assertEqual(response, expected)
예제 #6
0
 def test_should_return_none_if_empty_result_set_raised(self):
     self.kwargs['view_instance'].filter_queryset = lambda x: x.filter(pk__in=[])
     response = RetrieveSqlQueryKeyBit().get_data(**self.kwargs)
     self.assertEqual(response, None)
예제 #7
0
 def test_with_bad_lookup_value(self):
     self.kwargs['view_instance'].kwargs = {'id': "I'm ganna hack u are!"}
     response = RetrieveSqlQueryKeyBit().get_data(**self.kwargs)
     self.assertEqual(response, None)
예제 #8
0
class CustomObjectKeyConstructor(DefaultKeyConstructor):
    retrieve_sql = RetrieveSqlQueryKeyBit()
    updated_at = UpdatedAtKeyBit()
예제 #9
0
class PostObjectKeyConstructor(DefaultKeyConstructor):
    retrieve_sql = RetrieveSqlQueryKeyBit()
    updated_at = PostUpdatedAtKeyBit()