@@ -9,30 +9,20 @@ class TestCachesMetrics(PrometheusTestCaseMixin, TestCase):
99 """Test django_prometheus.caches metrics."""
1010
1111 def testCounters (self ):
12- cache_memcached = caches ['memcached' ]
13- cache_filebased = caches ['filebased' ]
14-
15- cache_filebased .set ('foo1' , 'bar' )
16- cache_filebased .get ('foo1' )
17- cache_filebased .get ('foo1' )
18- cache_filebased .get ('foofoo' )
19-
20- self .assertMetricEquals (
21- 3 , 'django_cache_get_total' , backend = 'filebased' )
22- self .assertMetricEquals (
23- 2 , 'django_cache_get_hits_total' , backend = 'filebased' )
24- self .assertMetricEquals (
25- 1 , 'django_cache_get_misses_total' , backend = 'filebased' )
12+ supported_caches = ['memcached' , 'filebased' , 'locmem' ]
2613
2714 # Note: those tests require a memcached server running
28- cache_memcached .set ('foo2' , 'bar' )
29- cache_memcached .get ('foo2' )
30- cache_memcached .get ('foofoo' )
31- cache_memcached .get ('foofoo' )
32-
33- self .assertMetricEquals (
34- 3 , 'django_cache_get_total' , backend = 'memcached' )
35- self .assertMetricEquals (
36- 1 , 'django_cache_get_hits_total' , backend = 'memcached' )
37- self .assertMetricEquals (
38- 2 , 'django_cache_get_misses_total' , backend = 'memcached' )
15+ for supported_cache in supported_caches :
16+ tested_cache = caches [supported_cache ]
17+
18+ tested_cache .set ('foo1' , 'bar' )
19+ tested_cache .get ('foo1' )
20+ tested_cache .get ('foo1' )
21+ tested_cache .get ('foofoo' )
22+
23+ self .assertMetricEquals (
24+ 3 , 'django_cache_get_total' , backend = supported_cache )
25+ self .assertMetricEquals (
26+ 2 , 'django_cache_get_hits_total' , backend = supported_cache )
27+ self .assertMetricEquals (
28+ 1 , 'django_cache_get_misses_total' , backend = supported_cache )
0 commit comments