~netlandish/django-wiki

fc14f872d4647fe96e03aa3aae19d8d8cd276185 — Benjamin Bach 6 years ago 89aa849 + dd72e57
Merge pull request #804 from atombrella/logout_view_tests

Account handling view tests
1 files changed, 51 insertions(+), 2 deletions(-)

M tests/core/test_views.py
M tests/core/test_views.py => tests/core/test_views.py +51 -2
@@ 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):