Skip to content

Commit ee0d682

Browse files
authored
Merge pull request #189 from ponder-lab/ypaing/reenable-cicd-steps
re-enabling and fixing django ci tests
2 parents 462d465 + 0771e1d commit ee0d682

File tree

5 files changed

+99
-5
lines changed

5 files changed

+99
-5
lines changed

.github/workflows/django.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
branches:
1414
- main
1515

16+
env:
17+
DATABASE_URL: mysql://dace5c60l5ctt7og:qrmu7nb4hbzjbp0z@r1bsyfx4gbowdsis.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306/uoq6lb032iusvpqz
18+
1619
jobs:
1720
build:
1821

@@ -32,7 +35,6 @@ jobs:
3235
run: |
3336
python -m pip install --upgrade pip
3437
pip install -r requirements.txt
35-
# Disabling tests for now as it requires a DB to connect to.
36-
# - name: Run Tests
37-
# run: |
38-
# python manage.py test ponder.tests
38+
- name: Run Tests
39+
run: |
40+
python manage.py test --pattern="tests_*.py"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ Tests that require a database will run on a separate test database. Make sure th
110110
├── fixtures
111111
├── forms.py
112112
├── migrations
113+
├── test
113114
├── models.py
114115
├── static
115116
├── tables.py
116117
├── templates
117-
├── tests.py
118118
├── urls.py
119119
└── views.py
120120
```

ponder/tests.py ponder/test/OLD_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
'''
2+
These are the old/default tests that were database dependent that required DB creation rights to be able to
3+
create a test database to run these tests against. Marking this file as OLD to disable running these as part of the CI
4+
pipeline as our current free hosting setup does not allow for DB creation.
5+
6+
See other tests inside this module for non DB specific unit tests.
7+
'''
8+
9+
110
from django.test import TestCase, Client
211
import django
312
django.setup()

ponder/test/__init__.py

Whitespace-only changes.

ponder/test/tests_model.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from django.test import SimpleTestCase
2+
from ponder.models import Commit, BugFix, Categorization, Categorizer, User
3+
from unittest.mock import patch
4+
5+
class ModelTest(SimpleTestCase):
6+
# def setUp(self):
7+
8+
@patch('ponder.models.Commit.objects.get')
9+
def test_commit_model(self, commit_get):
10+
commit_get.return_value = Commit(
11+
id=1,
12+
project="Mocked-project",
13+
sha="testsha1234",
14+
author_email="<[email protected]>"
15+
)
16+
17+
mocked_commit = Commit.objects.get(id=1)
18+
19+
self.assertEqual(mocked_commit.project, "Mocked-project")
20+
self.assertEqual(mocked_commit.get_project(), "https://github.com/Mocked-project")
21+
self.assertEqual(mocked_commit.email_author(), "mailto:[email protected]")
22+
self.assertEqual(mocked_commit.get_commit(), "https://github.com/Mocked-project/commit/testsha1234")
23+
24+
25+
@patch('ponder.models.Commit.objects.values')
26+
@patch('ponder.models.BugFix.objects.get')
27+
def test_bugfix_model(self, bugfix_get, commit_values):
28+
commit_values = Commit.objects.values
29+
commit_values.filter.return_value = Commit(
30+
id=1,
31+
project="Mocked-project",
32+
sha="testsha1234",
33+
author_email="<[email protected]>",
34+
)
35+
36+
bugfix_get = BugFix.objects.get
37+
bugfix_get.return_value = BugFix(
38+
id=9,
39+
sha="testsha1234",
40+
)
41+
42+
mocked_bugfix = BugFix.objects.get(id=9)
43+
44+
self.assertIn("testsha1234", mocked_bugfix.get_sha())
45+
self.assertEqual(mocked_bugfix.get_id(), '9/')
46+
47+
@patch('ponder.models.Commit.objects.values')
48+
@patch('ponder.models.User.objects.get')
49+
@patch('ponder.models.Categorization.objects.get')
50+
def test_categorization(self, categorization_get, user_get, commit_values):
51+
user_get = User.objects.get
52+
user_get.return_value = User(
53+
id=1,
54+
username="testuser",
55+
56+
)
57+
58+
commit_values = Commit.objects.values
59+
commit_values.filter.return_value = Commit(
60+
id=1,
61+
project="Mocked-project",
62+
sha="testsha1234",
63+
author_email="<[email protected]>",
64+
)
65+
66+
categorization_get = Categorization.objects.get
67+
categorization_get.return_value = Categorization(
68+
id=1,
69+
sha="testsha1234",
70+
bug_fix=BugFix(
71+
id=9,
72+
sha="testsha1234",
73+
),
74+
categorizer=Categorizer(
75+
name="testuser"
76+
)
77+
)
78+
79+
mocked_categorization = Categorization.objects.get(id=1)
80+
81+
self.assertIn("testsha1234", mocked_categorization.get_sha())
82+
self.assertEqual(mocked_categorization.get_absolute_url(), "bug_fixes/9")
83+
self.assertEqual(mocked_categorization.email_categorizer(), "mailto:<[email protected]>")

0 commit comments

Comments
 (0)