def test_large_feature_tree_cached_feature(self): feature = self.setup_feature_tree() cached_qs = CachedQueryset(Cache(), Feature.objects.all(), primary_keys=[feature.pk]) cached_feature = cached_qs.get(pk=feature.pk) self.assertEqual(cached_feature.pk, feature.id) self.assertEqual(cached_feature.descendant_count, 3) self.assertEqual(cached_feature.descendant_pks, []) # Too big to cache url = self.api_reverse('viewfeatures-detail', pk=cached_feature.pk) context = self.make_context(url, include_child_pages=True) serializer = ViewFeatureSerializer(context=context) representation = serializer.to_representation(cached_feature) next_page = url + '?child_pages=1&page=2' expected_pagination = { 'linked.features': { 'previous': None, 'next': self.baseUrl + next_page, 'count': 3, } } compat_table = representation['_view_extra']['meta']['compat_table'] actual_pagination = compat_table['pagination'] self.assertDataEqual(expected_pagination, actual_pagination) context2 = self.make_context(next_page, include_child_pages=True) serializer2 = ViewFeatureSerializer(context=context2) representation = serializer2.to_representation(feature) expected_pagination = { 'linked.features': { 'previous': self.baseUrl + url + '?child_pages=1&page=1', 'next': None, 'count': 3, } } compat_table = representation['_view_extra']['meta']['compat_table'] actual_pagination = compat_table['pagination'] self.assertEqual(expected_pagination, actual_pagination)
def test_large_feature_tree_cached_feature(self): feature = self.setup_feature_tree() cached_qs = CachedQueryset( Cache(), Feature.objects.all(), primary_keys=[feature.pk]) cached_feature = cached_qs.get(pk=feature.pk) self.assertEqual(cached_feature.pk, feature.id) self.assertEqual(cached_feature.descendant_count, 3) self.assertEqual(cached_feature.descendant_pks, []) # Too big to cache url = self.api_reverse('viewfeatures-detail', pk=cached_feature.pk) context = self.make_context(url, include_child_pages=True) serializer = ViewFeatureSerializer(context=context) representation = serializer.to_representation(cached_feature) next_page = url + '?child_pages=1&page=2' expected_pagination = { 'linked.features': { 'previous': None, 'next': self.baseUrl + next_page, 'count': 3, } } compat_table = representation['_view_extra']['meta']['compat_table'] actual_pagination = compat_table['pagination'] self.assertDataEqual(expected_pagination, actual_pagination) context2 = self.make_context(next_page, include_child_pages=True) serializer2 = ViewFeatureSerializer(context=context2) representation = serializer2.to_representation(feature) expected_pagination = { 'linked.features': { 'previous': self.baseUrl + url + '?child_pages=1&page=1', 'next': None, 'count': 3, } } compat_table = representation['_view_extra']['meta']['compat_table'] actual_pagination = compat_table['pagination'] self.assertEqual(expected_pagination, actual_pagination)
def test_get_existing_instance(self): """A cached instance can be retrieved by get(pk).""" user = User.objects.create(username='******') cq = CachedQueryset(self.cache, User.objects.all()) cached_user = cq.get(pk=user.pk) self.assertEqual('frank', cached_user.username)