Skip to content

Commit

Permalink
models test successful.
Browse files Browse the repository at this point in the history
  • Loading branch information
investor-uyah committed Jun 25, 2024
1 parent a57e32a commit a65e1ab
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 43 deletions.
30 changes: 14 additions & 16 deletions src/growth_forge/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]'
# username='testuser2',
password='testpassword2',
email='[email protected]',
)
cls.user2 = User.objects.create_user(
email='[email protected]', password='testpassword'
)
cls.user2 = User.objects.create_user(email='[email protected]', 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,
'[email protected]'
)
self.assertIsNotNone(profile)
self.assertEqual(profile.user.email, '[email protected]')

def test_retrieve_profile(self):
profile = Profile.objects.get(user=self.user)
Expand All @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions src/growth_forge/users/managers.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/growth_plan/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from tests import *
from tests import *
36 changes: 23 additions & 13 deletions src/growth_plan/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]'
email='[email protected]',
)
self.client.login(
# username='testuser',
# username='testuser',
password='testpassword',
email='[email protected]'
email='[email protected]',
)

# Common data for test cases
Expand All @@ -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):
Expand Down
15 changes: 10 additions & 5 deletions src/one_on_one/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]', password='testpassword')
self.mentee = User.objects.create_user(email='[email protected]', password='testpassword')
self.mentor = User.objects.create_user(
email='[email protected]', password='testpassword'
)
self.mentee = User.objects.create_user(
email='[email protected]', password='testpassword'
)

# Create surveys for testing
self.mentor_survey = Survey.objects.create(name='Mentor Survey')
Expand Down
15 changes: 10 additions & 5 deletions src/projects/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]', password='testpassword')
self.user2 = User.objects.create_user(email='[email protected]', password='testpassword')
self.user1 = User.objects.create_user(
email='[email protected]', password='testpassword'
)
self.user2 = User.objects.create_user(
email='[email protected]', password='testpassword'
)

# Common data for test cases
self.project_data = {
Expand Down Expand Up @@ -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)
Project.objects.get(id=project_id)

0 comments on commit a65e1ab

Please sign in to comment.