class CustomObjectKeyConstructor(DefaultKeyConstructor): """ Used to compute cache key for a single object. """ retrieve_sql = RetrieveSqlQueryKeyBit() updated_at = UpdatedAtKeyBit() user = UserKeyBit()
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_with_autenticated_user(self): self.kwargs['request'].user = self.user self.is_authenticated.return_value = True expected = u'123' self.assertEqual(UserKeyBit().get_data(**self.kwargs), expected)
def test_with_not_autenticated_user(self): self.kwargs['request'].user = self.user expected = u'anonymous' self.assertEqual(UserKeyBit().get_data(**self.kwargs), expected)
def test_without_user_in_request(self): expected = u'anonymous' self.assertEqual(UserKeyBit().get_data(**self.kwargs), expected)
class RequestKeyConstructor(DefaultKeyConstructor): arguments = ArgsKeyBit() key_arguments = KwargsKeyBit() query_params = QueryParamsKeyBit() user = UserKeyBit() headers = HeadersKeyBit()
class ContestTaskListKeyConstructor(DefaultKeyConstructor): user_bit = UserKeyBit() args_bit = ArgsKeyBit() kwargs_bit = KwargsKeyBit()