-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for /internal/clear_cache
- Loading branch information
Showing
1 changed file
with
33 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
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) |