Adds tests file

This commit is contained in:
Mouse Reeve 2024-08-24 09:09:09 -07:00
parent ace0bf46d6
commit 1c9bc936f6
3 changed files with 53 additions and 4 deletions

View file

@ -56,7 +56,7 @@
</form> </form>
{% endif %} {% endif %}
{% else %} {% else %}
<form name="erase-keys" method="POST" action="{% url 'settings-redis' %}"> <form name="scan-keys" method="POST" action="{% url 'settings-redis' %}">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="dry_run" value="True"> <input type="hidden" name="dry_run" value="True">
<button type="submit" class="button"> <button type="submit" class="button">
@ -90,7 +90,7 @@
{% endblocktrans %} {% endblocktrans %}
</p> </p>
{% else %} {% else %}
<form name="erase-keys" method="POST" action="{% url 'settings-redis' %}"> <form name="erase-cache" method="POST" action="{% url 'settings-redis' %}">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="erase_cache" value="True"> <input type="hidden" name="erase_cache" value="True">
<div class="control"> <div class="control">

View 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)

View file

@ -1,6 +1,5 @@
""" redis cache status """ """ redis cache status """
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.http import HttpResponse
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import View from django.views import View
@ -25,7 +24,6 @@ class RedisStatus(View):
return TemplateResponse(request, "settings/redis.html", data) return TemplateResponse(request, "settings/redis.html", data)
# pylint: disable=unused-argument
def post(self, request): def post(self, request):
"""Erase invalid keys""" """Erase invalid keys"""
dry_run = request.POST.get("dry_run") dry_run = request.POST.get("dry_run")