Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 217 commits
Commits
Show all changes
230 commits
Select commit Hold shift + click to select a range
713c7fc
test setting fix
ZinnurovArtur Oct 3, 2023
84fc2d6
Create main.yml
roshantoby Oct 4, 2023
0393b45
Merge pull request #1 from roshantoby/roshantoby-patch-1
roshantoby Oct 4, 2023
31110d5
Update main.yml
roshantoby Oct 4, 2023
bf6819e
Update and rename main.yml to test.yml
roshantoby Oct 4, 2023
365feef
Update test.yml
roshantoby Oct 4, 2023
ec6e193
Update test.yml
ZinnurovArtur Oct 4, 2023
c53c675
Merge pull request #2 from roshantoby/ZinnurovArtur-patch-1
ZinnurovArtur Oct 4, 2023
be0e2c8
Update test.yml
ZinnurovArtur Oct 4, 2023
5e3faac
adding changes to run globally
ZinnurovArtur Oct 4, 2023
f744582
adding test local to use act
ZinnurovArtur Oct 4, 2023
377cd3f
adding test main file and rename
ZinnurovArtur Oct 4, 2023
71d254f
Merge pull request #3 from roshantoby/arthur-tests
ZinnurovArtur Oct 4, 2023
2126763
adding env tests
ZinnurovArtur Oct 5, 2023
6736da3
Update testing.yml
roshantoby Oct 5, 2023
2804633
more fixes
ZinnurovArtur Oct 5, 2023
e26e772
fixing env issue to provide it to run
ZinnurovArtur Oct 5, 2023
4ceb33f
Merge pull request #4 from roshantoby/arthur-tests
roshantoby Oct 6, 2023
1dde8ab
using auto updater
ZinnurovArtur Oct 6, 2023
cc0f0e8
adding more tests
ZinnurovArtur Oct 7, 2023
f478b1b
Merge remote-tracking branch 'origin/Dynamic-Template-Feature-Master'…
ZinnurovArtur Oct 9, 2023
2b006d7
removing path
ZinnurovArtur Oct 9, 2023
61c9767
adding test chromedriver
ZinnurovArtur Oct 9, 2023
32ee053
adding chromedriver to docker
ZinnurovArtur Oct 9, 2023
bc87e56
unitest env
ZinnurovArtur Oct 9, 2023
0c84c6d
more test issues selcenium chromedriver
ZinnurovArtur Oct 9, 2023
b5767f1
removing logs
ZinnurovArtur Oct 9, 2023
fc5f03b
some fixes
ZinnurovArtur Oct 9, 2023
34cbd61
test message
ZinnurovArtur Oct 9, 2023
2be3f4c
deleted some requirements
ZinnurovArtur Oct 10, 2023
6da1e4d
deleted unused driver
ZinnurovArtur Oct 10, 2023
e09b186
changes env files
ZinnurovArtur Oct 10, 2023
b495680
adding db image
ZinnurovArtur Oct 10, 2023
754adaf
adding healh check
ZinnurovArtur Oct 10, 2023
56a9863
Merge pull request #5 from roshantoby/selenium-changes
ZinnurovArtur Oct 10, 2023
72c63ea
adding testing legacy to test
ZinnurovArtur Oct 10, 2023
eea8550
adding message to test if chromedriver works
ZinnurovArtur Oct 10, 2023
43ec6da
adding main changes
ZinnurovArtur Oct 10, 2023
0b668b5
Merge pull request #6 from roshantoby/artur-adding-test
ZinnurovArtur Oct 10, 2023
bfc9426
Merge remote-tracking branch 'origin/test-master' into file-main-testing
ZinnurovArtur Oct 10, 2023
5836c7b
adding pytest ini
ZinnurovArtur Oct 11, 2023
72b437f
same for requirements
ZinnurovArtur Oct 11, 2023
976842d
Merge pull request #7 from roshantoby/file-main-testing
ZinnurovArtur Oct 11, 2023
37be943
adding container name to the url
ZinnurovArtur Oct 12, 2023
b617f70
some refactor
ZinnurovArtur Oct 12, 2023
709b4b9
adding standalone chrome
ZinnurovArtur Oct 12, 2023
359d4c7
docker changes
ZinnurovArtur Oct 12, 2023
cf60d0f
adding separate compose
ZinnurovArtur Oct 12, 2023
08fdcaf
adding condition if test is local or not
ZinnurovArtur Oct 12, 2023
cccf5ef
adding env value for this
ZinnurovArtur Oct 12, 2023
1cdddba
deleteing unused chromedriver
ZinnurovArtur Oct 12, 2023
6689023
deleting container selenium from dev
ZinnurovArtur Oct 12, 2023
23e3e2f
Merge pull request #8 from roshantoby/file-main-testing
roshantoby Oct 12, 2023
8493f12
env fix for remote and local actions
ZinnurovArtur Oct 12, 2023
81076c4
fix of getting env
ZinnurovArtur Oct 12, 2023
78bf31d
test for github action
ZinnurovArtur Oct 12, 2023
995846a
Merge pull request #9 from roshantoby/selenium-env-fix
ZinnurovArtur Oct 12, 2023
74026d8
adding different image and adding plugin
ZinnurovArtur Oct 13, 2023
db195ce
add confest file to keep generic values
ZinnurovArtur Oct 17, 2023
6497d9b
added test tescase
ZinnurovArtur Oct 17, 2023
5be12ac
ini changes to the pytest file
ZinnurovArtur Oct 19, 2023
bccb9b0
changing default path when run container
ZinnurovArtur Oct 19, 2023
2546229
adding test user to the db
ZinnurovArtur Oct 19, 2023
d46ecf8
test user in file postgres
ZinnurovArtur Oct 19, 2023
245b366
some chages to confest
ZinnurovArtur Oct 19, 2023
db2d137
Merge pull request #10 from roshantoby/test-cases-arthur
ZinnurovArtur Oct 19, 2023
d65b047
adding more confest changes
ZinnurovArtur Oct 20, 2023
70d10af
adding more test cases
ZinnurovArtur Oct 20, 2023
a4431dd
deleted some imports
ZinnurovArtur Oct 20, 2023
a71dfde
added some test cases related to the read-only
ZinnurovArtur Oct 20, 2023
2f5e2d5
changed workflows
ZinnurovArtur Oct 20, 2023
db7417e
added confest changese
ZinnurovArtur Oct 24, 2023
4aba9ca
deleted blank
ZinnurovArtur Oct 24, 2023
cbbab58
added major changes to env
ZinnurovArtur Oct 24, 2023
9825385
added grant permision for test
ZinnurovArtur Oct 24, 2023
7e2e57d
Merge pull request #11 from roshantoby/test-cases-arthur
ZinnurovArtur Oct 24, 2023
ae6dd75
adding separate selenium testing folder
ZinnurovArtur Nov 3, 2023
00c3d36
changing selenium version
ZinnurovArtur Nov 3, 2023
b363d39
removing the old code
ZinnurovArtur Nov 3, 2023
ca84628
added changes to the env
ZinnurovArtur Nov 3, 2023
6b88b3e
using the different postgres build
ZinnurovArtur Nov 3, 2023
f123ebe
adding compose changes
ZinnurovArtur Nov 3, 2023
3d09b60
adding selenium test so we can use in the future
ZinnurovArtur Nov 3, 2023
5fc7fd6
Merge pull request #12 from roshantoby/refactor
roshantoby Nov 6, 2023
b1d2bc7
quit the driver in settings
ZinnurovArtur Nov 6, 2023
7aef4ef
adding different name for host in case remote
ZinnurovArtur Nov 6, 2023
e12f565
added pytest fixture to configure selenium driver.
Nov 6, 2023
bb65be1
Update testing-local.yml
roshantoby Nov 7, 2023
4aef5ae
Update testing-local.yml
roshantoby Nov 7, 2023
8436011
added pytest fixture to configure selenium driver.
Nov 7, 2023
42119fb
Merge remote-tracking branch 'origin/test-functional' into test-funct…
Nov 7, 2023
80b0621
added pytest fixture to configure selenium driver.
Nov 7, 2023
c765af2
added pytest fixture to configure selenium driver.
Nov 7, 2023
28da164
added corbetura coverage report to github actions
Nov 7, 2023
c574baf
added corbetura coverage report to github actions
Nov 8, 2023
8c1a69e
Merge pull request #14 from roshantoby/test-coverage
ZinnurovArtur Nov 8, 2023
8e95a7f
Merge remote-tracking branch 'origin/test-master' into changes-to-pip…
ZinnurovArtur Nov 8, 2023
c28cc21
adding the test url for getting title
ZinnurovArtur Nov 8, 2023
243439e
adding run application
ZinnurovArtur Nov 8, 2023
6206969
adding the separate file for github
ZinnurovArtur Nov 8, 2023
79f8f46
changes to env
ZinnurovArtur Nov 8, 2023
50e5ae5
adding host
ZinnurovArtur Nov 8, 2023
81fe69b
adding host to the yaml
ZinnurovArtur Nov 8, 2023
f317dc8
test again
ZinnurovArtur Nov 8, 2023
5c474df
changed user
ZinnurovArtur Nov 8, 2023
d926d09
removing run application
ZinnurovArtur Nov 8, 2023
d5d5e40
some changes
ZinnurovArtur Nov 8, 2023
5355d56
added ngrok install
ZinnurovArtur Nov 8, 2023
25d4ff7
fix yaml
ZinnurovArtur Nov 8, 2023
417958a
more yaml fix
ZinnurovArtur Nov 8, 2023
ca8d04b
ngrok access token
ZinnurovArtur Nov 8, 2023
2c0a32e
syntax error fix
ZinnurovArtur Nov 8, 2023
d7e5af1
more remote test fix
ZinnurovArtur Nov 8, 2023
a865429
more trying to get the env
ZinnurovArtur Nov 8, 2023
674cac9
different version python
ZinnurovArtur Nov 8, 2023
e7984a9
use test token
ZinnurovArtur Nov 8, 2023
a83f593
more changes
ZinnurovArtur Nov 8, 2023
9b8a6f7
more tests
ZinnurovArtur Nov 8, 2023
0398f25
move python dependency
ZinnurovArtur Nov 8, 2023
d6738a9
run browser fix
ZinnurovArtur Nov 8, 2023
24c983b
jobs delete
ZinnurovArtur Nov 8, 2023
c39caca
adding checkout code for run-tests
ZinnurovArtur Nov 8, 2023
d68233e
syntax fix
ZinnurovArtur Nov 8, 2023
f0920de
removing line
ZinnurovArtur Nov 8, 2023
d03dd09
some chnages to dependancy
ZinnurovArtur Nov 8, 2023
50ee3ef
add the dependancy in different job
ZinnurovArtur Nov 8, 2023
59debcf
restore back to original yaml
ZinnurovArtur Nov 8, 2023
82f01cc
adding missing dependency
ZinnurovArtur Nov 8, 2023
2df389a
added missing values
ZinnurovArtur Nov 8, 2023
656c0d5
more tests
ZinnurovArtur Nov 8, 2023
a6246ab
wrong env file
ZinnurovArtur Nov 8, 2023
7f8a192
fix again
ZinnurovArtur Nov 8, 2023
defc388
added corbetura coverage report to github actions
Nov 9, 2023
bbcea33
added corbetura coverage report to github actions
Nov 9, 2023
7b1b5ee
added pytest coverage report to github actions
Nov 9, 2023
abf7ca5
added pytest coverage report to github actions
Nov 9, 2023
35af21e
Merge pull request #15 from roshantoby/test-coverage
ZinnurovArtur Nov 9, 2023
ce5a685
Merge remote-tracking branch 'origin/test-master' into changes-to-pip…
ZinnurovArtur Nov 9, 2023
ba8b1be
deleting ngrok
ZinnurovArtur Nov 10, 2023
e182365
put different version
ZinnurovArtur Nov 10, 2023
14cefa3
removing tesmoato marks
ZinnurovArtur Nov 10, 2023
a4c67b6
trying cache pip
ZinnurovArtur Nov 10, 2023
79080da
more trying to cache
ZinnurovArtur Nov 10, 2023
5f1a385
more fix to cache
ZinnurovArtur Nov 10, 2023
dcd82b7
folder problem
ZinnurovArtur Nov 10, 2023
8bb43da
different approach
ZinnurovArtur Nov 10, 2023
1afbfaa
different approach
ZinnurovArtur Nov 10, 2023
28ef7b2
trying to get cache
ZinnurovArtur Nov 10, 2023
333daf8
using different path
ZinnurovArtur Nov 10, 2023
71eb122
another cache
ZinnurovArtur Nov 10, 2023
83e5163
caching only pip
ZinnurovArtur Nov 10, 2023
983342d
pip fix
ZinnurovArtur Nov 10, 2023
5bbcd7e
test wrong answer to see issue
ZinnurovArtur Nov 10, 2023
9b24d42
Some code reformat
ZinnurovArtur Nov 10, 2023
8c84903
removed cache for some reasons
ZinnurovArtur Nov 10, 2023
6ec1c2a
restoring back
ZinnurovArtur Nov 10, 2023
9308b99
Merge pull request #13 from roshantoby/changes-to-pipline
roshantoby Nov 13, 2023
390350f
added pytest coverage report to github actions
Nov 13, 2023
6899e49
Merge remote-tracking branch 'origin/test-master' into test-functional
Nov 13, 2023
b32cac0
added functional tests test_tags_filter
Nov 13, 2023
34eebd3
added functional tests test_tags_filter
Nov 14, 2023
dd30e6f
Merge pull request #16 from roshantoby/test-functional
ZinnurovArtur Nov 14, 2023
5bc7ae9
trying to generate report when fail
ZinnurovArtur Nov 14, 2023
eb4b48a
fix name
ZinnurovArtur Nov 14, 2023
77f86ed
Merge pull request #17 from roshantoby/pytest-error-handling
roshantoby Nov 14, 2023
612536f
adding driver quit instead of close
ZinnurovArtur Nov 17, 2023
1815a95
adding separtion for requirements for selenium
ZinnurovArtur Nov 17, 2023
45d64ab
deleting requirements from original file
ZinnurovArtur Nov 17, 2023
eb25faf
adding allure docker
ZinnurovArtur Nov 17, 2023
08ba6cf
changes folder for docker
ZinnurovArtur Nov 17, 2023
8ab1841
selenium docker app changs
ZinnurovArtur Nov 17, 2023
20a66af
moved test requirements
ZinnurovArtur Nov 17, 2023
f0052ac
ignore allure results
ZinnurovArtur Nov 17, 2023
7fe9b3c
changed path for generating the results
ZinnurovArtur Nov 17, 2023
ff4e6f8
test github pages
ZinnurovArtur Nov 17, 2023
6fae9b8
requirements fix
ZinnurovArtur Nov 17, 2023
44d2f03
adding allure dir
ZinnurovArtur Nov 17, 2023
4d636d2
more tests
ZinnurovArtur Nov 17, 2023
5c32022
adding different path
ZinnurovArtur Nov 17, 2023
ed2dc77
more tests to run allure
ZinnurovArtur Nov 17, 2023
ef23a7d
testing deploy
ZinnurovArtur Nov 17, 2023
783b255
fix for allure results
ZinnurovArtur Nov 19, 2023
6def110
adding allure
ZinnurovArtur Nov 20, 2023
af46891
removing always
ZinnurovArtur Nov 20, 2023
315247a
allure report with deploy
ZinnurovArtur Nov 20, 2023
90f5a5e
adding deploy changes to testing branch
ZinnurovArtur Nov 20, 2023
262829e
bug fixes
ZinnurovArtur Nov 20, 2023
7b8cf50
removed wrong test for now
ZinnurovArtur Nov 20, 2023
319bdbe
changing differnt path
ZinnurovArtur Nov 20, 2023
6b43875
adding wrong answer back
ZinnurovArtur Nov 20, 2023
a930d9f
putting working directory
ZinnurovArtur Nov 20, 2023
9c3c3c9
changin back and use differnt env
ZinnurovArtur Nov 20, 2023
df215bf
investigating why i cannot take the allure results
ZinnurovArtur Nov 20, 2023
a773ada
adding changes
ZinnurovArtur Nov 20, 2023
7879040
removing unnessary commands
ZinnurovArtur Nov 20, 2023
d145150
adding differnt way of check
ZinnurovArtur Nov 20, 2023
813bc1b
adding different path again
ZinnurovArtur Nov 20, 2023
3e0f14e
trying to genearte path this way
ZinnurovArtur Nov 20, 2023
cee239c
removing unnesary code
ZinnurovArtur Nov 20, 2023
edbc889
removing old yaml
ZinnurovArtur Nov 20, 2023
545f7d3
renaming pipline
ZinnurovArtur Nov 20, 2023
05481eb
adding wrong test to test history
ZinnurovArtur Nov 20, 2023
152b947
Merge pull request #18 from roshantoby/pytest-allure
roshantoby Nov 21, 2023
a98fe87
Add files via upload
roshantoby Nov 21, 2023
51779bf
Delete report.html
roshantoby Nov 21, 2023
f2ca197
adding github pages
ZinnurovArtur Nov 22, 2023
e997c31
test commit
ZinnurovArtur Nov 22, 2023
b50265f
Merge branch 'test-master' into pytest-allure
ZinnurovArtur Nov 22, 2023
5f37d0a
forgot keep files
ZinnurovArtur Nov 22, 2023
3e9b086
putting back the testing pages
ZinnurovArtur Nov 22, 2023
4f50ea8
removed keep file to test
ZinnurovArtur Nov 23, 2023
a56fbb8
removed job to deploy pages
ZinnurovArtur Nov 23, 2023
8e529e0
Merge pull request #19 from roshantoby/pytest-allure
roshantoby Nov 23, 2023
bd895e9
Merge branch 'test-pipline' into test-master
ZinnurovArtur Nov 23, 2023
2d4d594
adding required changes
ZinnurovArtur Nov 27, 2023
4911591
adding runs-on changes
ZinnurovArtur Nov 27, 2023
3e95218
adding comments
ZinnurovArtur Nov 27, 2023
038e1b6
renamed to gh-pages
ZinnurovArtur Nov 27, 2023
968a357
check only if changes in main folder
ZinnurovArtur Nov 27, 2023
a06c632
added changes to the concurency
ZinnurovArtur Nov 28, 2023
58b1339
adding conditions
ZinnurovArtur Nov 28, 2023
a4dc2c7
adding fix of setup chrome
ZinnurovArtur Nov 28, 2023
2008893
adding fix of psycopg
ZinnurovArtur Nov 28, 2023
de442f0
adding the ubuntu fix
ZinnurovArtur Nov 28, 2023
21dc878
putting back headless
ZinnurovArtur Nov 28, 2023
b4b17f4
adding headless
ZinnurovArtur Nov 28, 2023
004f40e
adding comma
ZinnurovArtur Nov 28, 2023
af0bd34
test of uploading the allure report
ZinnurovArtur Nov 28, 2023
3b7764c
upload artifact only when pull request
ZinnurovArtur Nov 28, 2023
3b4fb52
Adjusting ifs
ZinnurovArtur Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions .github/workflows/testing-pipline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Integration-test

