From dd72e576660842ae7e74a353087a5c7e820614fd Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Tue, 20 Feb 2018 12:31:01 +0100 Subject: [PATCH] Added tests for LogoutView, LoginView and SignupView. Added messages to UpdateView tests. --- tests/core/test_views.py | 53 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/tests/core/test_views.py b/tests/core/test_views.py index d18fb6f5..5ac40028 100644 --- a/tests/core/test_views.py +++ b/tests/core/test_views.py @@ -1,16 +1,24 @@ import pprint +from django.contrib import auth from django.contrib.auth import authenticate +from django.contrib.auth.models import AnonymousUser from django.http import JsonResponse from django.shortcuts import resolve_url from django.utils.html import escape from django_functest import FuncBaseMixin + +from tests.testdata.models import CustomUser from wiki import models +from wiki.conf import settings as wiki_settings from wiki.forms import validate_slug_numbers from wiki.models import URLPath, ArticleRevision, reverse -from ..base import (ArticleWebTestUtils, DjangoClientTestBase, - RequireRootArticleMixin, SeleniumBase, WebTestBase) +from ..base import ( + ArticleWebTestUtils, DjangoClientTestBase, RequireRootArticleMixin, SeleniumBase, + WebTestBase, TestBase, SUPERUSER1_USERNAME, SUPERUSER1_PASSWORD, + wiki_override_settings, +) class RootArticleViewTestsBase(FuncBaseMixin): @@ -531,6 +539,47 @@ class UpdateProfileViewTest(RequireRootArticleMixin, ArticleWebTestUtils, Django self.assertEqual(test_auth.email, 'test@test.com') +@wiki_override_settings(ACCOUNT_HANDLING=True) +class LogoutViewTests(RequireRootArticleMixin, DjangoClientTestBase): + + def test_logout_account_handling(self): + self.client.get(wiki_settings.LOGOUT_URL) + user = auth.get_user(self.client) + self.assertIs(auth.get_user(self.client).is_authenticated(), False) + self.assertIsInstance(user, AnonymousUser) + + +@wiki_override_settings(ACCOUNT_HANDLING=True) +class LoginTestViews(RequireRootArticleMixin, TestBase): + def test_already_signed_in(self): + self.client.force_login(self.superuser1) + response = self.client.get(wiki_settings.LOGIN_URL) + self.assertRedirects(response, reverse('wiki:root')) + + def test_log_in(self): + self.client.post( + wiki_settings.LOGIN_URL, + {'username': SUPERUSER1_USERNAME, 'password': SUPERUSER1_PASSWORD} + ) + self.assertIs(self.superuser1.is_authenticated(), True) + self.assertEqual(auth.get_user(self.client), self.superuser1) + + +class SignupViewTests(RequireRootArticleMixin, TestBase): + + @wiki_override_settings(ACCOUNT_HANDLING=True, ACCOUNT_SIGNUP_ALLOWED=True) + def test_signup(self): + response = self.client.post( + wiki_settings.SIGNUP_URL, + data={ + 'password1': 'wiki', 'password2': 'wiki', 'username': 'wiki', + 'email': 'wiki@wiki.com' + } + ) + self.assertIs(CustomUser.objects.filter(email='wiki@wiki.com').exists(), True) + self.assertRedirects(response, reverse('wiki:login')) + + class MergeViewTest(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestBase): def test_merge_preview(self): -- 2.45.2