From 8b0fc31f6a09d05074e7427ff228f069dfc52229 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Tue, 16 Jan 2024 14:00:38 +0000 Subject: [PATCH] Resolve "Logout leading to HTTP error 405" - closing #95 --- ivatar/test_views.py | 13 +++++++++++++ templates/_account_bar.html | 2 +- templates/_account_logout.html | 6 ++++++ templates/home.html | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 templates/_account_logout.html diff --git a/ivatar/test_views.py b/ivatar/test_views.py index 81c2901..1015880 100644 --- a/ivatar/test_views.py +++ b/ivatar/test_views.py @@ -6,6 +6,7 @@ Test our views in ivatar.ivataraccount.views and ivatar.views import os import json import django +from django.urls import reverse from django.test import TestCase from django.test import Client from django.contrib.auth.models import User @@ -76,3 +77,15 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods j["unconfirmed_openids"], 0, "unconfirmed openids count incorrect" ) self.assertEqual(j["avatars"], 0, "avatars count incorrect") + + def test_logout(self): + """ + Test if logout works correctly + """ + self.login() + response = self.client.get(reverse("logout"), follow=True) + self.assertEqual( + response.status_code, 405, "logout with get should lead to http error 405" + ) + response = self.client.post(reverse("logout"), follow=True) + self.assertEqual(response.status_code, 200, "logout with post should logout") diff --git a/templates/_account_bar.html b/templates/_account_bar.html index c2e83b5..fa1ebd2 100644 --- a/templates/_account_bar.html +++ b/templates/_account_bar.html @@ -18,7 +18,7 @@
  • {% trans 'Download your libravatar data' %}
  • {% trans 'Change password' %}
  • {% trans 'Reset password' %}
  • -
  • {% trans 'Logout' %}
  • +
  • {% include '_account_logout.html' %}
  • {% else %}
  • {% trans 'Local' %}
  • {% trans 'Create account' %}
  • diff --git a/templates/_account_logout.html b/templates/_account_logout.html new file mode 100644 index 0000000..3dc1a1f --- /dev/null +++ b/templates/_account_logout.html @@ -0,0 +1,6 @@ +{% load i18n %} +
    + {% csrf_token %} + +
    + {% trans 'Logout' %} diff --git a/templates/home.html b/templates/home.html index 7fc19b7..58e8c59 100644 --- a/templates/home.html +++ b/templates/home.html @@ -28,7 +28,7 @@
  • {% trans 'Import libravatar XML export' %}
  • {% trans 'Change password' %}
  • {% trans 'Reset password' %}
  • -
  • {% trans 'Logout' %}
  • +
  • {% include '_account_logout.html' %}
  • {% if user.is_staff %}
  • {% trans 'Admin' %}