Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add test cases for caching overview

Tom Bowyerebe2de62b5d0
diff --git a/wger/core/tests/api_base_test.py b/wger/core/tests/api_base_test.py
index c4b792a67..7a90e2224 100644
--- a/wger/core/tests/api_base_test.py
+++ b/wger/core/tests/api_base_test.py
@@ -14,6 +14,7 @@
# Django
from django.contrib.auth.models import User
+from django.core.cache.backends import locmem
# Third Party
from rest_framework import status
@@ -66,6 +67,11 @@ class ApiBaseTestCase(APITestCase):
a workout.
"""
+ overview_cached = False
+ """
+ A flag indicating whether the overview resource is cached
+ """
+
def get_resource_name(self):
"""
Returns the name of the resource. The default is the name of the model
@@ -152,6 +158,24 @@ class ApiGetTestCase(object):
response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
+ def test_get_overview_is_cached(self):
+ """
+ Test accessing the overview view of a resource
+ """
+ # Ensure the wger cache is empty.
+ cache_length = len(locmem._caches['wger-cache'])
+ self.assertEqual(cache_length, 0)
+
+ self.test_get_overview()
+
+ # If the overview is cached. Then ensure the cache isn't empty.
+ if self.overview_cached:
+ cache_length = len(locmem._caches['wger-cache'])
+ self.assertNotEqual(cache_length, 0)
+ else:
+ cache_length = len(locmem._caches['wger-cache'])
+ self.assertEqual(cache_length, 0)
+
def test_special_endpoints(self):
"""
Test accessing any special endpoint the resource could have
diff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.py
index 4a54ab4bd..8241ee927 100644
--- a/wger/exercises/tests/test_exercise.py
+++ b/wger/exercises/tests/test_exercise.py
@@ -18,6 +18,7 @@ import json
# Django
from django.core import mail
from django.core.cache import cache
+from django.core.cache.backends import locmem
from django.core.cache.utils import make_template_fragment_key
from django.template import (
Context,
@@ -25,6 +26,9 @@ from django.template import (
)
from django.urls import reverse
+# Third Party
+from rest_framework import status
+
# wger
from wger.core.tests import api_base_test
from wger.core.tests.base_testcase import (
@@ -700,6 +704,7 @@ class ExerciseApiTestCase(
pk = 1
resource = Exercise
private_resource = False
+ overview_cached = True
class ExerciseInfoApiTestCase(
@@ -712,6 +717,23 @@ class ExerciseInfoApiTestCase(
"""
pk = 1
private_resource = False
+ overview_cached = True
def get_resource_name(self):
return 'exerciseinfo'
+
+
+class ExerciseBaseInfoApiTestCase(
+ api_base_test.BaseTestCase,
+ api_base_test.ApiBaseTestCase,
+ api_base_test.ApiGetTestCase,
+):
+ """
+ Tests the exercise base info resource
+ """
+ pk = 1
+ private_resource = False
+ overview_cached = True
+
+ def get_resource_name(self):
+ return 'exercisebaseinfo'