Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Added Unit testing for users app
Browse files Browse the repository at this point in the history
  • Loading branch information
M4ash committed May 24, 2024
1 parent 256fab2 commit 78cf5d1
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion users/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
from django.test import TestCase
from django.contrib.auth.models import User
from .models import Profile

# Create your tests here.
# Unit Testing

# The purpose of these unit tests is to ensure that the individual units of Users application
# are functioning correctly in isolation.


class UserAndProfileTestCase(TestCase):
def setUp(self):
# Create a user object
self.user = User.objects.create_user(
'testuser', 'test@example.com', 'testpassword')
# Create a profile object linked to the user
self.profile = Profile.objects.create(
user=self.user, address='123 Test St', avatar='users/default.jpg')

def test_user_creation(self):
"""Test the user creation process"""
user = User.objects.get(username='testuser')
self.assertIsNotNone(user)
self.assertEqual(user.email, 'test@example.com')

def test_user_profile(self):
"""Test the user's linked profile"""
user = User.objects.get(username='testuser')
self.assertEqual(user.profile.address, '123 Test St')

def test_profile_creation(self):
"""Test the profile creation process"""
self.assertEqual(self.profile.address, '123 Test St')
self.assertEqual(self.profile.avatar, 'users/default.jpg')

def test_profile_link_to_user(self):
"""Test the one-to-one link between User and Profile"""
self.assertEqual(self.profile.user, self.user)

0 comments on commit 78cf5d1

Please sign in to comment.