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

re-enabling and fixing django ci tests #189

Merged
merged 9 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 6 additions & 4 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
branches:
- main

env:
DATABASE_URL: mysql://dace5c60l5ctt7og:qrmu7nb4hbzjbp0z@r1bsyfx4gbowdsis.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306/uoq6lb032iusvpqz

jobs:
build:

Expand All @@ -32,7 +35,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Disabling tests for now as it requires a DB to connect to.
# - name: Run Tests
# run: |
# python manage.py test ponder.tests
- name: Run Tests
run: |
python manage.py test --pattern="tests_*.py"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ Tests that require a database will run on a separate test database. Make sure th
├── fixtures
├── forms.py
├── migrations
├── test
├── models.py
├── static
├── tables.py
├── templates
├── tests.py
├── urls.py
└── views.py
```
Expand Down
9 changes: 9 additions & 0 deletions ponder/tests.py → ponder/test/OLD_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
'''
These are the old/default tests that were database dependent that required DB creation rights to be able to
create a test database to run these tests against. Marking this file as OLD to disable running these as part of the CI
pipeline as our current free hosting setup does not allow for DB creation.

See other tests inside this module for non DB specific unit tests.
'''


from django.test import TestCase, Client
import django
django.setup()
Expand Down
Empty file added ponder/test/__init__.py
Empty file.
83 changes: 83 additions & 0 deletions ponder/test/tests_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from django.test import SimpleTestCase
from ponder.models import Commit, BugFix, Categorization, Categorizer, User
from unittest.mock import patch

class ModelTest(SimpleTestCase):
# def setUp(self):

@patch('ponder.models.Commit.objects.get')
def test_commit_model(self, commit_get):
commit_get.return_value = Commit(
id=1,
project="Mocked-project",
sha="testsha1234",
author_email="<[email protected]>"
)

mocked_commit = Commit.objects.get(id=1)

self.assertEqual(mocked_commit.project, "Mocked-project")
self.assertEqual(mocked_commit.get_project(), "https://github.com/Mocked-project")
self.assertEqual(mocked_commit.email_author(), "mailto:[email protected]")
self.assertEqual(mocked_commit.get_commit(), "https://github.com/Mocked-project/commit/testsha1234")


@patch('ponder.models.Commit.objects.values')
@patch('ponder.models.BugFix.objects.get')
def test_bugfix_model(self, bugfix_get, commit_values):
commit_values = Commit.objects.values
commit_values.filter.return_value = Commit(
id=1,
project="Mocked-project",
sha="testsha1234",
author_email="<[email protected]>",
)

bugfix_get = BugFix.objects.get
bugfix_get.return_value = BugFix(
id=9,
sha="testsha1234",
)

mocked_bugfix = BugFix.objects.get(id=9)

self.assertIn("testsha1234", mocked_bugfix.get_sha())
self.assertEqual(mocked_bugfix.get_id(), '9/')

@patch('ponder.models.Commit.objects.values')
@patch('ponder.models.User.objects.get')
@patch('ponder.models.Categorization.objects.get')
def test_categorization(self, categorization_get, user_get, commit_values):
user_get = User.objects.get
user_get.return_value = User(
id=1,
username="testuser",
email="<[email protected]>"
)

commit_values = Commit.objects.values
commit_values.filter.return_value = Commit(
id=1,
project="Mocked-project",
sha="testsha1234",
author_email="<[email protected]>",
)

categorization_get = Categorization.objects.get
categorization_get.return_value = Categorization(
id=1,
sha="testsha1234",
bug_fix=BugFix(
id=9,
sha="testsha1234",
),
categorizer=Categorizer(
name="testuser"
)
)

mocked_categorization = Categorization.objects.get(id=1)

self.assertIn("testsha1234", mocked_categorization.get_sha())
self.assertEqual(mocked_categorization.get_absolute_url(), "bug_fixes/9")
self.assertEqual(mocked_categorization.email_categorizer(), "mailto:<[email protected]>")