forked from Fediversity/Fediversity
simplify login tests (#352)
don't go through template generation but use underlying the tag implementation directly Co-authored-by: Nicolas Jeannerod <nicolas.jeannerod@moduscreate.com> Reviewed-on: Fediversity/Fediversity#352
This commit is contained in:
parent
56b953526b
commit
b59f8a4183
1 changed files with 6 additions and 9 deletions
|
@ -1,9 +1,10 @@
|
|||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth.models import User
|
||||
from django.template import Template, Context
|
||||
from urllib.parse import unquote
|
||||
|
||||
from panel.templatetags.custom_tags import auth_url
|
||||
|
||||
class Login(TestCase):
|
||||
def setUp(self):
|
||||
self.username = 'testuser'
|
||||
|
@ -27,8 +28,7 @@ class Login(TestCase):
|
|||
|
||||
# check that the expected login URL is in the response
|
||||
context = response.context[0]
|
||||
template = Template("{% load custom_tags %}{% auth_url 'login' %}")
|
||||
login_url = template.render(context)
|
||||
login_url = auth_url(context, 'login')
|
||||
self.assertIn(login_url, response.content.decode('utf-8'))
|
||||
|
||||
# log in
|
||||
|
@ -49,8 +49,7 @@ class Login(TestCase):
|
|||
|
||||
# check that the expected logout URL is present
|
||||
context = response.context[0]
|
||||
template = Template("{% load custom_tags %}{% auth_url 'logout' %}")
|
||||
logout_url = template.render(context)
|
||||
logout_url = auth_url(context, 'logout')
|
||||
self.assertIn(logout_url, response.content.decode('utf-8'))
|
||||
|
||||
# log out again
|
||||
|
@ -88,8 +87,7 @@ class Login(TestCase):
|
|||
|
||||
# check that the expected logout URL is present
|
||||
context = response.context[0]
|
||||
template = Template("{% load custom_tags %}{% auth_url 'logout' %}")
|
||||
logout_url = template.render(context)
|
||||
logout_url = auth_url(context, 'logout')
|
||||
self.assertIn(logout_url, response.content.decode('utf-8'))
|
||||
|
||||
# log out
|
||||
|
@ -97,8 +95,7 @@ class Login(TestCase):
|
|||
|
||||
# check that we're at the expected location, logged out
|
||||
self.assertEqual(response.status_code, 200)
|
||||
template = Template("{% load custom_tags %}{% auth_url 'login' %}")
|
||||
login_url = template.render(context)
|
||||
login_url = auth_url(context, 'login')
|
||||
location, status = response.redirect_chain[-1]
|
||||
self.assertEqual(location, unquote(login_url))
|
||||
self.assertFalse(response.context['user'].is_authenticated)
|
||||
|
|
Loading…
Add table
Reference in a new issue