Skip to content

Commit

Permalink
added tests and refactoring of tests and added default user tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinDo committed Jul 2, 2024
1 parent 5324e6d commit b0f7d5b
Show file tree
Hide file tree
Showing 16 changed files with 509 additions and 70 deletions.
50 changes: 50 additions & 0 deletions src/frontend_celery/playwright/start_redis_for_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#!/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=500
while :
do
grep ".* Ready to accept connections tcp" redis.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 redis.log
exit 1
fi
done
}

set -o allexport
extension=env_
source $ROOT/.$extension$WEBAPP_ENV
set +o allexport

TOOLS=$ROOT/tools

redis_path=$SCRIPTPATH/redis_for_tests

# install keycloak for tests if it is missing
if [ ! -d "${redis_path}" ]; then
$TOOLS/script/install_redis.sh -p $SCRIPTPATH -n redis_for_tests
sleep 5
fi

redis_for_tests/src/redis-server --port $REDIS_PORT > redis.log 2>&1 &
waitForServer "Redis"
21 changes: 18 additions & 3 deletions src/frontend_celery/playwright/start_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,32 @@ fi
# start keycloak - this also seeds keycloak
$TESTDIR/start_keycloak_for_tests.sh

# start redis
$TESTDIR/start_redis_for_tests.sh

# start heredivar
$TESTDIR/start_heredivar_for_tests.sh


# run tests
cd $TESTDIR
export TESTUSER=$TEST_READONLY
export TESTUSERPW=$TEST_READONLY_PW
pytest --screenshot=only-on-failure --browser firefox tests/read_only/ #-k 'test_private_list_actions or test_variant_list_add' #-k 'test_dev' --browser webkit --browser chromium --numprocesses 2

# test read only
#export TESTUSER=$TEST_READONLY
#export TESTUSERPW=$TEST_READONLY_PW
#pytest --screenshot=only-on-failure --browser firefox tests/read_only/ -k 'test_user_classify' #-k 'test_private_list_actions or test_variant_list_add' #-k 'test_dev' --browser webkit --browser chromium --numprocesses 2

# test default user
export TESTUSER=$TEST_USER
export TESTUSERPW=$TEST_USER_PW
pytest --screenshot=only-on-failure --browser firefox tests/default_user/ -k 'test_user_select_all_schemes' #-k 'test_private_list_actions or test_variant_list_add' #-k 'test_dev' --browser webkit --browser chromium --numprocesses 2

# test superuser
#export TESTUSER=$TEST_SUPERUSER
#export TESTUSERPW=$TEST_SUPERUSER_PW
# TODO...

# stop services
pkill -s 0 -e java
pkill -s 0 -e python3
pkill -s 0 -e redis-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

from os import path
import os
import sys
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))
import utils
import re
#from playwright.sync_api import Page, expect, sync_playwright
from flask import url_for
sys.path.append(path.dirname(path.dirname(path.dirname(path.dirname(path.abspath(__file__))))))
import common.functions as functions
import common.paths as paths
import time
from functools import partial
from playwright.sync_api import expect
import requests


def test_consensus_classify(page, conn):
# seed database
user = utils.get_user()
user_id = conn.get_user_id(user["username"])

# insert variants
variant_id = conn.insert_variant(chr = "chr2", pos = "214730440", ref = "G", alt = "A", orig_chr = "chr2", orig_pos = "214730440", orig_ref = "G", orig_alt = "A", user_id = user_id) # chr2-214730440-G-A BARD1

# start the test
utils.login(page, user)

utils.nav(page.goto, utils.UNAUTHORIZED_STATI, url_for('variant.consensus_classify', variant_id = variant_id, _external = True))

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from os import path
import os
import sys
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))
import utils
import re
#from playwright.sync_api import Page, expect, sync_playwright
from flask import url_for
sys.path.append(path.dirname(path.dirname(path.dirname(path.dirname(path.abspath(__file__))))))
import common.functions as functions
import common.paths as paths
import time
from functools import partial
from playwright.sync_api import expect
import requests




