-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from EBI-G2P/dglemos-run-test
Set up tests to run automatically
- Loading branch information
Showing
4 changed files
with
86 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: G2P API tests | ||
|
||
on: [pull_request] | ||
|
||
permissions: | ||
contents: read | ||
actions: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
services: | ||
mysql: | ||
image: mysql:8.0 | ||
env: | ||
MYSQL_ROOT_PASSWORD: root | ||
MYSQL_DATABASE: test_db | ||
ports: | ||
- 3306:3306 | ||
options: >- | ||
--health-cmd="mysqladmin ping -h localhost" --health-interval=10s | ||
--health-timeout=5s --health-retries=3 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Change to the root directory | ||
run: cd /home/runner/work | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Create project config file | ||
run: | | ||
echo "# config.ini" > /home/runner/work/config.ini | ||
echo "[database]" >> /home/runner/work/config.ini | ||
echo "name=test_db" >> /home/runner/work/config.ini | ||
echo "user=root" >> /home/runner/work/config.ini | ||
echo "password=root" >> /home/runner/work/config.ini | ||
echo "host=127.0.0.1" >> /home/runner/work/config.ini | ||
echo "port=3306" >> /home/runner/work/config.ini | ||
- name: Run tests | ||
run: | | ||
python manage.py makemigrations | ||
python manage.py migrate | ||
python manage.py test gene2phenotype_app.tests | ||
env: | ||
SECRET_KEY: ${{ secrets.SECRET_KEY }} | ||
PROJECT_CONFIG_PATH: /home/runner/work/config.ini | ||
working-directory: gene2phenotype_project |
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
14 changes: 14 additions & 0 deletions
14
gene2phenotype_project/gene2phenotype_app/fixtures/molecular_mechanism.json
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,14 @@ | ||
[ | ||
{ | ||
"model": "gene2phenotype_app.molecularmechanism", | ||
"pk": 1, | ||
"fields": { | ||
"mechanism": 1, | ||
"mechanism_support": 16, | ||
"synopsis": null, | ||
"synopsis_support": null, | ||
"mechanism_description": null, | ||
"is_deleted": 0 | ||
} | ||
} | ||
] |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from knox.models import AuthToken | ||
from gene2phenotype_app.models import User | ||
|
||
class PanelListEndpointTests(TestCase): | ||
""" | ||
|
@@ -25,11 +26,15 @@ def test_login_get_panel_list(self): | |
Test for autenticated users. | ||
All panels are included in the response. | ||
""" | ||
login = self.client.login(username="[email protected]", password="user5pass") | ||
self.assertTrue(login) | ||
user = User.objects.get(email="[email protected]") | ||
# Create token for the user | ||
token_id = AuthToken.objects.create(user)[1] | ||
# Authenticate using the token | ||
self.client.defaults['HTTP_AUTHORIZATION'] = 'Token ' + token_id | ||
|
||
response = self.client.get(self.url_panels) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
self.assertEqual(response.data.get("count"), 3) | ||
|
||
class PanelDetailsEndpointTests(TestCase): | ||
|
@@ -40,7 +45,8 @@ class PanelDetailsEndpointTests(TestCase): | |
"gene2phenotype_app/fixtures/g2p_stable_id.json", "gene2phenotype_app/fixtures/locus.json", | ||
"gene2phenotype_app/fixtures/sequence.json", "gene2phenotype_app/fixtures/disease.json", | ||
"gene2phenotype_app/fixtures/ontology_term.json", "gene2phenotype_app/fixtures/source.json", | ||
"gene2phenotype_app/fixtures/locus_genotype_disease.json", "gene2phenotype_app/fixtures/lgd_panel.json"] | ||
"gene2phenotype_app/fixtures/locus_genotype_disease.json", "gene2phenotype_app/fixtures/lgd_panel.json", | ||
"gene2phenotype_app/fixtures/molecular_mechanism.json", "gene2phenotype_app/fixtures/cv_molecular_mechanism.json"] | ||
|
||
def setUp(self): | ||
self.url_panels = reverse('panel_details', kwargs={'name': 'DD'}) | ||
|
@@ -61,7 +67,8 @@ class PanelSummaryEndpointTests(TestCase): | |
"gene2phenotype_app/fixtures/g2p_stable_id.json", "gene2phenotype_app/fixtures/locus.json", | ||
"gene2phenotype_app/fixtures/sequence.json", "gene2phenotype_app/fixtures/disease.json", | ||
"gene2phenotype_app/fixtures/ontology_term.json", "gene2phenotype_app/fixtures/source.json", | ||
"gene2phenotype_app/fixtures/locus_genotype_disease.json", "gene2phenotype_app/fixtures/lgd_panel.json"] | ||
"gene2phenotype_app/fixtures/locus_genotype_disease.json", "gene2phenotype_app/fixtures/lgd_panel.json", | ||
"gene2phenotype_app/fixtures/molecular_mechanism.json", "gene2phenotype_app/fixtures/cv_molecular_mechanism.json"] | ||
|
||
def setUp(self): | ||
self.url_panels = reverse('panel_summary', kwargs={'name': 'DD'}) | ||
|