Skip to content

Commit

Permalink
Merge pull request #48 from EBI-G2P/dglemos-run-test
Browse files Browse the repository at this point in the history
Set up tests to run automatically
  • Loading branch information
seeta-ramaraju authored Oct 16, 2024
2 parents 128611e + bfbdd87 commit df85b5d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/test.yml
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"locus": 1,
"genotype": 9,
"disease": 2,
"molecular_mechanism": 1,
"confidence": 1,
"confidence_support": null,
"date_review": "2017-04-24T16:33:40Z",
Expand Down
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
}
}
]
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):
"""
Expand All @@ -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):
Expand All @@ -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'})
Expand All @@ -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'})
Expand Down

0 comments on commit df85b5d

Please sign in to comment.