def test_user_select_all_schemes(page, conn):
# seed database
user = utils.get_user()
user_id = conn.get_user_id(user["username"])

# insert variants
variant_id = conn.insert_variant(chr = "chr2", pos = "214730440", ref = "G", alt = "A", orig_chr = "chr2", orig_pos = "214730440", orig_ref = "G", orig_alt = "A", user_id = user_id) # chr2-214730440-G-A BARD1

# start the test
utils.login(page, user)

utils.nav(page.goto, utils.GOOD_STATI, url_for('variant.classify', variant_id = variant_id, _external = True))

# test that all classification schemes are selectable
classification_schemes = conn.get_classification_schemas()
for classification_scheme_id in classification_schemes:
classification_scheme_label = classification_schemes[classification_scheme_id]["description"]
page.select_option('select#scheme', label=classification_scheme_label)

# assert that all criteria are visible
criteria = classification_schemes[classification_scheme_id]["criteria"]
for criterium in criteria:
expect(page.locator("#" + criterium)).to_have_count(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from os import path
import os
import sys
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))
import utils
import re
#from playwright.sync_api import Page, expect, sync_playwright
from flask import url_for
sys.path.append(path.dirname(path.dirname(path.dirname(path.dirname(path.abspath(__file__))))))
import common.functions as functions
import common.paths as paths
import time
from functools import partial
from playwright.sync_api import expect
import requests




def test_user_classify(page, conn):
# seed database
user = utils.get_user()
user_id = conn.get_user_id(user["username"])

# insert variants
variant_id = conn.insert_variant(chr = "chr2", pos = "214730440", ref = "G", alt = "A", orig_chr = "chr2", orig_pos = "214730440", orig_ref = "G", orig_alt = "A", user_id = user_id) # chr2-214730440-G-A BARD1

# start the test
utils.login(page, user)

utils.nav(page.goto, utils.UNAUTHORIZED_STATI, url_for('variant.classify', variant_id = variant_id, _external = True))

def test_consensus_classify(page, conn):
# seed database
user = utils.get_user()
user_id = conn.get_user_id(user["username"])

# insert variants
variant_id = conn.insert_variant(chr = "chr2", pos = "214730440", ref = "G", alt = "A", orig_chr = "chr2", orig_pos = "214730440", orig_ref = "G", orig_alt = "A", user_id = user_id) # chr2-214730440-G-A BARD1

# start the test
utils.login(page, user)

utils.nav(page.goto, utils.UNAUTHORIZED_STATI, url_for('variant.consensus_classify', variant_id = variant_id, _external = True))
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))
import utils
from utils import Test_Connection
import re
#from playwright.sync_api import Page, expect, sync_playwright
from flask import url_for
Expand Down Expand Up @@ -263,7 +262,7 @@ def test_consensus_classification_search(page, conn):
]

# insert consensus classifications
classification_scheme_id = conn.get_classification_scheme_id_from_alias("ACMG standard + SVI")
classification_scheme_id = conn.get_classification_scheme_id_from_alias("ACMG standard + SVI", 'v1.0.0')
conn.insert_consensus_classification(user_id = user_id, variant_id = all_variant_ids[0], consensus_classification = "1", comment = "TEST1", evidence_document = bytes("TESTEXAMPLE", 'utf-8'), date = functions.get_now(), scheme_id = classification_scheme_id, scheme_class = "1")
conn.insert_consensus_classification(user_id = user_id, variant_id = all_variant_ids[1], consensus_classification = "2", comment = "TEST2", evidence_document = bytes("TESTEXAMPLE", 'utf-8'), date = functions.get_now(), scheme_id = classification_scheme_id, scheme_class = "2")
conn.insert_consensus_classification(user_id = user_id, variant_id = all_variant_ids[2], consensus_classification = "3-", comment = "TEST3", evidence_document = bytes("TESTEXAMPLE", 'utf-8'), date = functions.get_now(), scheme_id = classification_scheme_id, scheme_class = "3")
Expand Down Expand Up @@ -359,7 +358,7 @@ def test_user_classification_search(page, conn):
]

