new functional_tests.test_sharing FT for sharing lists; create_pre_authenticated_session() moved from .test_my_lists to .base
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import time
|
||||
|
||||
from datetime import datetime
|
||||
from django.conf import settings
|
||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
||||
from pathlib import Path
|
||||
from selenium import webdriver
|
||||
@@ -9,7 +10,9 @@ from selenium.common.exceptions import WebDriverException
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
|
||||
from .container_commands import reset_database
|
||||
from .container_commands import create_session_on_server, reset_database
|
||||
from .management.commands.create_session import create_pre_authenticated_session
|
||||
|
||||
|
||||
|
||||
MAX_WAIT = 10
|
||||
@@ -70,6 +73,7 @@ class FunctionalTest(StaticLiveServerTestCase):
|
||||
f"{self.__class__.__name__}.{self._testMethodName}-{timestamp}.{extension}"
|
||||
)
|
||||
|
||||
|
||||
@wait
|
||||
def wait_for(self, fn):
|
||||
return fn()
|
||||
@@ -89,6 +93,22 @@ class FunctionalTest(StaticLiveServerTestCase):
|
||||
item_number = num_rows + 1
|
||||
self.wait_for_row_in_list_table(f"{item_number}. {item_text}")
|
||||
|
||||
def create_pre_authenticated_session(self, email):
|
||||
if self.test_server:
|
||||
session_key = create_session_on_server(self.test_server, email)
|
||||
else:
|
||||
session_key = create_pre_authenticated_session(email)
|
||||
## 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_key,
|
||||
path="/",
|
||||
)
|
||||
)
|
||||
|
||||
@wait
|
||||
def wait_to_be_logged_in(self, email):
|
||||
self.browser.find_element(By.CSS_SELECTOR, "#id_logout"),
|
||||
|
||||
@@ -1,26 +1,7 @@
|
||||
from django.conf import settings
|
||||
from selenium.webdriver.common.by import By
|
||||
from .base import FunctionalTest
|
||||
from .container_commands import create_session_on_server
|
||||
from .management.commands.create_session import create_pre_authenticated_session
|
||||
|
||||
|
||||
class MyListsTest(FunctionalTest):
|
||||
def create_pre_authenticated_session(self, email):
|
||||
if self.test_server:
|
||||
session_key = create_session_on_server(self.test_server, email)
|
||||
else:
|
||||
session_key = create_pre_authenticated_session(email)
|
||||
## 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_key,
|
||||
path="/",
|
||||
)
|
||||
)
|
||||
|
||||
def test_logged_in_users_lists_are_saved_as_my_lists(self):
|
||||
self.create_pre_authenticated_session("discoman@example.com")
|
||||
|
||||
34
src/functional_tests/test_sharing.py
Normal file
34
src/functional_tests/test_sharing.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from .base import FunctionalTest
|
||||
|
||||
|
||||
# Helper fns
|
||||
def quit_if_possible(browser):
|
||||
try:
|
||||
browser.quit()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# Test mdls
|
||||
class SharingTest(FunctionalTest):
|
||||
def test_can_share_a_list_with_another_user(self):
|
||||
self.create_pre_authenticated_session("discoman@example.com")
|
||||
disco_browser = self.browser
|
||||
self.addCleanup(lambda: quit_if_possible(disco_browser))
|
||||
|
||||
ali_browser = webdriver.Firefox()
|
||||
self.addCleanup(lambda: quit_if_possible(ali_browser))
|
||||
self.browser = ali_browser
|
||||
self.create_pre_authenticated_session("alice@example.com")
|
||||
|
||||
self.browser = disco_browser
|
||||
self.browser.get(self.live_server_url)
|
||||
self.add_list_item("Send help")
|
||||
|
||||
share_box = self.browser.find_element(By.CSS_SELECTOR, 'input[name="shareable"]')
|
||||
self.assertEqual(
|
||||
share_box.get_attribute("placeholder"),
|
||||
"friend@example.com",
|
||||
)
|
||||
Reference in New Issue
Block a user