cd34d30866
* Activate restricted_data_cache on inmemory cache * Use ElementCache in rest-api get requests * Get requests on the restapi return 404 when the user has no permission * Added async function for has_perm and in_some_groups * changed Cachable.get_restricted_data to be an ansync function * rewrote required_user_system * changed default implementation of access_permission.check_permission to check a given permission or check if anonymous is enabled
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from openslides.topics.models import Topic
|
|
from openslides.utils import collection
|
|
from openslides.utils.test import TestCase
|
|
|
|
|
|
class TestCollectionElementCache(TestCase):
|
|
def test_with_cache(self):
|
|
"""
|
|
Tests that no db query is used when the valie is in the cache.
|
|
|
|
The value is added to the test when .create(...) is called. This hits
|
|
the autoupdate system, which fills the cache.
|
|
"""
|
|
topic = Topic.objects.create(title='test topic')
|
|
collection_element = collection.CollectionElement.from_values('topics/topic', 1)
|
|
|
|
with self.assertNumQueries(0):
|
|
collection_element = collection.CollectionElement.from_values('topics/topic', 1)
|
|
instance = collection_element.get_full_data()
|
|
self.assertEqual(topic.title, instance['title'])
|
|
|
|
def test_fail_early(self):
|
|
"""
|
|
Tests that a CollectionElement.from_values fails, if the object does
|
|
not exist.
|
|
"""
|
|
with self.assertRaises(Topic.DoesNotExist):
|
|
collection.CollectionElement.from_values('topics/topic', 999)
|