-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
372 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import sys | ||
from os import path | ||
sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) | ||
from webapp import create_app | ||
import pytest | ||
import os | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
app = create_app() | ||
yield app | ||
|
||
@pytest.fixture | ||
def test_client(app): | ||
with app.test_client() as client: | ||
yield client | ||
|
||
@pytest.fixture | ||
def config(app): | ||
return app.config | ||
|
||
@pytest.fixture() | ||
def client(): | ||
return app.test_client() | ||
|
||
@pytest.fixture(autouse=True) | ||
def _push_request_context(request, app): | ||
ctx = app.test_request_context() # create context | ||
ctx.push() | ||
|
||
def teardown(): | ||
ctx.pop() | ||
|
||
request.addfinalizer(teardown) | ||
|
||
|
||
#@pytest.fixture() | ||
#def page2(playwright): | ||
# browser = playwright.firefox.launch(args=['--no-proxy-server']) | ||
# context = browser.new_context( | ||
# #user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0", | ||
# color_scheme=r"light" | ||
# ) | ||
# page = context.new_page() | ||
# return page |
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,5 @@ | ||
[pytest] | ||
# Run firefox with UI | ||
#addopts = --headed --browser firefox | ||
#addopts = --base-url http://srv018.img.med.uni-tuebingen.de:4999 | ||
live_server_scope = function |
40 changes: 40 additions & 0 deletions
40
src/frontend_celery/playwright/start_heredivar_for_tests.sh
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,40 @@ | ||
|
||
#!/bin/bash | ||
|
||
SCRIPT=$(readlink -f "$0") | ||
SCRIPTPATH=$(dirname "$SCRIPT") | ||
cd $SCRIPTPATH | ||
pwd | ||
ROOT=$(dirname $(dirname $(dirname "$SCRIPTPATH"))) | ||
|
||
function waitForServer { | ||
dist=$1 | ||
echo -n "Starting $dist" | ||
# Give the server some time to start up. Look for a well-known | ||
# bit of text in the log file. Try at most 50 times before giving up. | ||
C=50 | ||
while : | ||
do | ||
grep "* Debugger PIN: " heredivar.log | ||
if [ $? -eq 0 ]; then | ||
echo " server started." | ||
break | ||
elif [ $C -gt 0 ]; then | ||
echo -n "." | ||
C=$((C-1)) | ||
sleep 1 | ||
else | ||
echo " timeout!" | ||
cat heredivar.log | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
set -o allexport | ||
extension=env_ | ||
source $ROOT/.$extension$WEBAPP_ENV | ||
set +o allexport | ||
|
||
python3 $ROOT/src/frontend_celery/main.py > heredivar.log 2>&1 & | ||
waitForServer "HerediVar" |
40 changes: 40 additions & 0 deletions
40
src/frontend_celery/playwright/start_keycloak_for_tests.sh
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,40 @@ | ||
|
||
#!/bin/bash | ||
|
||
SCRIPT=$(readlink -f "$0") | ||
SCRIPTPATH=$(dirname "$SCRIPT") | ||
cd $SCRIPTPATH | ||
pwd | ||
ROOT=$(dirname $(dirname $(dirname "$SCRIPTPATH"))) | ||
|
||
function waitForServer { | ||
dist=$1 | ||
echo -n "Starting $dist" | ||
# Give the server some time to start up. Look for a well-known | ||
# bit of text in the log file. Try at most 50 times before giving up. | ||
C=50 | ||
while : | ||
do | ||
grep "$dist .* (powered by Quarkus .*) started" keycloak.log | ||
if [ $? -eq 0 ]; then | ||
echo " server started." | ||
break | ||
elif [ $C -gt 0 ]; then | ||
echo -n "." | ||
C=$((C-1)) | ||
sleep 1 | ||
else | ||
echo " timeout!" | ||
cat keycloak.log | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
set -o allexport | ||
extension=env_ | ||
source $ROOT/.$extension$WEBAPP_ENV | ||
set +o allexport | ||
|
||
$SCRIPTPATH/keycloak-18.0.0/bin/kc.sh start-dev --hostname $KEYCLOAK_HOST --http-port $KEYCLOAK_PORT > keycloak.log 2>&1 & # --log-level debug | ||
waitForServer "Keycloak" |
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,56 @@ | ||
#!/bin/bash | ||
#set -e | ||
#set -o pipefail | ||
#set -o verbose | ||
|
||
export WEBAPP_ENV=localtest | ||
|
||
SCRIPT=$(readlink -f "$0") | ||
ROOT=$(dirname $(dirname $(dirname $(dirname "$SCRIPT")))) | ||
cd $ROOT | ||
pwd | ||
|
||
TESTDIR=$ROOT/src/frontend_celery/playwright | ||
TEST_DATA_DIR=$TESTDIR/data | ||
DB_STRUCTURE=$TEST_DATA_DIR/db_structure/structure.sql.gz | ||
DB_STATIC_SEED=$TEST_DATA_DIR/db_seeds/static.sql | ||
|
||
|
||
set -o allexport | ||
extension=env_ | ||
source $ROOT/.$extension$WEBAPP_ENV | ||
set +o allexport | ||
|
||
source $ROOT/.venv/bin/activate | ||
|
||
|
||
|
||
# init structure of the database | ||
zcat $DB_STRUCTURE | mysql -h $DB_HOST -P $DB_PORT -u$DB_ADMIN -p$DB_ADMIN_PW $DB_NAME | ||
|
||
# init static information | ||
mysql_errors=$(mysql -h $DB_HOST -P $DB_PORT -u$DB_ADMIN -p$DB_ADMIN_PW $DB_NAME < $DB_STATIC_SEED 2>&1) | ||
if [ $? = "1" ]; then | ||
echo $mysql_errors | ||
exit 1 | ||
fi | ||
|
||
#mysql --host sql.img.med.uni-tuebingen.de -uahdoebm1 -p20220303 HerediVar_ahdoebm1_test < $DATABASE_DUMPER_DIR/users/user_privileges_test.sql | ||
#mysql --host sql.img.med.uni-tuebingen.de -uahdoebm1 -p20220303 HerediVar_ahdoebm1_test -e "SHOW TABLES" | ||
|
||
|
||
# start keycloak | ||
$TESTDIR/start_keycloak_for_tests.sh | ||
|
||
|
||
# start heredivar | ||
$TESTDIR/start_heredivar_for_tests.sh | ||
|
||
|
||
# run tests | ||
cd $TESTDIR | ||
pytest #-k 'test_dev' | ||
|
||
# stop keycloak | ||
pkill -s 0 -e java | ||
pkill -s 0 -e python3 |
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,36 @@ | ||
from os import path | ||
import sys | ||
sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) | ||
import re | ||
#from playwright.sync_api import Page, expect, sync_playwright | ||
from flask import url_for | ||
|
||
|
||
def test_screenshot(page): | ||
response = page.goto(url_for("main.index", _external=True )) # "http://localhost:4000" + | ||
print(response.request.all_headers()) | ||
page.screenshot(path="screenshots/index.png") | ||
|
||
def test_login(page): | ||
response = page.goto(url_for("auth.login", _external=True)) | ||
page.screenshot(path="screenshots/login.png") | ||
assert response.status == 200 | ||
|
||
page.locator("#username").fill("superuser") | ||
page.locator("#password").fill("12345") | ||
page.screenshot(path="screenshots/login_filled.png") | ||
|
||
page.locator("#kc-login").click() | ||
page.screenshot(path="screenshots/login_done.png") | ||
|
||
|
||
|
||
|
||
#def test_get_started_link(page: Page): | ||
# page.goto("https://playwright.dev/") | ||
# | ||
# # Click the get started link. | ||
# page.get_by_role("link", name="Get started").click() | ||
# | ||
# # Expects page to have a heading with the name of Installation. | ||
# expect(page.get_by_role("heading", name="Installation")).to_be_visible() |
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,82 @@ | ||
#!/bin/bash | ||
set -e | ||
set -o pipefail | ||
#set -o verbose | ||
|
||
|
||
helpFunction() | ||
{ | ||
echo "" | ||
echo "Usage: $0 -w env" | ||
echo "This script dumps the static data from HerediVar for tests. This data is used for seeding the database during tests." | ||
echo -e "\t-w Provide 'dev' for development server and 'prod' for production config." | ||
exit 1 # Exit script after printing help | ||
} | ||
|
||
while getopts "w:" opt | ||
do | ||
case "$opt" in | ||
w ) we="$OPTARG" ;; | ||
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent | ||
esac | ||
done | ||
|
||
# Print helpFunction in case parameters are empty | ||
if [ -z "$we" ] | ||
then | ||
echo "Some or all of the parameters are empty"; | ||
helpFunction | ||
fi | ||
|
||
|
||
# set paths | ||
SCRIPT=$(readlink -f "$0") | ||
ROOT=$(dirname $(dirname $(dirname "$SCRIPT"))) | ||
cd $ROOT | ||
pwd | ||
|
||
|
||
export WEBAPP_ENV=$we | ||
if [ -z "${WEBAPP_ENV}" ] | ||
then | ||
echo Environment variable WEBAPP_ENV not set. Use -w option | ||
exit 1 | ||
fi | ||
|
||
echo using "${WEBAPP_ENV}" config | ||
|
||
|
||
SCRIPTPATH=$(dirname "$SCRIPT") | ||
echo script: $SCRIPT | ||
echo scriptpath: $SCRIPTPATH | ||
ROOT=$(dirname $(dirname $(dirname $(dirname "$SCRIPT")))) | ||
echo Root dir: $ROOT | ||
|
||
#cd $SCRIPTPATH | ||
|
||
|
||
# load environment variables | ||
set -o allexport | ||
extension=env_ | ||
source $ROOT/.$extension$WEBAPP_ENV | ||
set +o allexport | ||
|
||
|
||
# setup paths | ||
path_to_structure=$SCRIPTPATH/data/db_structure | ||
mkdir -p $path_to_structure | ||
path_to_structure=$path_to_structure/structure.sql | ||
path_to_data=$SCRIPTPATH/data/db_seeds | ||
mkdir -p $path_to_data | ||
path_to_data=$path_to_data/static.sql | ||
|
||
echo $path_to_structure | ||
echo $path_to_data | ||
|
||
# dump structure | ||
mysqldump --quick --column-statistics=0 $DB_NAME -P $DB_PORT -h $DB_HOST -u $DB_ADMIN -p$DB_ADMIN_PW --no-tablespaces --no-data -r $path_to_structure | ||
gzip --force $path_to_structure | ||
|
||
# dump static data | ||
mysqldump --quick --column-statistics=0 $DB_NAME -P $DB_PORT -h $DB_HOST -u $DB_ADMIN -p$DB_ADMIN_PW --no-tablespaces --no-create-info -r $path_to_data annotation_type classification_scheme classification_criterium classification_criterium_strength classification_scheme_alias mutually_exclusive_criteria mutually_inclusive_criteria | ||
#gzip $path_to_data |
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,8 @@ | ||
|
||
|
||
|
||
|
||
|
||
def subscribe_request_response(page): | ||
page.on("request", lambda request: print(">>", request.method, request.url)) | ||
page.on("response", lambda response: print("<<", response.status, response.url)) |
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
Oops, something went wrong.