From b5ee6b98844374406b6e72b0bbcddef74c8c9f41 Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 7 May 2024 23:26:49 +0100 Subject: [PATCH 1/8] Issues which the linter was pointing to in the codebase has been resolved --- docs/contributing.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/contributing.md b/docs/contributing.md index 8d10ce7..a0ff08d 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -71,7 +71,8 @@ Ready to contribute? Here’s how to set up `growth-forge` for local development $ git clone git@github.com:your_name_here/growth-forge.git ``` -3. **Install Dependencies**: Use `mamba` to create a Conda environment and`poetry` for managing Python dependencies. +3. **Install Dependencies**: Use `mamba` to create a Conda environment + and`poetry` for managing Python dependencies. ```bash $ cd growth-forge/ # in the case you are not in the root of the project @@ -118,14 +119,18 @@ $ git push origin name-of-your-bugfix-or-feature ```bash $ sugar build ``` + 3. It is important to run the command: ```bash $ makim django.migrate ``` -This command is executed to apply migrations based on the current migration files. -4. To create a superuser, you should use the following commands with your information: +This command is executed to apply migrations based on the current migration +files. + +4. To create a superuser, you should use the following commands with your + information: ```bash $ makim django.create-superuser --email @@ -153,12 +158,18 @@ The project will be accessible at `localhost:8000`. $ sugar ext restart --options ``` -The command mentioned is used to restart the project, which can be useful when registering a new user. - -After adding a new user, you should check the console for the email verification link. To complete the email verification, click on the link, which will open in your browser. There, you will see the option to verify the email. This step is crucial to ensure the email address is valid and active, enabling the new user to fully utilize their account. +The command mentioned is used to restart the project, which can be useful when +registering a new user. -7. Once you have accessed the verification link and verified your email, you can navigate through the menu of the project "growth-forge." This menu will likely offer various options related to project settings. +After adding a new user, you should check the console for the email verification +link. To complete the email verification, click on the link, which will open in +your browser. There, you will see the option to verify the email. This step is +crucial to ensure the email address is valid and active, enabling the new user +to fully utilize their account. +7. Once you have accessed the verification link and verified your email, you can + navigate through the menu of the project "growth-forge." This menu will + likely offer various options related to project settings. ## Pull Request Guidelines From 95174a81e98b862c39650f454a4b3d1fd5d96192 Mon Sep 17 00:00:00 2001 From: Bobby Date: Wed, 5 Jun 2024 08:13:26 +0100 Subject: [PATCH 2/8] Test models commit --- src/growth_forge/tests/__init__.py | 0 src/growth_forge/tests/test_models.py | 0 src/growth_plan/tests/__init__.py | 0 src/growth_plan/tests/test_models.py | 0 src/one_on_one/tests/__init__.py | 0 src/one_on_one/tests/test_models.py | 0 src/projects/tests/__init__.py | 0 src/projects/tests/test_models.py | 0 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/growth_forge/tests/__init__.py create mode 100644 src/growth_forge/tests/test_models.py create mode 100644 src/growth_plan/tests/__init__.py create mode 100644 src/growth_plan/tests/test_models.py create mode 100644 src/one_on_one/tests/__init__.py create mode 100644 src/one_on_one/tests/test_models.py create mode 100644 src/projects/tests/__init__.py create mode 100644 src/projects/tests/test_models.py diff --git a/src/growth_forge/tests/__init__.py b/src/growth_forge/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/growth_forge/tests/test_models.py b/src/growth_forge/tests/test_models.py new file mode 100644 index 0000000..e69de29 diff --git a/src/growth_plan/tests/__init__.py b/src/growth_plan/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/growth_plan/tests/test_models.py b/src/growth_plan/tests/test_models.py new file mode 100644 index 0000000..e69de29 diff --git a/src/one_on_one/tests/__init__.py b/src/one_on_one/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/one_on_one/tests/test_models.py b/src/one_on_one/tests/test_models.py new file mode 100644 index 0000000..e69de29 diff --git a/src/projects/tests/__init__.py b/src/projects/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/projects/tests/test_models.py b/src/projects/tests/test_models.py new file mode 100644 index 0000000..e69de29 From 32ce9e371b857df0ddf79bae5d7cf2cc417f7be8 Mon Sep 17 00:00:00 2001 From: Bobby Date: Wed, 5 Jun 2024 08:28:05 +0100 Subject: [PATCH 3/8] test issues --- src/growth_forge/tests/test_models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/growth_forge/tests/test_models.py b/src/growth_forge/tests/test_models.py index e69de29..1d2e98b 100644 --- a/src/growth_forge/tests/test_models.py +++ b/src/growth_forge/tests/test_models.py @@ -0,0 +1 @@ +#test models code yet to be inserted \ No newline at end of file From d56409856d3f9a9b79e0499285632afa4140461a Mon Sep 17 00:00:00 2001 From: Bobby Date: Wed, 5 Jun 2024 08:35:55 +0100 Subject: [PATCH 4/8] test issues --- src/growth_plan/tests/test_models.py | 1 + src/one_on_one/tests/test_models.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/growth_plan/tests/test_models.py b/src/growth_plan/tests/test_models.py index e69de29..1d2e98b 100644 --- a/src/growth_plan/tests/test_models.py +++ b/src/growth_plan/tests/test_models.py @@ -0,0 +1 @@ +#test models code yet to be inserted \ No newline at end of file diff --git a/src/one_on_one/tests/test_models.py b/src/one_on_one/tests/test_models.py index e69de29..1d2e98b 100644 --- a/src/one_on_one/tests/test_models.py +++ b/src/one_on_one/tests/test_models.py @@ -0,0 +1 @@ +#test models code yet to be inserted \ No newline at end of file From a57e32a4eb963690fd0b17204b31e79dfdae96d8 Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 25 Jun 2024 02:28:36 +0100 Subject: [PATCH 5/8] models test successful --- src/growth_forge/tests/test_models.py | 57 +++++++++++++++++++++++++- src/growth_forge/users/managers.py | 8 ++-- src/growth_plan/tests.py | 1 - src/growth_plan/tests/__init__.py | 1 + src/growth_plan/tests/test_models.py | 59 ++++++++++++++++++++++++++- src/one_on_one/tests.py | 1 - src/one_on_one/tests/test_models.py | 58 +++++++++++++++++++++++++- src/projects/tests.py | 1 - src/projects/tests/test_models.py | 52 +++++++++++++++++++++++ 9 files changed, 228 insertions(+), 10 deletions(-) delete mode 100644 src/growth_plan/tests.py delete mode 100644 src/one_on_one/tests.py delete mode 100644 src/projects/tests.py diff --git a/src/growth_forge/tests/test_models.py b/src/growth_forge/tests/test_models.py index 1d2e98b..edde650 100644 --- a/src/growth_forge/tests/test_models.py +++ b/src/growth_forge/tests/test_models.py @@ -1 +1,56 @@ -#test models code yet to be inserted \ No newline at end of file +from django.test import TestCase +from django.contrib.auth import get_user_model +from growth_forge.models import Profile +from projects.models import Project + +User = get_user_model() + +class ProfileTests(TestCase): + @classmethod + def setUpClass(cls): + # Create a user for testing + cls.user = User.objects.create_user( + # username='testuser2', + password='testpassword2', + email='test@test.com' + ) + cls.user2 = User.objects.create_user(email='testuser2@example.com', password='testpassword') + + @classmethod + def tearDownClass(cls): + # Create a user for testing + cls.user.delete() + + cls.user2.delete() + + def test_create_profile(self): + # The Profile should be created automatically due to the post_save signal + profile = Profile.objects.get(user=self.user) + self.assertIsNotNone( + profile + ) + self.assertEqual( + profile.user.email, + 'test@test.com' + ) + + def test_retrieve_profile(self): + profile = Profile.objects.get(user=self.user) + retrieved_profile = Profile.objects.get(id=profile.id) + self.assertEqual(retrieved_profile.user.email, 'test@test.com') + + def test_update_profile(self): + profile, _ = Profile.objects.get_or_create(user=self.user) + # Create a Project instance and add it to the profile's projects + project = Project.objects.create(name='Test Project') + profile.projects.add(project) + # Verify the profile has the project added + self.assertIn(project, profile.projects.all()) + + + def test_delete_profile(self): + profile = Profile.objects.get(user=self.user) + profile_id = profile.id + profile.delete() + with self.assertRaises(Profile.DoesNotExist): + Profile.objects.get(id=profile_id) diff --git a/src/growth_forge/users/managers.py b/src/growth_forge/users/managers.py index 5d832aa..91be61f 100644 --- a/src/growth_forge/users/managers.py +++ b/src/growth_forge/users/managers.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING - +from typing import Optional from django.contrib.auth.hashers import make_password from django.contrib.auth.models import UserManager as DjangoUserManager @@ -14,7 +14,7 @@ class UserManager(DjangoUserManager['User']): """Custom manager for the User model.""" def _create_user( - self, email: str, password: str | None, **extra_fields + self, email: str, password: str, username: Optional[str] = None, **extra_fields ) -> User: """ Create and save a user with the given email and password. @@ -23,7 +23,7 @@ def _create_user( msg = 'The given email must be set' raise ValueError(msg) email = self.normalize_email(email) - user = self.model(email=email, **extra_fields) + user = self.model(email=email) user.password = make_password(password) user.save(using=self._db) return user @@ -36,7 +36,7 @@ def create_user( ): # type: ignore[override] extra_fields.setdefault('is_staff', False) extra_fields.setdefault('is_superuser', False) - return self._create_user(email, password, **extra_fields) + return self._create_user(email, password) def create_superuser( self, diff --git a/src/growth_plan/tests.py b/src/growth_plan/tests.py deleted file mode 100644 index a39b155..0000000 --- a/src/growth_plan/tests.py +++ /dev/null @@ -1 +0,0 @@ -# Create your tests here. diff --git a/src/growth_plan/tests/__init__.py b/src/growth_plan/tests/__init__.py index e69de29..f853b10 100644 --- a/src/growth_plan/tests/__init__.py +++ b/src/growth_plan/tests/__init__.py @@ -0,0 +1 @@ +from tests import * \ No newline at end of file diff --git a/src/growth_plan/tests/test_models.py b/src/growth_plan/tests/test_models.py index 1d2e98b..1a0c868 100644 --- a/src/growth_plan/tests/test_models.py +++ b/src/growth_plan/tests/test_models.py @@ -1 +1,58 @@ -#test models code yet to be inserted \ No newline at end of file +#test models code yet to be inserted +#test models code yet to be inserted +from django.test import TestCase +from django.contrib.auth import get_user_model +from growth_plan.models import GrowthPlanItem +from django.utils import timezone +from datetime import timedelta + +User = get_user_model() + +class GrowthPlanItemTests(TestCase): + + def setUp(self): + # Create a user for testing + self.user = User.objects.create_user( + # username='testuser', + password='testpassword', + email='test@test.com' + ) + self.client.login( + # username='testuser', + password='testpassword', + email='test@test.com' + ) + + # Common data for test cases + self.growth_plan_item_data = { + 'user': self.user, + 'title': 'Test Growth Plan', + 'description': 'This is a test description.', + 'start_date': timezone.now().date(), + 'end_date': (timezone.now() + timedelta(days=10)).date(), + 'progress_percentage': 50, + } + + def test_create_growth_plan_item(self): + growth_plan_item = GrowthPlanItem.objects.create(**self.growth_plan_item_data) + self.assertEqual(GrowthPlanItem.objects.count(), 1) + self.assertEqual(growth_plan_item.title, 'Test Growth Plan') + + def test_retrieve_growth_plan_item(self): + growth_plan_item = GrowthPlanItem.objects.create(**self.growth_plan_item_data) + retrieved_item = GrowthPlanItem.objects.get(id=growth_plan_item.id) + self.assertEqual(retrieved_item.title, growth_plan_item.title) + + def test_update_growth_plan_item(self): + growth_plan_item = GrowthPlanItem.objects.create(**self.growth_plan_item_data) + growth_plan_item.title = 'Updated Title' + growth_plan_item.save() + updated_item = GrowthPlanItem.objects.get(id=growth_plan_item.id) + self.assertEqual(updated_item.title, 'Updated Title') + + def test_delete_growth_plan_item(self): + growth_plan_item = GrowthPlanItem.objects.create(**self.growth_plan_item_data) + growth_plan_item_id = growth_plan_item.id + growth_plan_item.delete() + with self.assertRaises(GrowthPlanItem.DoesNotExist): + GrowthPlanItem.objects.get(id=growth_plan_item_id) diff --git a/src/one_on_one/tests.py b/src/one_on_one/tests.py deleted file mode 100644 index a39b155..0000000 --- a/src/one_on_one/tests.py +++ /dev/null @@ -1 +0,0 @@ -# Create your tests here. diff --git a/src/one_on_one/tests/test_models.py b/src/one_on_one/tests/test_models.py index 1d2e98b..724c07c 100644 --- a/src/one_on_one/tests/test_models.py +++ b/src/one_on_one/tests/test_models.py @@ -1 +1,57 @@ -#test models code yet to be inserted \ No newline at end of file +#test models code yet to be inserted +from django.test import TestCase +from django.contrib.auth import get_user_model +from djf_surveys.models import Survey +from one_on_one.models import Link + +User = get_user_model() + +class LinkTests(TestCase): + + def setUp(self): + # Create users for testing + self.mentor = User.objects.create_user(email='mentor@example.com', password='testpassword') + self.mentee = User.objects.create_user(email='mentee@example.com', password='testpassword') + + # Create surveys for testing + self.mentor_survey = Survey.objects.create(name='Mentor Survey') + self.mentee_survey = Survey.objects.create(name='Mentee Survey') + + # Common data for test cases + self.link_data = { + 'mentor': self.mentor, + 'mentee': self.mentee, + 'mentor_survey': self.mentor_survey, + 'mentee_survey': self.mentee_survey, + 'periodicity': 'weekly', + 'times': 5, + } + + def test_create_link(self): + link = Link.objects.create(**self.link_data) + self.assertEqual(Link.objects.count(), 1) + self.assertEqual(link.mentor.email, 'mentor@example.com') + self.assertEqual(link.mentee.email, 'mentee@example.com') + self.assertEqual(link.periodicity, 'weekly') + + def test_retrieve_link(self): + link = Link.objects.create(**self.link_data) + retrieved_link = Link.objects.get(id=link.id) + self.assertEqual(retrieved_link.mentor.email, 'mentor@example.com') + self.assertEqual(retrieved_link.mentee.email, 'mentee@example.com') + + def test_update_link(self): + link = Link.objects.create(**self.link_data) + link.periodicity = 'monthly' + link.times = 10 + link.save() + updated_link = Link.objects.get(id=link.id) + self.assertEqual(updated_link.periodicity, 'monthly') + self.assertEqual(updated_link.times, 10) + + def test_delete_link(self): + link = Link.objects.create(**self.link_data) + link_id = link.id + link.delete() + with self.assertRaises(Link.DoesNotExist): + Link.objects.get(id=link_id) diff --git a/src/projects/tests.py b/src/projects/tests.py deleted file mode 100644 index a39b155..0000000 --- a/src/projects/tests.py +++ /dev/null @@ -1 +0,0 @@ -# Create your tests here. diff --git a/src/projects/tests/test_models.py b/src/projects/tests/test_models.py index e69de29..1cec5c4 100644 --- a/src/projects/tests/test_models.py +++ b/src/projects/tests/test_models.py @@ -0,0 +1,52 @@ +from django.test import TestCase +from django.contrib.auth import get_user_model +from projects.models import Project + +User = get_user_model() + +class ProjectTests(TestCase): + + def setUp(self): + # Create users for testing + self.user1 = User.objects.create_user(email='user1@example.com', password='testpassword') + self.user2 = User.objects.create_user(email='user2@example.com', password='testpassword') + + # Common data for test cases + self.project_data = { + 'name': 'Test Project', + } + + def test_create_project(self): + project = Project.objects.create(**self.project_data) + project.observers.add(self.user1, self.user2) + self.assertEqual(Project.objects.count(), 1) + self.assertEqual(project.name, 'Test Project') + self.assertIn(self.user1, project.observers.all()) + self.assertIn(self.user2, project.observers.all()) + + def test_retrieve_project(self): + project = Project.objects.create(**self.project_data) + project.observers.add(self.user1, self.user2) + retrieved_project = Project.objects.get(id=project.id) + self.assertEqual(retrieved_project.name, 'Test Project') + self.assertIn(self.user1, retrieved_project.observers.all()) + self.assertIn(self.user2, retrieved_project.observers.all()) + + def test_update_project(self): + project = Project.objects.create(**self.project_data) + project.observers.add(self.user1) + project.name = 'Updated Project' + project.observers.remove(self.user1) + project.observers.add(self.user2) + project.save() + updated_project = Project.objects.get(id=project.id) + self.assertEqual(updated_project.name, 'Updated Project') + self.assertNotIn(self.user1, updated_project.observers.all()) + self.assertIn(self.user2, updated_project.observers.all()) + + def test_delete_project(self): + project = Project.objects.create(**self.project_data) + project_id = project.id + project.delete() + with self.assertRaises(Project.DoesNotExist): + Project.objects.get(id=project_id) \ No newline at end of file From a65e1ab27079d11206854d564967ebf09434a66e Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 25 Jun 2024 05:17:24 +0100 Subject: [PATCH 6/8] models test successful. --- src/growth_forge/tests/test_models.py | 30 +++++++++++----------- src/growth_forge/users/managers.py | 10 +++++--- src/growth_plan/tests/__init__.py | 2 +- src/growth_plan/tests/test_models.py | 36 +++++++++++++++++---------- src/one_on_one/tests/test_models.py | 15 +++++++---- src/projects/tests/test_models.py | 15 +++++++---- 6 files changed, 65 insertions(+), 43 deletions(-) diff --git a/src/growth_forge/tests/test_models.py b/src/growth_forge/tests/test_models.py index edde650..475b1ba 100644 --- a/src/growth_forge/tests/test_models.py +++ b/src/growth_forge/tests/test_models.py @@ -1,38 +1,37 @@ -from django.test import TestCase from django.contrib.auth import get_user_model -from growth_forge.models import Profile +from django.test import TestCase from projects.models import Project +from growth_forge.models import Profile + User = get_user_model() + class ProfileTests(TestCase): @classmethod def setUpClass(cls): # Create a user for testing cls.user = User.objects.create_user( - # username='testuser2', - password='testpassword2', - email='test@test.com' + # username='testuser2', + password='testpassword2', + email='test@test.com', + ) + cls.user2 = User.objects.create_user( + email='testuser2@example.com', password='testpassword' ) - cls.user2 = User.objects.create_user(email='testuser2@example.com', password='testpassword') @classmethod def tearDownClass(cls): # Create a user for testing - cls.user.delete() + cls.user.delete() - cls.user2.delete() + cls.user2.delete() def test_create_profile(self): # The Profile should be created automatically due to the post_save signal profile = Profile.objects.get(user=self.user) - self.assertIsNotNone( - profile - ) - self.assertEqual( - profile.user.email, - 'test@test.com' - ) + self.assertIsNotNone(profile) + self.assertEqual(profile.user.email, 'test@test.com') def test_retrieve_profile(self): profile = Profile.objects.get(user=self.user) @@ -46,7 +45,6 @@ def test_update_profile(self): profile.projects.add(project) # Verify the profile has the project added self.assertIn(project, profile.projects.all()) - def test_delete_profile(self): profile = Profile.objects.get(user=self.user) diff --git a/src/growth_forge/users/managers.py b/src/growth_forge/users/managers.py index 91be61f..6db5532 100644 --- a/src/growth_forge/users/managers.py +++ b/src/growth_forge/users/managers.py @@ -1,8 +1,8 @@ # type: ignore from __future__ import annotations -from typing import TYPE_CHECKING -from typing import Optional +from typing import TYPE_CHECKING, Optional + from django.contrib.auth.hashers import make_password from django.contrib.auth.models import UserManager as DjangoUserManager @@ -14,7 +14,11 @@ class UserManager(DjangoUserManager['User']): """Custom manager for the User model.""" def _create_user( - self, email: str, password: str, username: Optional[str] = None, **extra_fields + self, + email: str, + password: str, + username: Optional[str] = None, + **extra_fields, ) -> User: """ Create and save a user with the given email and password. diff --git a/src/growth_plan/tests/__init__.py b/src/growth_plan/tests/__init__.py index f853b10..ecadf74 100644 --- a/src/growth_plan/tests/__init__.py +++ b/src/growth_plan/tests/__init__.py @@ -1 +1 @@ -from tests import * \ No newline at end of file +from tests import * diff --git a/src/growth_plan/tests/test_models.py b/src/growth_plan/tests/test_models.py index 1a0c868..c16aedb 100644 --- a/src/growth_plan/tests/test_models.py +++ b/src/growth_plan/tests/test_models.py @@ -1,26 +1,28 @@ -#test models code yet to be inserted -#test models code yet to be inserted -from django.test import TestCase +# test models code yet to be inserted +# test models code yet to be inserted +from datetime import timedelta + from django.contrib.auth import get_user_model -from growth_plan.models import GrowthPlanItem +from django.test import TestCase from django.utils import timezone -from datetime import timedelta + +from growth_plan.models import GrowthPlanItem User = get_user_model() -class GrowthPlanItemTests(TestCase): +class GrowthPlanItemTests(TestCase): def setUp(self): # Create a user for testing self.user = User.objects.create_user( # username='testuser', password='testpassword', - email='test@test.com' + email='test@test.com', ) self.client.login( - # username='testuser', + # username='testuser', password='testpassword', - email='test@test.com' + email='test@test.com', ) # Common data for test cases @@ -34,24 +36,32 @@ def setUp(self): } def test_create_growth_plan_item(self): - growth_plan_item = GrowthPlanItem.objects.create(**self.growth_plan_item_data) + growth_plan_item = GrowthPlanItem.objects.create( + **self.growth_plan_item_data + ) self.assertEqual(GrowthPlanItem.objects.count(), 1) self.assertEqual(growth_plan_item.title, 'Test Growth Plan') def test_retrieve_growth_plan_item(self): - growth_plan_item = GrowthPlanItem.objects.create(**self.growth_plan_item_data) + growth_plan_item = GrowthPlanItem.objects.create( + **self.growth_plan_item_data + ) retrieved_item = GrowthPlanItem.objects.get(id=growth_plan_item.id) self.assertEqual(retrieved_item.title, growth_plan_item.title) def test_update_growth_plan_item(self): - growth_plan_item = GrowthPlanItem.objects.create(**self.growth_plan_item_data) + growth_plan_item = GrowthPlanItem.objects.create( + **self.growth_plan_item_data + ) growth_plan_item.title = 'Updated Title' growth_plan_item.save() updated_item = GrowthPlanItem.objects.get(id=growth_plan_item.id) self.assertEqual(updated_item.title, 'Updated Title') def test_delete_growth_plan_item(self): - growth_plan_item = GrowthPlanItem.objects.create(**self.growth_plan_item_data) + growth_plan_item = GrowthPlanItem.objects.create( + **self.growth_plan_item_data + ) growth_plan_item_id = growth_plan_item.id growth_plan_item.delete() with self.assertRaises(GrowthPlanItem.DoesNotExist): diff --git a/src/one_on_one/tests/test_models.py b/src/one_on_one/tests/test_models.py index 724c07c..036c4b6 100644 --- a/src/one_on_one/tests/test_models.py +++ b/src/one_on_one/tests/test_models.py @@ -1,17 +1,22 @@ -#test models code yet to be inserted -from django.test import TestCase +# test models code yet to be inserted from django.contrib.auth import get_user_model +from django.test import TestCase from djf_surveys.models import Survey + from one_on_one.models import Link User = get_user_model() -class LinkTests(TestCase): +class LinkTests(TestCase): def setUp(self): # Create users for testing - self.mentor = User.objects.create_user(email='mentor@example.com', password='testpassword') - self.mentee = User.objects.create_user(email='mentee@example.com', password='testpassword') + self.mentor = User.objects.create_user( + email='mentor@example.com', password='testpassword' + ) + self.mentee = User.objects.create_user( + email='mentee@example.com', password='testpassword' + ) # Create surveys for testing self.mentor_survey = Survey.objects.create(name='Mentor Survey') diff --git a/src/projects/tests/test_models.py b/src/projects/tests/test_models.py index 1cec5c4..00c0a47 100644 --- a/src/projects/tests/test_models.py +++ b/src/projects/tests/test_models.py @@ -1,15 +1,20 @@ -from django.test import TestCase from django.contrib.auth import get_user_model +from django.test import TestCase + from projects.models import Project User = get_user_model() -class ProjectTests(TestCase): +class ProjectTests(TestCase): def setUp(self): # Create users for testing - self.user1 = User.objects.create_user(email='user1@example.com', password='testpassword') - self.user2 = User.objects.create_user(email='user2@example.com', password='testpassword') + self.user1 = User.objects.create_user( + email='user1@example.com', password='testpassword' + ) + self.user2 = User.objects.create_user( + email='user2@example.com', password='testpassword' + ) # Common data for test cases self.project_data = { @@ -49,4 +54,4 @@ def test_delete_project(self): project_id = project.id project.delete() with self.assertRaises(Project.DoesNotExist): - Project.objects.get(id=project_id) \ No newline at end of file + Project.objects.get(id=project_id) From 053971d947b1e0835d63f286cdbe671501e6e63e Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 2 Jul 2024 01:20:57 +0100 Subject: [PATCH 7/8] pre-commit hook issues resolved --- src/growth_forge/tests/test_models.py | 22 ++++++++++++--------- src/growth_forge/users/managers.py | 3 +-- src/growth_plan/tests/__init__.py | 1 - src/growth_plan/tests/test_models.py | 16 +++++++-------- src/one_on_one/tests/test_models.py | 24 ++++++++++++----------- src/projects/tests/test_models.py | 28 ++++++++++++++------------- 6 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/growth_forge/tests/test_models.py b/src/growth_forge/tests/test_models.py index 475b1ba..dc654ef 100644 --- a/src/growth_forge/tests/test_models.py +++ b/src/growth_forge/tests/test_models.py @@ -12,12 +12,12 @@ class ProfileTests(TestCase): def setUpClass(cls): # Create a user for testing cls.user = User.objects.create_user( - # username='testuser2', - password='testpassword2', + password='testpassword2', # noqa email='test@test.com', ) cls.user2 = User.objects.create_user( - email='testuser2@example.com', password='testpassword' + email='testuser2@example.com', + password='testpassword', # noqa ) @classmethod @@ -28,15 +28,19 @@ def tearDownClass(cls): cls.user2.delete() def test_create_profile(self): - # The Profile should be created automatically due to the post_save signal + """ + The Profile + should be created automatically + due to the post_save signal + """ profile = Profile.objects.get(user=self.user) - self.assertIsNotNone(profile) - self.assertEqual(profile.user.email, 'test@test.com') + assert profile is not None + assert profile.user.email == 'test@test.com' def test_retrieve_profile(self): profile = Profile.objects.get(user=self.user) retrieved_profile = Profile.objects.get(id=profile.id) - self.assertEqual(retrieved_profile.user.email, 'test@test.com') + assert retrieved_profile.user.email == 'test@test.com' def test_update_profile(self): profile, _ = Profile.objects.get_or_create(user=self.user) @@ -44,11 +48,11 @@ def test_update_profile(self): project = Project.objects.create(name='Test Project') profile.projects.add(project) # Verify the profile has the project added - self.assertIn(project, profile.projects.all()) + assert project in profile.projects.all() def test_delete_profile(self): profile = Profile.objects.get(user=self.user) profile_id = profile.id profile.delete() - with self.assertRaises(Profile.DoesNotExist): + with self.pytest.raises(Profile.DoesNotExist): Profile.objects.get(id=profile_id) diff --git a/src/growth_forge/users/managers.py b/src/growth_forge/users/managers.py index 6db5532..92047da 100644 --- a/src/growth_forge/users/managers.py +++ b/src/growth_forge/users/managers.py @@ -1,7 +1,7 @@ # type: ignore from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING from django.contrib.auth.hashers import make_password from django.contrib.auth.models import UserManager as DjangoUserManager @@ -17,7 +17,6 @@ def _create_user( self, email: str, password: str, - username: Optional[str] = None, **extra_fields, ) -> User: """ diff --git a/src/growth_plan/tests/__init__.py b/src/growth_plan/tests/__init__.py index ecadf74..e69de29 100644 --- a/src/growth_plan/tests/__init__.py +++ b/src/growth_plan/tests/__init__.py @@ -1 +0,0 @@ -from tests import * diff --git a/src/growth_plan/tests/test_models.py b/src/growth_plan/tests/test_models.py index c16aedb..8c45acb 100644 --- a/src/growth_plan/tests/test_models.py +++ b/src/growth_plan/tests/test_models.py @@ -15,13 +15,11 @@ class GrowthPlanItemTests(TestCase): def setUp(self): # Create a user for testing self.user = User.objects.create_user( - # username='testuser', - password='testpassword', + password='testpassword', # noqa email='test@test.com', ) self.client.login( - # username='testuser', - password='testpassword', + password='testpassword', # noqa email='test@test.com', ) @@ -39,15 +37,15 @@ def test_create_growth_plan_item(self): growth_plan_item = GrowthPlanItem.objects.create( **self.growth_plan_item_data ) - self.assertEqual(GrowthPlanItem.objects.count(), 1) - self.assertEqual(growth_plan_item.title, 'Test Growth Plan') + assert GrowthPlanItem.objects.count() == 1 + assert growth_plan_item.title == 'Test Growth Plan' def test_retrieve_growth_plan_item(self): growth_plan_item = GrowthPlanItem.objects.create( **self.growth_plan_item_data ) retrieved_item = GrowthPlanItem.objects.get(id=growth_plan_item.id) - self.assertEqual(retrieved_item.title, growth_plan_item.title) + assert retrieved_item.title == growth_plan_item.title def test_update_growth_plan_item(self): growth_plan_item = GrowthPlanItem.objects.create( @@ -56,7 +54,7 @@ def test_update_growth_plan_item(self): growth_plan_item.title = 'Updated Title' growth_plan_item.save() updated_item = GrowthPlanItem.objects.get(id=growth_plan_item.id) - self.assertEqual(updated_item.title, 'Updated Title') + assert updated_item.title == 'Updated Title' def test_delete_growth_plan_item(self): growth_plan_item = GrowthPlanItem.objects.create( @@ -64,5 +62,5 @@ def test_delete_growth_plan_item(self): ) growth_plan_item_id = growth_plan_item.id growth_plan_item.delete() - with self.assertRaises(GrowthPlanItem.DoesNotExist): + with self.pytest.raises(GrowthPlanItem.DoesNotExist): GrowthPlanItem.objects.get(id=growth_plan_item_id) diff --git a/src/one_on_one/tests/test_models.py b/src/one_on_one/tests/test_models.py index 036c4b6..344e4b9 100644 --- a/src/one_on_one/tests/test_models.py +++ b/src/one_on_one/tests/test_models.py @@ -12,10 +12,12 @@ class LinkTests(TestCase): def setUp(self): # Create users for testing self.mentor = User.objects.create_user( - email='mentor@example.com', password='testpassword' + email='mentor@example.com', + password='testpassword', # noqa ) self.mentee = User.objects.create_user( - email='mentee@example.com', password='testpassword' + email='mentee@example.com', + password='testpassword', # noqa ) # Create surveys for testing @@ -34,16 +36,16 @@ def setUp(self): def test_create_link(self): link = Link.objects.create(**self.link_data) - self.assertEqual(Link.objects.count(), 1) - self.assertEqual(link.mentor.email, 'mentor@example.com') - self.assertEqual(link.mentee.email, 'mentee@example.com') - self.assertEqual(link.periodicity, 'weekly') + assert Link.objects.count() == 1 + assert link.mentor.email == 'mentor@example.com' + assert link.mentee.email == 'mentee@example.com' + assert link.periodicity == 'weekly' def test_retrieve_link(self): link = Link.objects.create(**self.link_data) retrieved_link = Link.objects.get(id=link.id) - self.assertEqual(retrieved_link.mentor.email, 'mentor@example.com') - self.assertEqual(retrieved_link.mentee.email, 'mentee@example.com') + assert retrieved_link.mentor.email == 'mentor@example.com' + assert retrieved_link.mentee.email == 'mentee@example.com' def test_update_link(self): link = Link.objects.create(**self.link_data) @@ -51,12 +53,12 @@ def test_update_link(self): link.times = 10 link.save() updated_link = Link.objects.get(id=link.id) - self.assertEqual(updated_link.periodicity, 'monthly') - self.assertEqual(updated_link.times, 10) + assert updated_link.periodicity == 'monthly' + assert updated_link.times == 10 # noqa def test_delete_link(self): link = Link.objects.create(**self.link_data) link_id = link.id link.delete() - with self.assertRaises(Link.DoesNotExist): + with self.pytest.raises(Link.DoesNotExist): Link.objects.get(id=link_id) diff --git a/src/projects/tests/test_models.py b/src/projects/tests/test_models.py index 00c0a47..7f09d8e 100644 --- a/src/projects/tests/test_models.py +++ b/src/projects/tests/test_models.py @@ -10,10 +10,12 @@ class ProjectTests(TestCase): def setUp(self): # Create users for testing self.user1 = User.objects.create_user( - email='user1@example.com', password='testpassword' + email='user1@example.com', + password='testpassword', # noqa ) self.user2 = User.objects.create_user( - email='user2@example.com', password='testpassword' + email='user2@example.com', + password='testpassword', # noqa ) # Common data for test cases @@ -24,18 +26,18 @@ def setUp(self): def test_create_project(self): project = Project.objects.create(**self.project_data) project.observers.add(self.user1, self.user2) - self.assertEqual(Project.objects.count(), 1) - self.assertEqual(project.name, 'Test Project') - self.assertIn(self.user1, project.observers.all()) - self.assertIn(self.user2, project.observers.all()) + assert Project.objects.count() == 1 + assert project.name == 'Test Project' + assert self.user1 == project.observers.all() + assert self.user2 == project.observers.all() def test_retrieve_project(self): project = Project.objects.create(**self.project_data) project.observers.add(self.user1, self.user2) retrieved_project = Project.objects.get(id=project.id) - self.assertEqual(retrieved_project.name, 'Test Project') - self.assertIn(self.user1, retrieved_project.observers.all()) - self.assertIn(self.user2, retrieved_project.observers.all()) + assert retrieved_project.name == 'Test Project' + assert self.user1 in retrieved_project.observers.all() + assert self.user2 in retrieved_project.observers.all() def test_update_project(self): project = Project.objects.create(**self.project_data) @@ -45,13 +47,13 @@ def test_update_project(self): project.observers.add(self.user2) project.save() updated_project = Project.objects.get(id=project.id) - self.assertEqual(updated_project.name, 'Updated Project') - self.assertNotIn(self.user1, updated_project.observers.all()) - self.assertIn(self.user2, updated_project.observers.all()) + assert updated_project.name == 'Updated Project' + assert self.user1 == updated_project.observers.all() + assert self.user2 in updated_project.observers.all() def test_delete_project(self): project = Project.objects.create(**self.project_data) project_id = project.id project.delete() - with self.assertRaises(Project.DoesNotExist): + with self.pytest.raises(Project.DoesNotExist): Project.objects.get(id=project_id) From 9803f0ca82330ef8dfc2869e826c0a41991ac528 Mon Sep 17 00:00:00 2001 From: Bobby Date: Mon, 15 Jul 2024 16:05:18 +0100 Subject: [PATCH 8/8] changes to assert attribute --- src/growth_forge/tests/test_models.py | 6 ++++-- src/growth_plan/tests/test_models.py | 21 ++++++++++++++------- src/one_on_one/tests/test_models.py | 17 ++++++++++++----- src/projects/tests/test_models.py | 20 +++++++++++++------- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/growth_forge/tests/test_models.py b/src/growth_forge/tests/test_models.py index dc654ef..f65a7d9 100644 --- a/src/growth_forge/tests/test_models.py +++ b/src/growth_forge/tests/test_models.py @@ -54,5 +54,7 @@ def test_delete_profile(self): profile = Profile.objects.get(user=self.user) profile_id = profile.id profile.delete() - with self.pytest.raises(Profile.DoesNotExist): - Profile.objects.get(id=profile_id) + + # Check that the profile does not exist + profile_exists = Profile.objects.filter(id=profile_id).exists() + assert not profile_exists, "Profile still exists after deletion" diff --git a/src/growth_plan/tests/test_models.py b/src/growth_plan/tests/test_models.py index 8c45acb..c9fae62 100644 --- a/src/growth_plan/tests/test_models.py +++ b/src/growth_plan/tests/test_models.py @@ -57,10 +57,17 @@ def test_update_growth_plan_item(self): assert updated_item.title == 'Updated Title' def test_delete_growth_plan_item(self): - growth_plan_item = GrowthPlanItem.objects.create( - **self.growth_plan_item_data - ) - growth_plan_item_id = growth_plan_item.id - growth_plan_item.delete() - with self.pytest.raises(GrowthPlanItem.DoesNotExist): - GrowthPlanItem.objects.get(id=growth_plan_item_id) + growth_plan_item = GrowthPlanItem.objects.create( + **self.growth_plan_item_data + ) + growth_plan_item_id = growth_plan_item.id + growth_plan_item.delete() + + try: + GrowthPlanItem.objects.get(id=growth_plan_item_id) + item_exists = True + except GrowthPlanItem.DoesNotExist: + item_exists = False + + assert not item_exists, "GrowthPlanItem should not exist after deletion" + diff --git a/src/one_on_one/tests/test_models.py b/src/one_on_one/tests/test_models.py index 344e4b9..5fbe3b6 100644 --- a/src/one_on_one/tests/test_models.py +++ b/src/one_on_one/tests/test_models.py @@ -57,8 +57,15 @@ def test_update_link(self): assert updated_link.times == 10 # noqa def test_delete_link(self): - link = Link.objects.create(**self.link_data) - link_id = link.id - link.delete() - with self.pytest.raises(Link.DoesNotExist): - Link.objects.get(id=link_id) + link = Link.objects.create(**self.link_data) + link_id = link.id + link.delete() + + try: + Link.objects.get(id=link_id) + link_exists = True + except Link.DoesNotExist: + link_exists = False + + assert not link_exists, "Link should not exist after deletion" + diff --git a/src/projects/tests/test_models.py b/src/projects/tests/test_models.py index 7f09d8e..0f924d7 100644 --- a/src/projects/tests/test_models.py +++ b/src/projects/tests/test_models.py @@ -28,7 +28,7 @@ def test_create_project(self): project.observers.add(self.user1, self.user2) assert Project.objects.count() == 1 assert project.name == 'Test Project' - assert self.user1 == project.observers.all() + assert self.user1 in project.observers.all() assert self.user2 == project.observers.all() def test_retrieve_project(self): @@ -48,12 +48,18 @@ def test_update_project(self): project.save() updated_project = Project.objects.get(id=project.id) assert updated_project.name == 'Updated Project' - assert self.user1 == updated_project.observers.all() + assert self.user1 in updated_project.observers.all() assert self.user2 in updated_project.observers.all() def test_delete_project(self): - project = Project.objects.create(**self.project_data) - project_id = project.id - project.delete() - with self.pytest.raises(Project.DoesNotExist): - Project.objects.get(id=project_id) + project = Project.objects.create(**self.project_data) + project_id = project.id + project.delete() + + try: + Project.objects.get(id=project_id) + project_exists = True + except Project.DoesNotExist: + project_exists = False + + assert not project_exists, "Project should not exist after deletion"