mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 11:01:12 +00:00
Adds tests file
This commit is contained in:
parent
ace0bf46d6
commit
1c9bc936f6
3 changed files with 53 additions and 4 deletions
|
@ -56,7 +56,7 @@
|
|||
</form>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<form name="erase-keys" method="POST" action="{% url 'settings-redis' %}">
|
||||
<form name="scan-keys" method="POST" action="{% url 'settings-redis' %}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="dry_run" value="True">
|
||||
<button type="submit" class="button">
|
||||
|
@ -90,7 +90,7 @@
|
|||
{% endblocktrans %}
|
||||
</p>
|
||||
{% else %}
|
||||
<form name="erase-keys" method="POST" action="{% url 'settings-redis' %}">
|
||||
<form name="erase-cache" method="POST" action="{% url 'settings-redis' %}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="erase_cache" value="True">
|
||||
<div class="control">
|
||||
|
|
51
bookwyrm/tests/views/admin/test_redis.py
Normal file
51
bookwyrm/tests/views/admin/test_redis.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
""" test for app action functionality """
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.contrib.auth.models import Group
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models, views
|
||||
from bookwyrm.management.commands import initdb
|
||||
from bookwyrm.tests.validate_html import validate_html
|
||||
|
||||
|
||||
class RedisStatusViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_redis_status_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.RedisStatus.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
|
@ -1,6 +1,5 @@
|
|||
""" redis cache status """
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.http import HttpResponse
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
@ -25,7 +24,6 @@ class RedisStatus(View):
|
|||
|
||||
return TemplateResponse(request, "settings/redis.html", data)
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def post(self, request):
|
||||
"""Erase invalid keys"""
|
||||
dry_run = request.POST.get("dry_run")
|
||||
|
|
Loading…
Reference in a new issue