# insert consensus classifications
classification_scheme_id = conn.get_classification_scheme_id_from_alias("ACMG standard + SVI")
classification_scheme_id = conn.get_classification_scheme_id_from_alias("ACMG standard + SVI", 'v1.0.0')
conn.insert_user_classification(variant_id = all_variant_ids[0], classification = "1", user_id = user_id, comment = "", date = functions.get_now(), scheme_id = classification_scheme_id, scheme_class = "1")
conn.insert_user_classification(variant_id = all_variant_ids[1], classification = "2", user_id = user_id, comment = "", date = functions.get_now(), scheme_id = classification_scheme_id, scheme_class = "2")
conn.insert_user_classification(variant_id = all_variant_ids[2], classification = "3-", user_id = user_id, comment = "", date = functions.get_now(), scheme_id = classification_scheme_id, scheme_class = "3")
Expand Down Expand Up @@ -429,7 +428,7 @@ def test_automatic_classification_splicing_search(page, conn):
]

# insert consensus classifications
classification_scheme_id = conn.get_classification_scheme_id_from_alias("ACMG standard + SVI")
classification_scheme_id = conn.get_classification_scheme_id_from_alias("ACMG standard + SVI", 'v1.0.0')
conn.insert_automatic_classification(variant_id = all_variant_ids[0], classification_scheme_id = classification_scheme_id, classification_splicing = "1", classification_protein = "2", tool_version = "1.0.0")
conn.insert_automatic_classification(variant_id = all_variant_ids[1], classification_scheme_id = classification_scheme_id, classification_splicing = "2", classification_protein = "1", tool_version = "1.0.0")
conn.insert_automatic_classification(variant_id = all_variant_ids[2], classification_scheme_id = classification_scheme_id, classification_splicing = "3", classification_protein = "1", tool_version = "1.0.0")
Expand Down Expand Up @@ -490,7 +489,7 @@ def test_automatic_classification_protein_search(page, conn):
]

