created new FT file at functional_tests.test_my_lists, where the first test model focuses on the integrity of cookie sessions; much of FT login/logout logic offloaded to helper functions in .base;logout django templating added to base.html
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from django.urls import include, path
|
||||
from . import views
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import path
|
||||
from . import views as lyric_views
|
||||
|
||||
urlpatterns = [
|
||||
path('send_login_email', views.send_login_email, name='send_login_email'),
|
||||
path('login', views.login, name="login"),
|
||||
path('send_login_email', lyric_views.send_login_email, name='send_login_email'),
|
||||
path('login', lyric_views.login, name='login'),
|
||||
path('logout', auth_views.LogoutView.as_view(next_page='/'), name='logout')
|
||||
]
|
||||
|
||||
|
||||
@@ -43,3 +43,17 @@ class FunctionalTest(StaticLiveServerTestCase):
|
||||
|
||||
def get_item_input_box(self):
|
||||
return self.browser.find_element(By.ID, "id_text")
|
||||
|
||||
def wait_to_be_logged_in(self, email):
|
||||
self.wait_for(
|
||||
lambda: self.browser.find_element(By.CSS_SELECTOR, "#id_logout"),
|
||||
)
|
||||
navbar = self.browser.find_element(By.CSS_SELECTOR, ".navbar")
|
||||
self.assertIn(email, navbar.text)
|
||||
|
||||
def wait_to_be_logged_out(self, email):
|
||||
self.wait_for(
|
||||
lambda: self.browser.find_element(By.CSS_SELECTOR, "input[name=email]"),
|
||||
)
|
||||
navbar = self.browser.find_element(By.CSS_SELECTOR, ".navbar")
|
||||
self.assertNotIn(email, navbar.text)
|
||||
|
||||
@@ -34,8 +34,8 @@ class LoginTest(FunctionalTest):
|
||||
|
||||
self.browser.get(url)
|
||||
|
||||
self.wait_for(
|
||||
lambda: self.browser.find_element(By.CSS_SELECTOR, "#id_logout"),
|
||||
)
|
||||
navbar = self.browser.find_element(By.CSS_SELECTOR, ".navbar")
|
||||
self.assertIn(TEST_EMAIL, navbar.text)
|
||||
self.wait_to_be_logged_in(email=TEST_EMAIL)
|
||||
|
||||
self.browser.find_element(By.CSS_SELECTOR, "#id_logout").click()
|
||||
|
||||
self.wait_to_be_logged_out(email=TEST_EMAIL)
|
||||
|
||||
25
src/functional_tests/test_my_lists.py
Normal file
25
src/functional_tests/test_my_lists.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY, get_user_model
|
||||
from django.contrib.sessions.backends.db import SessionStore
|
||||
from .base import FunctionalTest
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class MyListsTest(FunctionalTest):
|
||||
def create_pre_authenticated_session(self, email):
|
||||
user = User.objects.create(email=email)
|
||||
session = SessionStore()
|
||||
session[SESSION_KEY] = user.pk
|
||||
session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
|
||||
session.save()
|
||||
## to set a cookie we need to first visit the domain
|
||||
## 404 pages load the quickest!
|
||||
self.browser.get(self.live_server_url + "/404_no_such_url/")
|
||||
self.browser.add_cookie(
|
||||
dict(
|
||||
name=settings.SESSION_COOKIE_NAME,
|
||||
value=session.session_key,
|
||||
path="/",
|
||||
)
|
||||
)
|
||||
@@ -19,7 +19,7 @@
|
||||
</a>
|
||||
{% if user.email %}
|
||||
<span class="navbar-text">Logged in as {{ user.email }}</span>
|
||||
<form action="TODO" method="POST">
|
||||
<form method="POST" action="{% url "logout" %}">
|
||||
{% csrf_token %}
|
||||
<button id="id_logout" class="btn btn-outline-secondary" type="submit">
|
||||
Log Out
|
||||
|
||||
Reference in New Issue
Block a user