From cb827b3d3ea2bf80c51c2c3366ddf4183bf77f6a Mon Sep 17 00:00:00 2001 From: Y Paing Date: Fri, 24 Jan 2025 19:21:11 -0500 Subject: [PATCH 1/9] re-enabling django cicd pipeline steps --- .github/workflows/django.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index a339f94..277fcd4 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -32,7 +32,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 ponder.tests From 8042e1ee412d37813ad2394d68f4292b41fb0c0a Mon Sep 17 00:00:00 2001 From: Y Paing Date: Fri, 24 Jan 2025 19:29:25 -0500 Subject: [PATCH 2/9] testing adding env variables to CICD config --- .github/workflows/django.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 277fcd4..49ffaae 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: From baa842d66e54ecdc72d143932bc4bac6fd1e24a9 Mon Sep 17 00:00:00 2001 From: Y Paing Date: Mon, 27 Jan 2025 19:21:33 -0500 Subject: [PATCH 3/9] adding test module to start writing db independent tests --- .github/workflows/django.yml | 2 +- ponder/test/__init__.py | 0 ponder/test/tests_model.py | 7 +++++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 ponder/test/__init__.py create mode 100644 ponder/test/tests_model.py diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 49ffaae..556a535 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -37,4 +37,4 @@ jobs: pip install -r requirements.txt - name: Run Tests run: | - python manage.py test ponder.tests + python manage.py test --pattern="tests_*.py" 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..edf8fca --- /dev/null +++ b/ponder/test/tests_model.py @@ -0,0 +1,7 @@ +from django.test import SimpleTestCase + +class ModelTest(SimpleTestCase): + # def setUp(self): + + def test_self(self): + self.assertEqual("Hello", "Hello") \ No newline at end of file From 68cb9d5c4e519c3a9c0bd82dea071e51f8f7851a Mon Sep 17 00:00:00 2001 From: Y Paing Date: Mon, 27 Jan 2025 19:27:57 -0500 Subject: [PATCH 4/9] moving old test file into test module --- README.md | 2 +- ponder/{tests.py => test/tests_OLD.py} | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) rename ponder/{tests.py => test/tests_OLD.py} (98%) 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/tests_OLD.py similarity index 98% rename from ponder/tests.py rename to ponder/test/tests_OLD.py index 6105931..6853bd7 100644 --- a/ponder/tests.py +++ b/ponder/test/tests_OLD.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() From e773e138b64fe1c644106ea2dc37ef838c61a15c Mon Sep 17 00:00:00 2001 From: Y Paing Date: Mon, 27 Jan 2025 19:28:55 -0500 Subject: [PATCH 5/9] reverting db env url --- .github/workflows/django.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 556a535..fae2f40 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -13,9 +13,6 @@ on: branches: - main -env: - DATABASE_URL: mysql://dace5c60l5ctt7og:qrmu7nb4hbzjbp0z@r1bsyfx4gbowdsis.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306/uoq6lb032iusvpqz - jobs: build: From 47cd52a3dee5f11c9cfa044f4ad0a5f57d10f490 Mon Sep 17 00:00:00 2001 From: Y Paing Date: Mon, 27 Jan 2025 19:30:47 -0500 Subject: [PATCH 6/9] adding back env variable with dummy value --- .github/workflows/django.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index fae2f40..0ba445c 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -13,6 +13,9 @@ on: branches: - main +env: + DATABASE_URL: test + jobs: build: From f0cb938a17e07d6899beb76ebe36cdd9c45219d8 Mon Sep 17 00:00:00 2001 From: Y Paing Date: Mon, 27 Jan 2025 19:32:03 -0500 Subject: [PATCH 7/9] adding back env variable value --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 0ba445c..556a535 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -14,7 +14,7 @@ on: - main env: - DATABASE_URL: test + DATABASE_URL: mysql://dace5c60l5ctt7og:qrmu7nb4hbzjbp0z@r1bsyfx4gbowdsis.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306/uoq6lb032iusvpqz jobs: build: From 27b5a913ceecd671b80d73fbf3cccdb777a04e34 Mon Sep 17 00:00:00 2001 From: Y Paing Date: Mon, 27 Jan 2025 19:34:24 -0500 Subject: [PATCH 8/9] fixing old test pattern --- ponder/test/{tests_OLD.py => OLD_test.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ponder/test/{tests_OLD.py => OLD_test.py} (99%) diff --git a/ponder/test/tests_OLD.py b/ponder/test/OLD_test.py similarity index 99% rename from ponder/test/tests_OLD.py rename to ponder/test/OLD_test.py index 6853bd7..c31ce77 100644 --- a/ponder/test/tests_OLD.py +++ b/ponder/test/OLD_test.py @@ -1,6 +1,6 @@ ''' 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 +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 0771e1df233cc5e18bec9721d2fadb9b76a07e9f Mon Sep 17 00:00:00 2001 From: Y Paing Date: Tue, 28 Jan 2025 18:33:15 -0500 Subject: [PATCH 9/9] adding core model tests --- ponder/test/tests_model.py | 80 +++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/ponder/test/tests_model.py b/ponder/test/tests_model.py index edf8fca..094db41 100644 --- a/ponder/test/tests_model.py +++ b/ponder/test/tests_model.py @@ -1,7 +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): - def test_self(self): - self.assertEqual("Hello", "Hello") \ No newline at end of file + @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