Example #1
0
 def test_resulting_dict_all_params(self):
     self.kwargs['params'] = '*'
     expected = {
         'part': u'Londo',
         'callback': u'jquery_callback'
     }
     self.assertEqual(QueryParamsKeyBit().get_data(**self.kwargs), expected)
Example #2
0
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()
Example #3
0
class TimestampedListKeyConstructor(DefaultListKeyConstructor):
    timestamp = ApiTimestampKeyBit()
    # The DefaultListKeyConstructor includes the PaginationKeyBit. While it does
    # subclass QueryParamsKeyBit, it also bypasses logic which includes all query
    # params in the cache key, restricting the set of query params that end up in
    # the cache key to those that are used for page number pagination. This causes
    # cache collisions when other query params are involved. For more, see:
    # https://github.com/chibisov/drf-extensions/blob/master/rest_framework_extensions/key_constructor/bits.py#L48-L49
    querystring = QueryParamsKeyBit()
Example #4
0
class QueryParamsKeyConstructor(DefaultKeyConstructor):
    """
    Example:
    class ProductViewSet(CacheResponseMixin, mixins.ListModelMixin,
        mixins.RetrieveModelMixin, viewsets.GenericViewSet):
        queryset = Product.objects.filter(withdrawn=False)
        serializer_class = ProductSerializer
        pagination_class = LargeResultsSetPagination
        list_cache_key_func = QueryParamsKeyConstructor()
    """
    all_query_params = QueryParamsKeyBit()
Example #5
0
 def test_resulting_dict(self):
     self.kwargs = {
         'params': ['part', 'callback', 'not_existing_param'],
         'view_instance': None,
         'view_method': None,
         'request': factory.get('?part=Londo&callback=jquery_callback'),
         'args': None,
         'kwargs': None
     }
     expected = {'part': u'Londo', 'callback': u'jquery_callback'}
     self.assertEqual(QueryParamsKeyBit().get_data(**self.kwargs), expected)
Example #6
0
 def test_default_params_is_all_args(self):
     self.assertEqual(QueryParamsKeyBit().params, '*')
Example #7
0
class QueryParamsKeyConstructor(DefaultKeyConstructor):
    all_query_params = QueryParamsKeyBit()
Example #8
0
class RequestKeyConstructor(DefaultKeyConstructor):
    arguments = ArgsKeyBit()
    key_arguments = KwargsKeyBit()
    query_params = QueryParamsKeyBit()
    user = UserKeyBit()
    headers = HeadersKeyBit()
Example #9
0
class TimestampedObjectKeyConstructor(DefaultObjectKeyConstructor):
    timestamp = ApiTimestampKeyBit()
    # The DefaultObjectKeyConstructor doesn't include querystring parameters
    # in its cache key.
    querystring = QueryParamsKeyBit()
Example #10
0
class ScoreboardKeyConstructor(DefaultKeyConstructor):
    params_bit = QueryParamsKeyBit()
    args_bit = ArgsKeyBit()
    kwargs_bit = KwargsKeyBit()
Example #11
0
class UpdatedAtDayForFeed(DefaultKeyConstructor):
    updated_at = UpdatedAtKeyBit()
    data_day = UpdatedAtDay()
    pagination = PaginationKeyBit()
    query = QueryParamsKeyBit()
Example #12
0
class ListKeyConstructor(DefaultListKeyConstructor):
    query_params = QueryParamsKeyBit()