# insert consensus classifications
classification_scheme_id = conn.get_classification_scheme_id_from_alias("ACMG standard + SVI")
classification_scheme_id = conn.get_classification_scheme_id_from_alias("ACMG standard + SVI", 'v1.0.0')
conn.insert_automatic_classification(variant_id = all_variant_ids[0], classification_scheme_id = classification_scheme_id, classification_splicing = "2", classification_protein = "1", tool_version = "1.0.0")
conn.insert_automatic_classification(variant_id = all_variant_ids[1], classification_scheme_id = classification_scheme_id, classification_splicing = "1", classification_protein = "2", tool_version = "1.0.0")
conn.insert_automatic_classification(variant_id = all_variant_ids[2], classification_scheme_id = classification_scheme_id, classification_splicing = "1", classification_protein = "3", tool_version = "1.0.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))
import utils
from utils import Test_Connection
import re
#from playwright.sync_api import Page, expect, sync_playwright
from flask import url_for
Expand Down Expand Up @@ -73,7 +72,7 @@ def test_variant_list_add(page):
def test_private_list_actions(page, conn):
# seed database
conn.insert_user(username = "transient_tester", first_name = "TRA", last_name = "TEST", affiliation = "AFF")
user_id = conn.get_last_insert_id()
user_id = conn.get_user_id("transient_tester")

list_name = "priv_l"
conn.insert_user_variant_list(user_id = user_id, list_name = list_name, public_read = False, public_edit = False)
Expand All @@ -95,7 +94,6 @@ def test_private_list_actions(page, conn):
# try accessing the private list -> unauthorized
utils.nav(page.goto, utils.UNAUTHORIZED_STATI, url_for('user.my_lists', view=list_id, _external=True))


# try to add variants to the private list -> unauthorized
get_data = {
"selected_list_id": list_id,
Expand Down Expand Up @@ -127,7 +125,7 @@ def test_add_list(page, conn):
# seed database
user = utils.get_user()
conn.insert_user(username = "transient_tester", first_name = "TRA", last_name = "TEST", affiliation = "AFF")
other_user_id = conn.get_last_insert_id()
other_user_id = conn.get_user_id("transient_tester")

private_list_name = "priv_l"
conn.insert_user_variant_list(user_id = other_user_id, list_name = private_list_name, public_read = False, public_edit = False)
Expand Down Expand Up @@ -206,7 +204,7 @@ def test_subtract_list(page, conn):
# seed database
user = utils.get_user()
conn.insert_user(username = "transient_tester", first_name = "TRA", last_name = "TEST", affiliation = "AFF")
other_user_id = conn.get_last_insert_id()
other_user_id = conn.get_user_id("transient_tester")

private_list_name = "priv_l"
conn.insert_user_variant_list(user_id = other_user_id, list_name = private_list_name, public_read = False, public_edit = False)
Expand Down Expand Up @@ -294,7 +292,7 @@ def test_intersect_list(page, conn):
# seed database
user = utils.get_user()
conn.insert_user(username = "transient_tester", first_name = "TRA", last_name = "TEST", affiliation = "AFF")
other_user_id = conn.get_last_insert_id()
other_user_id = conn.get_user_id("transient_tester")

private_list_name = "priv_l"
conn.insert_user_variant_list(user_id = other_user_id, list_name = private_list_name, public_read = False, public_edit = False)
Expand Down Expand Up @@ -380,7 +378,7 @@ def test_duplicate_list(page, conn):
# seed database
user = utils.get_user()
conn.insert_user(username = "transient_tester", first_name = "TRA", last_name = "TEST", affiliation = "AFF")
other_user_id = conn.get_last_insert_id()
other_user_id = conn.get_user_id("transient_tester")

list_name = "priv_l"
conn.insert_user_variant_list(user_id = other_user_id, list_name = list_name, public_read = False, public_edit = False)
Expand Down Expand Up @@ -422,7 +420,7 @@ def test_delete_list(page, conn):
# seed database
user = utils.get_user()
conn.insert_user(username = "transient_tester", first_name = "TRA", last_name = "TEST", affiliation = "AFF")
other_user_id = conn.get_last_insert_id()
other_user_id = conn.get_user_id("transient_tester")

list_name = "priv_l"
conn.insert_user_variant_list(user_id = other_user_id, list_name = list_name, public_read = False, public_edit = False)
Expand Down Expand Up @@ -460,7 +458,7 @@ def test_modify_list_permissions(page, conn):
# seed database
user = utils.get_user()
conn.insert_user(username = "transient_tester", first_name = "TRA", last_name = "TEST", affiliation = "AFF")
other_user_id = conn.get_last_insert_id()
other_user_id = conn.get_user_id("transient_tester")

list_name = "priv_l"
conn.insert_user_variant_list(user_id = other_user_id, list_name = list_name, public_read = False, public_edit = False)
Expand Down Expand Up @@ -554,7 +552,7 @@ def test_modify_list_permissions(page, conn):
def test_public_list_actions(page, conn):
# seed database
conn.insert_user(username = "transient_tester", first_name = "TRA", last_name = "TEST", affiliation = "AFF")
user_id = conn.get_last_insert_id()
user_id = conn.get_user_id("transient_tester")

list_name = "publ_l"
conn.insert_user_variant_list(user_id = user_id, list_name = list_name, public_read = True, public_edit = False)
Expand All @@ -571,7 +569,7 @@ def test_public_list_actions(page, conn):

# is the list visible?
utils.nav(page.goto, utils.GOOD_STATI, url_for('user.my_lists', _external=True))
expect(page.locator("tr[list_id='" + str(list_id) + "']")).to_have_count(0)
expect(page.locator("tr[list_id='" + str(list_id) + "']")).to_have_count(1)

# try accessing the public list -> works
utils.nav(page.goto, utils.GOOD_STATI, url_for('user.my_lists', view=list_id, _external=True))
Expand Down
Loading

0 comments on commit b0f7d5b

Please sign in to comment.