on:
pull_request:

JossWhittle marked this conversation as resolved.
Show resolved Hide resolved
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not work. Depends if this template gets evaluated when github.event_name is defined.

cancel-in-progress: ${{ github.event_name == 'pull_request' }}

If this works it will be great. Otherwise set this to false.


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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if statement.

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if: always()

uses: 5monkeys/cobertura-action@v13
with:
path: CodeListLibrary_project/coverage.xml
minimum_coverage: 25

- name: "Upload Test Results"
if: success() || failure()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if: always()

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: testing-result-pages # this needs to be changed to gh-pages after finilizing the docs pipline
path: testing-result-pages # this needs to be changed to gh-pages after finilizing the docs pipline

- 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: testing-result-pages # this needs to be changed to gh-pages after finilizing the docs pipline
JossWhittle marked this conversation as resolved.
Show resolved Hide resolved
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: testing-result-pages # this needs to be changed to gh-pages after finilizing the docs pipline
JossWhittle marked this conversation as resolved.
Show resolved Hide resolved
PUBLISH_DIR: allure-history
keep_files: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ docker/CodeListLibrary_project
# macOS system files
.DS_Stores
.idea

CodeListLibrary_project/clinicalcode/tests/allure-results/
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,4 @@ def chk_valid_id(request, set_class, pk, chk_permission=False):
ret_id = set_class.objects.get(pk=actual_pk).id

return is_valid_id, err, ret_id

125 changes: 125 additions & 0 deletions CodeListLibrary_project/clinicalcode/tests/conftest.py
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




Loading
Loading