diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index a339f94..556a535 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -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: @@ -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" diff --git a/README.md b/README.md index d07c7c5..789e762 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/ponder/tests.py b/ponder/test/OLD_test.py similarity index 98% rename from ponder/tests.py rename to ponder/test/OLD_test.py index 6105931..c31ce77 100644 --- a/ponder/tests.py +++ b/ponder/test/OLD_test.py @@ -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() diff --git a/ponder/test/__init__.py b/ponder/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ponder/test/tests_model.py b/ponder/test/tests_model.py new file mode 100644 index 0000000..094db41 --- /dev/null +++ b/ponder/test/tests_model.py @@ -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="" + ) + + 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:test@tester.com") + 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="", + ) + + 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="" + ) + + commit_values = Commit.objects.values + commit_values.filter.return_value = Commit( + id=1, + project="Mocked-project", + sha="testsha1234", + author_email="", + ) + + 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:") \ No newline at end of file