2026-02-18 15:24:55 -05:00
|
|
|
import os
|
|
|
|
|
|
2026-02-22 21:50:25 -05:00
|
|
|
from django.conf import settings
|
2026-03-28 23:14:31 -04:00
|
|
|
from django.test import tag
|
2026-02-17 21:19:24 -05:00
|
|
|
from selenium import webdriver
|
|
|
|
|
from selenium.webdriver.common.by import By
|
2026-02-17 23:07:12 -05:00
|
|
|
|
2026-02-17 21:19:24 -05:00
|
|
|
from .base import FunctionalTest
|
2026-04-23 01:55:12 -04:00
|
|
|
from .post_page import PostPage
|
|
|
|
|
from .my_posts_page import MyPostsPage
|
2026-02-17 21:19:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Helper fns
|
|
|
|
|
def quit_if_possible(browser):
|
|
|
|
|
try:
|
|
|
|
|
browser.quit()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test mdls
|
|
|
|
|
class SharingTest(FunctionalTest):
|
2026-03-28 23:14:31 -04:00
|
|
|
@tag("two-browser")
|
2026-04-23 01:55:12 -04:00
|
|
|
def test_can_share_a_post_with_another_user(self):
|
2026-03-03 16:10:49 -05:00
|
|
|
self.create_pre_authenticated_session("disco@test.io")
|
2026-02-17 21:19:24 -05:00
|
|
|
disco_browser = self.browser
|
|
|
|
|
self.addCleanup(lambda: quit_if_possible(disco_browser))
|
|
|
|
|
|
2026-02-18 15:24:55 -05:00
|
|
|
options = webdriver.FirefoxOptions()
|
|
|
|
|
if os.environ.get("HEADLESS"):
|
|
|
|
|
options.add_argument("--headless")
|
|
|
|
|
ali_browser = webdriver.Firefox(options=options)
|
2026-02-17 21:19:24 -05:00
|
|
|
self.addCleanup(lambda: quit_if_possible(ali_browser))
|
|
|
|
|
self.browser = ali_browser
|
2026-03-03 16:10:49 -05:00
|
|
|
self.create_pre_authenticated_session("alice@test.io")
|
2026-02-17 21:19:24 -05:00
|
|
|
|
|
|
|
|
self.browser = disco_browser
|
2026-04-23 01:55:12 -04:00
|
|
|
self.browser.get(self.live_server_url + '/billboard/')
|
|
|
|
|
post_page = PostPage(self).add_post_line("Send help")
|
2026-02-17 21:19:24 -05:00
|
|
|
|
2026-04-23 01:55:12 -04:00
|
|
|
share_box = post_page.get_share_box()
|
2026-02-17 21:19:24 -05:00
|
|
|
self.assertEqual(
|
|
|
|
|
share_box.get_attribute("placeholder"),
|
|
|
|
|
"friend@example.com",
|
|
|
|
|
)
|
2026-02-17 23:07:12 -05:00
|
|
|
|
2026-04-23 01:55:12 -04:00
|
|
|
post_page.share_post_with("alice@test.io")
|
2026-02-17 23:27:54 -05:00
|
|
|
|
|
|
|
|
self.browser = ali_browser
|
2026-04-23 01:55:12 -04:00
|
|
|
MyPostsPage(self).go_to_my_posts_page("alice@test.io")
|
2026-02-17 23:27:54 -05:00
|
|
|
|
|
|
|
|
self.browser.find_element(By.LINK_TEXT, "Send help").click()
|
|
|
|
|
|
|
|
|
|
self.wait_for(
|
2026-04-23 01:55:12 -04:00
|
|
|
lambda: self.assertEqual(post_page.get_post_owner(), "disco@test.io")
|
2026-02-17 23:27:54 -05:00
|
|
|
)
|
|
|
|
|
|
2026-04-23 01:55:12 -04:00
|
|
|
post_page.add_post_line("At your command, Disco King")
|
2026-02-17 23:27:54 -05:00
|
|
|
|
|
|
|
|
self.browser = disco_browser
|
|
|
|
|
self.browser.refresh()
|
2026-04-23 01:55:12 -04:00
|
|
|
post_page.wait_for_row_in_post_table("At your command, Disco King", 2)
|
2026-02-22 21:50:25 -05:00
|
|
|
|
2026-04-23 01:55:12 -04:00
|
|
|
class PostAccessTest(FunctionalTest):
|
|
|
|
|
def test_stranger_cannot_access_owned_post(self):
|
2026-03-03 16:10:49 -05:00
|
|
|
self.create_pre_authenticated_session("disco@test.io")
|
2026-04-23 01:55:12 -04:00
|
|
|
self.browser.get(self.live_server_url + '/billboard/')
|
|
|
|
|
PostPage(self).add_post_line("private eye")
|
|
|
|
|
post_url = self.browser.current_url
|
2026-02-22 21:50:25 -05:00
|
|
|
|
|
|
|
|
self.browser.delete_cookie(settings.SESSION_COOKIE_NAME)
|
2026-04-23 01:55:12 -04:00
|
|
|
self.browser.get(post_url)
|
2026-02-22 21:50:25 -05:00
|
|
|
|
2026-04-23 01:55:12 -04:00
|
|
|
self.assertNotEqual(self.browser.current_url, post_url)
|