use os.environ["TEST_USER"], fix check_if_user_exists

This commit is contained in:
Daniel 2023-12-14 12:13:00 +01:00
parent 8e926d4e64
commit 6be9fdc535

View file

@ -2,15 +2,14 @@ import json
import os
import re
from playwright.sync_api import BrowserContext, expect
from playwright.sync_api import BrowserContext, TimeoutError, expect
from pytest_abra import BaseUrl, DirManager
ADMIN_USER = os.environ["ADMIN_USER"]
ADMIN_PASS = os.environ["ADMIN_PASS"]
TESTUSER = {"username": "testuser", "name": "Test User", "password": "test123", "email": "test@example.com"}
TEST_USER = os.environ["TEST_USER"]
TEST_PASS = os.environ["TEST_PASS"]
def setup_admin_state(context: BrowserContext, env_config: dict[str, str], DIR: DirManager, URL: BaseUrl):
@ -42,9 +41,12 @@ def check_if_user_exists(admin_context: BrowserContext, env_config: dict[str, st
nav.click()
nav.get_by_role("link", name=re.compile(r"Users|Benutzer")).click()
user = page.get_by_text(TESTUSER["username"])
user.wait_for(state="visible")
return user.is_visible()
user = page.get_by_text(TEST_USER)
try:
user.wait_for(state="visible", timeout=5_000)
return True
except TimeoutError:
return False
def create_invite_link(admin_context: BrowserContext, env_config: dict[str, str], URL: BaseUrl):
@ -83,15 +85,16 @@ def create_user(user_context: BrowserContext, invitelink):
page = user_context.new_page()
page.goto(invitelink)
page.get_by_placeholder("Benutzername").click()
page.get_by_placeholder("Benutzername").fill(TESTUSER["username"])
page.get_by_placeholder("Benutzername").fill(TEST_USER)
page.locator('input[name="name"]').click()
page.locator('input[name="name"]').fill(TESTUSER["name"])
page.locator('input[name="name"]').fill("name")
page.locator('input[name="email"]').click()
page.locator('input[name="email"]').fill(TESTUSER["email"])
email = os.environ["IMAP_EMAIL"] if "IMAP_EMAIL" in os.environ else "test@domain.com"
page.locator('input[name="email"]').fill(email)
page.get_by_placeholder("Passwort", exact=True).click()
page.get_by_placeholder("Passwort", exact=True).fill(TESTUSER["password"])
page.get_by_placeholder("Passwort", exact=True).fill(TEST_PASS)
page.get_by_placeholder("Passwort (wiederholen)").click()
page.get_by_placeholder("Passwort (wiederholen)").fill(TESTUSER["password"])
page.get_by_placeholder("Passwort (wiederholen)").fill(TEST_PASS)
page.get_by_role("button", name="Weiter").click()
expect(page.locator("ak-library")).to_be_visible()