-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working locally as far as document uploading.
- Loading branch information
Showing
7 changed files
with
95 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,33 @@ | ||
import logging | ||
import os | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from _settings import BASE_URL | ||
from dotenv import load_dotenv | ||
from playwright.sync_api import Page, expect | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
from playwright.sync_api import Page | ||
from tests_playwright.pages import HomePage, LandingPage, SignInConfirmationPage | ||
from yarl import URL | ||
|
||
EMAIL_ADDRESS = os.environ["USER_EMAIL"] | ||
DJANGO_ROOT = Path(__file__).parents[1] | ||
load_dotenv(dotenv_path=DJANGO_ROOT / ".env", override=True) | ||
|
||
|
||
def sign_in(page: Page): | ||
email_address = os.environ["USER_EMAIL"] | ||
def sign_in(page: Page) -> "HomePage": | ||
# Landing page | ||
landing_page = LandingPage(page) | ||
|
||
# Sign in | ||
sign_in_page = landing_page.navigate_to_sign_in() | ||
sign_in_page.email = EMAIL_ADDRESS | ||
sign_in_page.continue_() | ||
|
||
if not email_address: | ||
message = "USER_EMAIL not set in your .env - this must be set to the email address you use for signing in." | ||
raise ValueError(message) | ||
# Use magic link | ||
magic_link = get_magic_link(EMAIL_ADDRESS, DJANGO_ROOT) | ||
sign_in_confirmation_page = SignInConfirmationPage(page, magic_link) | ||
return sign_in_confirmation_page.navigate_to_documents_page() | ||
|
||
# Sign in page | ||
page.goto(f"{BASE_URL / 'sign-in'}") | ||
expect(page.get_by_text("Redbox Copilot")).to_be_visible() | ||
page.get_by_label("Email Address").type(email_address) | ||
page.get_by_text("Continue").click() | ||
|
||
# Get magic link | ||
def get_magic_link(email_address: str, django_root: Path) -> URL: | ||
command = ["poetry", "run", "python", "manage.py", "show_magiclink_url", email_address] | ||
result = subprocess.run(command, capture_output=True, text=True, cwd=DJANGO_ROOT) # noqa: S603 | ||
result = subprocess.run(command, capture_output=True, text=True, cwd=django_root) # noqa: S603 | ||
magic_link = result.stdout.strip().lstrip("/") | ||
|
||
# Complete sign-in and verify | ||
page.goto(f"{BASE_URL / magic_link}") | ||
page.get_by_role("button").click() | ||
expect(page.get_by_text("Sign out")).to_be_visible() | ||
return BASE_URL / magic_link |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from _signin import sign_in | ||
from playwright.sync_api import Page | ||
from tests_playwright.pages import ChatsPage, FeedbackType | ||
|
||
|
||
def test_response_feedback(page: Page): | ||
home_page = sign_in(page) | ||
|
||
chats_page: ChatsPage = home_page.navigate_to_chats() | ||
chats_page.write_message = "This is a test chat" | ||
chats_page = chats_page.send() | ||
|
||
assert not chats_page.check_feedback_prompt_visible(FeedbackType.HELPFUL) | ||
assert not chats_page.check_feedback_prompt_visible(FeedbackType.NOT_HELPFUL) | ||
|
||
chats_page.give_feedback(FeedbackType.HELPFUL) | ||
assert chats_page.check_feedback_prompt_visible(FeedbackType.HELPFUL) | ||
assert not chats_page.check_feedback_prompt_visible(FeedbackType.NOT_HELPFUL) | ||
|
||
chats_page.give_feedback(FeedbackType.NOT_HELPFUL) | ||
assert chats_page.check_feedback_prompt_visible(FeedbackType.NOT_HELPFUL) | ||
assert not chats_page.check_feedback_prompt_visible(FeedbackType.HELPFUL) | ||
|
||
chats_page.give_feedback(FeedbackType.NOT_HELPFUL) | ||
assert not chats_page.check_feedback_prompt_visible(FeedbackType.HELPFUL) | ||
assert not chats_page.check_feedback_prompt_visible(FeedbackType.NOT_HELPFUL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
import logging | ||
import os | ||
import string | ||
import subprocess | ||
from pathlib import Path | ||
from random import choice | ||
|
||
import pytest | ||
from pages import LandingPage, SignInConfirmationPage | ||
from playwright.sync_api import Page | ||
from yarl import URL | ||
|
||
from tests.pages import LandingPage, SignInConfirmationPage | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
BASE_URL = URL("http://localhost:8090/") | ||
EMAIL_ADDRESS = "[email protected]" | ||
TEST_ROOT = Path(__file__) | ||
TEST_ROOT = Path(__file__).parent | ||
|
||
|
||
def test_user_journey(page: Page): | ||
create_user(EMAIL_ADDRESS) | ||
def test_user_journey(page: Page, email_address: str): | ||
create_user(email_address) | ||
|
||
# Landing page | ||
landing_page = LandingPage(page, BASE_URL) | ||
|
||
# Sign in | ||
sign_in_page = landing_page.navigate_to_sign_in() | ||
sign_in_page.email = EMAIL_ADDRESS | ||
sign_in_page.email = email_address | ||
sign_in_page.continue_() | ||
|
||
# Use magic link | ||
magic_link = get_magic_link(EMAIL_ADDRESS) | ||
magic_link = get_magic_link(email_address) | ||
logger.debug("magic_link: %s", magic_link) | ||
sign_in_confirmation_page = SignInConfirmationPage(page, magic_link) | ||
|
||
# Documents page | ||
|
@@ -72,33 +73,26 @@ def create_user(email_address: str): | |
"compose", | ||
"run", | ||
"django-app", | ||
"poetry", | ||
"run", | ||
"python", | ||
"manage.py", | ||
"venv/bin/django-admin", | ||
"createsuperuser", | ||
"--noinput", | ||
"--email", | ||
email_address, | ||
] | ||
env = os.environ.copy() | ||
env["DJANGO_SUPERUSER_EMAIL"] = email_address | ||
env["DJANGO_SUPERUSER_USERNAME"] = email_address | ||
env["DJANGO_SUPERUSER_PASSWORD"] = email_address | ||
subprocess.run(command, capture_output=True, text=True, env=env) # noqa: S603 | ||
result = subprocess.run(command, capture_output=True, text=True) # noqa: S603 | ||
result.check_returncode() | ||
logger.debug("create_user result: %s", result) | ||
|
||
|
||
def get_magic_link(email_address: str) -> URL: | ||
command = [ | ||
"docker", | ||
"compose", | ||
"run", | ||
"django-app", | ||
"poetry", | ||
"run", | ||
"python", | ||
"manage.py", | ||
"show_magiclink_url", | ||
email_address, | ||
] | ||
command = ["docker", "compose", "run", "django-app", "venv/bin/django-admin", "show_magiclink_url", email_address] | ||
result = subprocess.run(command, capture_output=True, text=True) # noqa: S603 | ||
result.check_returncode() | ||
magic_link = result.stdout.strip().lstrip("/") | ||
return BASE_URL / magic_link | ||
|
||
|
||
@pytest.fixture() | ||
def email_address() -> str: | ||
username = "".join(choice(string.ascii_lowercase) for _ in range(10)) # noqa: S311 | ||
return f"{username}@cabinetoffice.gov.uk" |