-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding testing pipline to the testing branch #1471
Changes from 219 commits
713c7fc
84fc2d6
0393b45
31110d5
bf6819e
365feef
ec6e193
c53c675
be0e2c8
5e3faac
f744582
377cd3f
71d254f
2126763
6736da3
2804633
e26e772
4ceb33f
1dde8ab
cc0f0e8
f478b1b
2b006d7
61c9767
32ee053
bc87e56
0c84c6d
b5767f1
fc5f03b
34cbd61
2be3f4c
6da1e4d
e09b186
b495680
754adaf
56a9863
72c63ea
eea8550
43ec6da
0b668b5
bfc9426
5836c7b
72b437f
976842d
37be943
b617f70
709b4b9
359d4c7
cf60d0f
08fdcaf
cccf5ef
1cdddba
6689023
23e3e2f
8493f12
81076c4
78bf31d
995846a
74026d8
db195ce
6497d9b
5be12ac
bccb9b0
2546229
d46ecf8
245b366
db2d137
d65b047
70d10af
a4431dd
a71dfde
2f5e2d5
db7417e
4aba9ca
cbbab58
9825385
7e2e57d
ae6dd75
00c3d36
b363d39
ca84628
6b88b3e
f123ebe
3d09b60
5fc7fd6
b1d2bc7
7aef4ef
e12f565
bb65be1
4aef5ae
8436011
42119fb
80b0621
c765af2
28da164
c574baf
8c1a69e
8e95a7f
c28cc21
243439e
6206969
79f8f46
50e5ae5
81fe69b
f317dc8
5c474df
d926d09
d5d5e40
5355d56
25d4ff7
417958a
ca8d04b
2c0a32e
d7e5af1
a865429
674cac9
e7984a9
a83f593
9b8a6f7
0398f25
d6738a9
24c983b
c39caca
d68233e
f0920de
d03dd09
50ee3ef
59debcf
82f01cc
2df389a
656c0d5
a6246ab
7f8a192
defc388
bbcea33
7b1b5ee
abf7ca5
35af21e
ce5a685
ba8b1be
e182365
14cefa3
a4c67b6
79080da
5f1a385
dcd82b7
8bb43da
1afbfaa
28ef7b2
333daf8
71eb122
83e5163
983342d
5bbcd7e
9b24d42
8c84903
6ec1c2a
9308b99
390350f
6899e49
b32cac0
34eebd3
dd30e6f
5bc7ae9
eb4b48a
77f86ed
612536f
1815a95
45d64ab
eb25faf
08ba6cf
8ab1841
20a66af
f0052ac
7fe9b3c
ff4e6f8
6fae9b8
44d2f03
4d636d2
5c32022
ed2dc77
ef23a7d
783b255
6def110
af46891
315247a
90f5a5e
262829e
7b8cf50
319bdbe
6b43875
a930d9f
9c3c3c9
df215bf
a773ada
7879040
d145150
813bc1b
3e0f14e
cee239c
edbc889
545f7d3
05481eb
152b947
a98fe87
51779bf
f2ca197
e997c31
b50265f
5f37d0a
3e9b086
4f50ea8
a56fbb8
8e529e0
bd895e9
2d4d594
4911591
3e95218
038e1b6
968a357
a06c632
58b1339
a4dc2c7
2008893
de442f0
21dc878
b4b17f4
004f40e
af0bd34
3b7764c
3b4fb52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
name: Integration-test | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'CodeListLibrary_project/**' | ||
|
||
JossWhittle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may not work. Depends if this template gets evaluated when
If this works it will be great. Otherwise set this to |
||
|
||
jobs: | ||
pre-deploy-test: | ||
env: | ||
working-directory: ./concept-library | ||
runs-on: | ||
labels: [self-hosted, linux, x64] | ||
group: heavy | ||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: [3.11] | ||
|
||
services: | ||
db: | ||
image: postgres | ||
env: | ||
POSTGRES_DB: concept_library | ||
POSTGRES_USER: clluser_test | ||
POSTGRES_PASSWORD: password | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: browser-actions/setup-chrome@v1 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('docker/requirements/test-requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install LDAP files | ||
run: | | ||
sudo apt-get install -y -q libsasl2-dev libldap2-dev libssl-dev | ||
|
||
- name: Install Dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install --upgrade --upgrade-strategy eager -r docker/requirements/test-requirements.txt | ||
|
||
- name: Prepare Selenium | ||
uses: nanasess/setup-chromedriver@v2 | ||
- name: Run Browser | ||
run: | | ||
chrome --version | ||
- name: Run chromedriver | ||
run: | | ||
export DISPLAY=:99 | ||
chromedriver --url-base=/wd/hub & | ||
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional | ||
|
||
- name: Run application | ||
run: | | ||
export $(grep -v '^#' docker/selenium-testing/env/remotetest.compose.env | xargs) | ||
cd CodeListLibrary_project | ||
python manage.py makemigrations | ||
python manage.py migrate | ||
python manage.py runserver 0.0.0.0:8000 > /dev/null & | ||
|
||
- name: Run tests | ||
if: success() || failure() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
run: | | ||
export $(grep -v '^#' docker/selenium-testing/env/remotetest.compose.env | xargs) | ||
cd CodeListLibrary_project | ||
pytest -v -s --cov-report xml --cov . --html=report.html --self-contained-html --alluredir=./clinicalcode/tests/allure-results | ||
env: | ||
DISPLAY: ":99" | ||
|
||
- name: Coverage report | ||
if: success() || failure() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
uses: 5monkeys/cobertura-action@v13 | ||
with: | ||
path: CodeListLibrary_project/coverage.xml | ||
minimum_coverage: 25 | ||
|
||
- name: "Upload Test Results" | ||
if: success() || failure() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: test-results | ||
path: CodeListLibrary_project/report.html | ||
retention-days: 5 | ||
|
||
- name: Get Allure history | ||
uses: actions/checkout@v3 | ||
if: success() || failure() | ||
continue-on-error: true | ||
with: | ||
ref: gh-pages | ||
path: gh-pages | ||
JossWhittle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Allure report action # Step to generate Allure report | ||
if: success() || failure() | ||
uses: simple-elf/allure-report-action@master | ||
with: | ||
allure_results: CodeListLibrary_project/clinicalcode/tests/allure-results | ||
allure_report: CodeListLibrary_project/clinicalcode/tests/allure-report | ||
allure_history: allure-history | ||
gh_pages: gh-pages | ||
keep_reports: 10 # Specify the number of previous reports to keep | ||
|
||
- name: Upload an artifact for GitHub Pages | ||
uses: actions/upload-pages-artifact@v2 | ||
if: success() || failure() | ||
with: | ||
name: allure-report | ||
path: CodeListLibrary_project/clinicalcode/tests/allure-report | ||
|
||
- name: Deploy report to testing-result-pages branch | ||
if: always() | ||
uses: peaceiris/actions-gh-pages@v2 | ||
env: | ||
PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PUBLISH_BRANCH: gh-pages | ||
PUBLISH_DIR: allure-history | ||
keep_files: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
from datetime import datetime | ||
|
||
import pytest | ||
from clinicalcode.models import GenericEntity | ||
from django.contrib.auth.models import User, Group | ||
from django.utils.timezone import make_aware | ||
|
||
from selenium.webdriver import Keys | ||
from selenium import webdriver | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.wait import WebDriverWait | ||
|
||
from cll.test_settings import WEBAPP_HOST, REMOTE_TEST_HOST, REMOTE_TEST, chrome_options | ||
|
||
|
||
@pytest.fixture | ||
def generate_user(): | ||
su_user = User.objects.create_superuser(username='superuser', password='superpassword', email=None) | ||
nm_user = User.objects.create_user(username='normaluser', password='normalpassword', email=None) | ||
ow_user = User.objects.create_user(username='owneruser', password='ownerpassword', email=None) | ||
gp_user = User.objects.create_user(username='groupuser', password='grouppassword', email=None) | ||
vgp_user = User.objects.create_user(username='viewgroupuser', password='viewgrouppassword', email=None) | ||
egp_user = User.objects.create_user(username='editgroupuser', password='editgrouppassword', email=None) | ||
|
||
users = { | ||
'super_user': su_user, | ||
'normal_user': nm_user, | ||
'owner_user': ow_user, | ||
'group_user': gp_user, | ||
'view_group_user': vgp_user, | ||
'edit_group_user': egp_user, | ||
} | ||
|
||
yield users | ||
|
||
# Clean up the users after the tests are finished | ||
for user in users.values(): | ||
user.delete() | ||
|
||
|
||
@pytest.fixture | ||
def create_groups(): | ||
permitted_group = Group.objects.create(name="permitted_group") | ||
forbidden_group = Group.objects.create(name="forbidden_group") | ||
view_group = Group.objects.create(name="view_group") | ||
edit_group = Group.objects.create(name="edit_group") | ||
|
||
# Yield the created groups so they can be used in tests | ||
yield { | ||
'permitted_group': permitted_group, | ||
'forbidden_group': forbidden_group, | ||
'view_group': view_group, | ||
'edit_group': edit_group, | ||
} | ||
|
||
# Clean up the groups after the tests are finished | ||
for group in [permitted_group, forbidden_group, view_group, edit_group]: | ||
group.delete() | ||
|
||
@pytest.fixture | ||
def generate_entity(create_groups): | ||
template_data = { | ||
"sex": "3", | ||
"type": "1", | ||
"version": 1, | ||
"phenoflowid": "", | ||
"data_sources": [ | ||
5 | ||
], | ||
"coding_system": [], | ||
"agreement_date": "2012-11-23", | ||
"phenotype_uuid": "4", | ||
"event_date_range": "01/01/1999 - 01/07/2016", | ||
"source_reference": "https://portal.caliberresearch.org/phenotypes/archangelidi-heart-rate-6keWsw2mW2TQjDMhNAUETt", | ||
"concept_information": [] | ||
} | ||
generate_entity = GenericEntity.objects.create(name="Test entity", | ||
group=create_groups['permitted_group'], | ||
template_data=template_data,updated=make_aware(datetime.now())) | ||
return generate_entity | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def setup_webdriver(request): | ||
if REMOTE_TEST: | ||
driver = webdriver.Chrome(options=chrome_options) | ||
else: | ||
driver = webdriver.Remote(command_executor=REMOTE_TEST_HOST, options=chrome_options) | ||
|
||
wait = WebDriverWait(driver, 10) | ||
driver.maximize_window() | ||
request.cls.driver = driver | ||
request.cls.wait = wait | ||
yield | ||
driver.quit() | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def login(): | ||
def _login(driver, username, password): | ||
driver.get(WEBAPP_HOST + "/account/login/") | ||
username_input = driver.find_element(By.NAME, "username") | ||
password_input = driver.find_element(By.NAME, "password") | ||
|
||
# Input username and password | ||
username_input.send_keys(username) | ||
password_input.send_keys(password) | ||
|
||
# Submit the form by pressing Enter | ||
password_input.send_keys(Keys.ENTER) | ||
|
||
yield _login | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def logout(): | ||
def _logout(driver): | ||
driver.get(WEBAPP_HOST + "/account/logout/") | ||
yield _logout | ||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import time | ||
|
||
import pytest | ||
from selenium.webdriver.common.by import By | ||
|
||
from cll.test_settings import WEBAPP_HOST | ||
|
||
@pytest.mark.django_db | ||
@pytest.mark.usefixtures("setup_webdriver") | ||
class TestSearchFilters: | ||
|
||
@pytest.mark.parametrize('user_type', ['super_user']) | ||
def test_tags_filter(self, login, logout, generate_user, user_type): | ||
user = generate_user[user_type] | ||
login(self.driver, user.username, user.password) | ||
|
||
self.driver.get(WEBAPP_HOST +"/phenotypes") | ||
accordian = self.driver.find_element(By.XPATH, "/html/body/main/div/div/aside/div[2]/div[4]") | ||
time.sleep(5) | ||
accordian.click() | ||
checkboxes = self.driver.find_elements(By.XPATH, "//input[(@class='checkbox-item') and (@aria-label = 'Tags')]") | ||
|
||
for checkbox in checkboxes: | ||
assert checkbox.is_enabled() is True | ||
|
||
logout(self.driver) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from pytest import mark | ||
from clinicalcode.entity_utils.permission_utils import allowed_to_create, can_user_edit_entity | ||
import pytest | ||
from datetime import datetime | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestReadOnlyPermissions: | ||
|
||
def test_my_user(self, generate_user): | ||
super_user = generate_user['super_user'] | ||
assert super_user.username == 'superuser' | ||
|
||
@pytest.mark.parametrize('user_type', ['super_user']) | ||
def test_genereic_entity(self, generate_entity, generate_user, user_type): | ||
generate_entity.owner = generate_user[user_type] | ||
generate_entity.created_by = generate_user[user_type] | ||
assert generate_entity.name == 'Test entity' | ||
|
||
@pytest.mark.parametrize('user_type', ['super_user', 'owner_user']) | ||
def test_users_to_edit(self, generate_user, generate_entity, user_type): | ||
generate_entity.owner = generate_user[user_type] | ||
generate_entity.created_by = generate_user[user_type] | ||
assert can_user_edit_entity( | ||
None, generate_entity, generate_user[user_type]) == False | ||
|
||
def test_user_not_allowed_to_create(self): | ||
assert allowed_to_create() == False | ||
|
||
def test_wrong_answer(self): | ||
assert allowed_to_create() == True | ||
|
||
def test_wrong_again(): | ||
assert 1 == 2 | ||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an
on.
condition to handle when the PR gets merged intomain
.You can later conditionally test if
github.event_name == 'pull_request'
to run the steps for pushing to gh-pages only when this is a merge into main.