2020-09-13 21:39:44 +02:00
|
|
|
import os
|
|
|
|
import random
|
2022-03-23 12:36:41 +01:00
|
|
|
import re
|
2020-09-13 21:39:44 +02:00
|
|
|
import string
|
2022-03-23 12:36:41 +01:00
|
|
|
import time
|
2020-09-13 21:39:44 +02:00
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
import requests
|
2022-07-03 15:01:21 +02:00
|
|
|
from selenium.webdriver.common.by import By
|
2020-09-13 21:39:44 +02:00
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
2022-03-23 12:36:41 +01:00
|
|
|
from urllib3.util import parse_url
|
2020-09-13 21:39:44 +02:00
|
|
|
|
|
|
|
TEST_APP_URL = os.getenv('TEST_APP_URL')
|
|
|
|
TEST_CLIENT_URL = os.getenv('TEST_CLIENT_URL')
|
|
|
|
E2E_ARGS = os.getenv('E2E_ARGS')
|
|
|
|
TEST_URL = TEST_CLIENT_URL if E2E_ARGS == 'client' else TEST_APP_URL
|
2022-03-23 12:36:41 +01:00
|
|
|
EMAIL_URL = os.getenv('EMAIL_URL', 'smtp://none:none@0.0.0.0:1025')
|
|
|
|
parsed_email_url = parse_url(EMAIL_URL)
|
|
|
|
EMAIL_API_URL = f'http://{parsed_email_url.host}:8025'
|
2020-09-13 21:39:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def random_string(length=8):
|
2022-03-23 12:36:41 +01:00
|
|
|
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
|
2020-09-13 21:39:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def register(selenium, user):
|
|
|
|
selenium.get(f'{TEST_URL}/register')
|
|
|
|
selenium.implicitly_wait(1)
|
2022-07-03 15:01:21 +02:00
|
|
|
username = selenium.find_element(By.ID, 'username')
|
2020-09-13 21:39:44 +02:00
|
|
|
username.send_keys(user.get('username'))
|
2022-07-03 15:01:21 +02:00
|
|
|
email = selenium.find_element(By.ID, 'email')
|
2020-09-13 21:39:44 +02:00
|
|
|
email.send_keys(user.get('email'))
|
2022-07-03 15:01:21 +02:00
|
|
|
password = selenium.find_element(By.ID, 'password')
|
2020-09-13 21:39:44 +02:00
|
|
|
password.send_keys(user.get('password'))
|
2023-02-26 18:57:35 +01:00
|
|
|
accepted_policy = selenium.find_element(By.ID, 'accepted_policy')
|
|
|
|
accepted_policy.click()
|
2023-07-13 21:49:27 +02:00
|
|
|
submit_button = selenium.find_elements(By.TAG_NAME, 'button')[-1]
|
2020-09-13 21:39:44 +02:00
|
|
|
submit_button.click()
|
|
|
|
|
|
|
|
|
|
|
|
def login(selenium, user):
|
|
|
|
selenium.get(f'{TEST_URL}/login')
|
|
|
|
selenium.implicitly_wait(1)
|
2022-07-03 15:01:21 +02:00
|
|
|
email = selenium.find_element(By.ID, 'email')
|
2020-09-13 21:39:44 +02:00
|
|
|
email.send_keys(user.get('email'))
|
2022-07-03 15:01:21 +02:00
|
|
|
password = selenium.find_element(By.ID, 'password')
|
2020-09-13 21:39:44 +02:00
|
|
|
password.send_keys(user.get('password'))
|
2023-07-13 21:49:27 +02:00
|
|
|
submit_button = selenium.find_elements(By.TAG_NAME, 'button')[-1]
|
2020-09-13 21:39:44 +02:00
|
|
|
submit_button.click()
|
|
|
|
|
|
|
|
|
|
|
|
def register_valid_user(selenium):
|
|
|
|
user_name = random_string()
|
|
|
|
user = {
|
|
|
|
'username': user_name,
|
|
|
|
'email': f'{user_name}@example.com',
|
|
|
|
'password': 'p@ssw0rd',
|
|
|
|
}
|
|
|
|
register(selenium, user)
|
2022-03-23 12:36:41 +01:00
|
|
|
WebDriverWait(selenium, 30).until(EC.url_changes(f"{TEST_URL}/register"))
|
|
|
|
confirm_account(selenium, user)
|
2020-09-13 21:39:44 +02:00
|
|
|
return user
|
|
|
|
|
|
|
|
|
2022-02-12 16:31:29 +01:00
|
|
|
def register_valid_user_and_logout(selenium):
|
2022-03-23 12:36:41 +01:00
|
|
|
user = register_valid_user(selenium)
|
2022-07-03 15:01:21 +02:00
|
|
|
user_menu = selenium.find_element(By.CLASS_NAME, 'nav-items-user-menu')
|
2023-07-13 21:49:27 +02:00
|
|
|
logout_button = user_menu.find_elements(By.CLASS_NAME, 'logout-button')[0]
|
|
|
|
logout_button.click()
|
|
|
|
modal = selenium.find_element(By.ID, 'modal')
|
|
|
|
confirm_button = modal.find_elements(By.CLASS_NAME, 'confirm')[0]
|
|
|
|
confirm_button.click()
|
|
|
|
selenium.implicitly_wait(1)
|
2022-02-12 16:31:29 +01:00
|
|
|
return user
|
|
|
|
|
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
def confirm_account(selenium, user):
|
|
|
|
time.sleep(1)
|
|
|
|
response = requests.get(
|
|
|
|
f"{EMAIL_API_URL}/api/v2/search?kind=to&query={user['email']}"
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
results = response.json()
|
|
|
|
message = results['items'][0]['Content']['Body']
|
|
|
|
link = re.search(r'Verify your email: (.+?)\r\n', message).groups()[0]
|
|
|
|
link = link.replace('http://0.0.0.0:5000', TEST_URL)
|
|
|
|
selenium.get(link)
|
|
|
|
WebDriverWait(selenium, 15).until(EC.url_changes(link))
|
|
|
|
|
|
|
|
|
2020-09-13 21:39:44 +02:00
|
|
|
def login_valid_user(selenium, user):
|
|
|
|
login(selenium, user)
|
|
|
|
WebDriverWait(selenium, 10).until(EC.url_changes(f"{TEST_URL}/login"))
|
|
|
|
return user
|