Skip to content

Commit

Permalink
Adding tests for /internal/clear_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
abellotti committed Nov 7, 2022
1 parent 42c2ade commit 9acb4bb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cloudigrade/internal/tests/views/test_clear_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Collection of tests for Clearing Internal cache."""
import faker
from django.core.cache import cache
from django.test import TestCase
from rest_framework.test import APIRequestFactory

from internal.views import clear_cache

_faker = faker.Faker()


class ClearCacheTest(TestCase):
"""Clear cache view test case."""

def setUp(self):
"""Set up a bunch shared test data."""
self.factory = APIRequestFactory()

def test_clear_cache(self):
"""Test happy path success for clearing the cache."""
key1 = _faker.word()
key2 = _faker.word()
cache.set(key1, _faker.slug())
cache.set(key2, _faker.slug())
request = self.factory.post("/clear_cache")

response = clear_cache(request)

self.assertEqual(response.status_code, 200)
self.assertIsNone(response.data)

self.assertEqual(cache.get(key1), None)
self.assertEqual(cache.get(key2), None)

0 comments on commit 9acb4bb

Please sign in to comment.