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.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.template import Template, Context
|
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
|
from panel.templatetags.custom_tags import auth_url
|
||||||
|
|
||||||
class Login(TestCase):
|
class Login(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.username = 'testuser'
|
self.username = 'testuser'
|
||||||
|
@ -27,8 +28,7 @@ class Login(TestCase):
|
||||||
|
|
||||||
# check that the expected login URL is in the response
|
# check that the expected login URL is in the response
|
||||||
context = response.context[0]
|
context = response.context[0]
|
||||||
template = Template("{% load custom_tags %}{% auth_url 'login' %}")
|
login_url = auth_url(context, 'login')
|
||||||
login_url = template.render(context)
|
|
||||||
self.assertIn(login_url, response.content.decode('utf-8'))
|
self.assertIn(login_url, response.content.decode('utf-8'))
|
||||||
|
|
||||||
# log in
|
# log in
|
||||||
|
@ -49,8 +49,7 @@ class Login(TestCase):
|
||||||
|
|
||||||
# check that the expected logout URL is present
|
# check that the expected logout URL is present
|
||||||
context = response.context[0]
|
context = response.context[0]
|
||||||
template = Template("{% load custom_tags %}{% auth_url 'logout' %}")
|
logout_url = auth_url(context, 'logout')
|
||||||
logout_url = template.render(context)
|
|
||||||
self.assertIn(logout_url, response.content.decode('utf-8'))
|
self.assertIn(logout_url, response.content.decode('utf-8'))
|
||||||
|
|
||||||
# log out again
|
# log out again
|
||||||
|
@ -88,8 +87,7 @@ class Login(TestCase):
|
||||||
|
|
||||||
# check that the expected logout URL is present
|
# check that the expected logout URL is present
|
||||||
context = response.context[0]
|
context = response.context[0]
|
||||||
template = Template("{% load custom_tags %}{% auth_url 'logout' %}")
|
logout_url = auth_url(context, 'logout')
|
||||||
logout_url = template.render(context)
|
|
||||||
self.assertIn(logout_url, response.content.decode('utf-8'))
|
self.assertIn(logout_url, response.content.decode('utf-8'))
|
||||||
|
|
||||||
# log out
|
# log out
|
||||||
|
@ -97,8 +95,7 @@ class Login(TestCase):
|
||||||
|
|
||||||
# check that we're at the expected location, logged out
|
# check that we're at the expected location, logged out
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
template = Template("{% load custom_tags %}{% auth_url 'login' %}")
|
login_url = auth_url(context, 'login')
|
||||||
login_url = template.render(context)
|
|
||||||
location, status = response.redirect_chain[-1]
|
location, status = response.redirect_chain[-1]
|
||||||
self.assertEqual(location, unquote(login_url))
|
self.assertEqual(location, unquote(login_url))
|
||||||
self.assertFalse(response.context['user'].is_authenticated)
|
self.assertFalse(response.context['user'].is_authenticated)
|
||||||
|
|
Loading…
Add table
Reference in a new issue