-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/contrib: adds tests for caching
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
from django.core.cache import cache | ||
from django.urls import reverse | ||
|
||
from adhocracy4.projects.enums import Access | ||
from adhocracy4.test.factories import ProjectFactory | ||
from meinberlin.apps.contrib import caching | ||
from meinberlin.test.factories.extprojects import ExternalProjectFactory | ||
from meinberlin.test.factories.plans import PlanFactory | ||
from meinberlin.test.factories.projectcontainers import ProjectContainerFactory | ||
|
||
|
||
def test_cache_delete(): | ||
... | ||
|
||
|
||
def test_cache_add_or_query(): | ||
... | ||
|
||
|
||
def test_cache_add_or_serialize(): | ||
... | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize( | ||
"url_name,factory,factory_kwargs", | ||
[ | ||
("projects-list", ProjectFactory, {}), | ||
("plans-list", PlanFactory, {}), | ||
("extprojects-list", ExternalProjectFactory, {"access": Access.PUBLIC}), | ||
("containers-list", ProjectContainerFactory, {}), | ||
# ("projects-list", ProjectFactory, {"access": Access.PRIVATE}), | ||
], | ||
) | ||
def test_list_url(client, url_name, factory, factory_kwargs): | ||
n_objects = 3 | ||
url = reverse(url_name) | ||
cache_key = caching.get_key(namespace=url) | ||
cache_value_before = cache.get(cache_key) | ||
|
||
objects = factory.create_batch(size=n_objects, **factory_kwargs) | ||
response = client.get(url) | ||
cache_value_after = cache.get(cache_key) | ||
|
||
assert response.status_code == 200 | ||
assert cache_value_before is None | ||
assert len(cache_value_after) == len(objects) == n_objects | ||
|
||
cache.clear() |