Fakultas Ilmu Komputer UI

Commit 8703fc54 authored by Muhammad Ilham Peruzzi's avatar Muhammad Ilham Peruzzi
Browse files

test_my_lists: precreate sessions, move login checks into base

parent ecfbbd2e
......@@ -49,4 +49,19 @@ class FunctionalTest(StaticLiveServerTestCase):
except (AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
raise e
time.sleep(0.5)
\ No newline at end of file
time.sleep(0.5)
def wait_to_be_logged_in(self, email):
self.wait_for(
lambda: self.browser.find_element_by_link_text('Log out')
)
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_name('email')
)
navbar = self.browser.find_element_by_css_selector('.navbar')
self.assertNotIn(email, navbar.text)
\ No newline at end of file
......@@ -55,4 +55,9 @@ class LoginTest(FunctionalTest):
lambda: self.browser.find_element_by_name('email')
)
navbar = self.browser.find_element_by_css_selector('.navbar')
self.assertNotIn(TEST_EMAIL, navbar.text) """
\ No newline at end of file
self.assertNotIn(TEST_EMAIL, navbar.text)
def test_can_get_email_link_to_log_in(self):
​self.wait_to_be_logged_in(email=TEST_EMAIL)
self.browser.find_element_by_link_text('Log out').click()
​self.wait_to_be_logged_out(email=TEST_EMAIL) """
\ No newline at end of file
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='/',
))
def test_logged_in_users_lists_are_saved_as_my_lists(self):
email = 'edith@example.com'
self.browser.get(self.live_server_url)
self.wait_to_be_logged_out(email)
self.create_pre_authenticated_session(email)
self.browser.get(self.live_server_url)
self.wait_to_be_logged_in(email)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment