From ef5adbf8c1a6354dc9ad2a31a2727dcf8bd377dc Mon Sep 17 00:00:00 2001 From: Rezaul Karim Shaon Date: Wed, 7 Aug 2024 18:19:38 +0600 Subject: [PATCH 1/4] test: backend --- backend/user_api/tests.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/backend/user_api/tests.py b/backend/user_api/tests.py index 39840ec..2571612 100644 --- a/backend/user_api/tests.py +++ b/backend/user_api/tests.py @@ -44,26 +44,31 @@ def test_superuser_creation(self): class UrlsTestCase(SimpleTestCase): def test_user_registration_url_resolves(self): url = reverse('user-registration') - self.assertEqual(resolve(url).func.view_class, - v1_views.UserRegistrationView) + self.assertEqual( + resolve(url).func.view_class, + v1_views.UserRegistrationView, + ) def test_user_login_url_resolves(self): url = reverse('user-login') - self.assertEqual(resolve(url).func.view_class, v1_views.UserLoginView) + self.assertEqual( + resolve(url).func.view_class, + v1_views.UserLoginView + ) class UserSerializerTestCase(TestCase): def setUp(self): self.user_attributes = { - 'email': 'testuser@example.com', - 'username': 'testuser', - 'name': 'Test User', + 'email': 'testuser1@example.com', + 'username': 'testuser1', + 'name': 'Test User1', 'password': 'testpassword123' } self.serializer_data = { - 'email': 'testuser@example.com', - 'username': 'testuser', - 'name': 'Test User', + 'email': 'testuser2@example.com', + 'username': 'testuser2', + 'name': 'Test User2', 'password': 'testpassword123' } self.user = User.objects.create(**self.user_attributes) From 30c8a53e196ace64f163d0497ade93716eddba99 Mon Sep 17 00:00:00 2001 From: Rezaul Karim Shaon Date: Wed, 7 Aug 2024 23:47:39 +0600 Subject: [PATCH 2/4] test: backend - user models test separated --- backend/user_api/tests/__init__.py | 0 backend/user_api/{ => tests}/tests.py | 31 ----------------------- backend/user_api/tests/tests_models.py | 35 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 backend/user_api/tests/__init__.py rename backend/user_api/{ => tests}/tests.py (62%) create mode 100644 backend/user_api/tests/tests_models.py diff --git a/backend/user_api/tests/__init__.py b/backend/user_api/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/user_api/tests.py b/backend/user_api/tests/tests.py similarity index 62% rename from backend/user_api/tests.py rename to backend/user_api/tests/tests.py index 2571612..8b432ee 100644 --- a/backend/user_api/tests.py +++ b/backend/user_api/tests/tests.py @@ -9,37 +9,6 @@ from user_api.views import v1 as v1_views -class UserModelTestCase(TestCase): - def setUp(self): - self.user = User.objects.create_user( - email='testuser@example.com', - username='testuser', - password='testpassword123', - name='Test User' - ) - - def test_user_creation(self): - self.assertEqual(self.user.email, 'testuser@example.com') - self.assertEqual(self.user.username, 'testuser') - self.assertTrue(self.user.check_password('testpassword123')) - self.assertEqual(self.user.name, 'Test User') - self.assertTrue(self.user.is_active) - self.assertFalse(self.user.is_staff) - self.assertFalse(self.user.is_superuser) - - def test_superuser_creation(self): - superuser = User.objects.create_superuser( - email='superuser@example.com', - username='superuser', - password='superpassword123' - ) - self.assertEqual(superuser.email, 'superuser@example.com') - self.assertEqual(superuser.username, 'superuser') - self.assertTrue(superuser.check_password('superpassword123')) - self.assertTrue(superuser.is_active) - self.assertTrue(superuser.is_staff) - self.assertTrue(superuser.is_superuser) - class UrlsTestCase(SimpleTestCase): def test_user_registration_url_resolves(self): diff --git a/backend/user_api/tests/tests_models.py b/backend/user_api/tests/tests_models.py new file mode 100644 index 0000000..6716079 --- /dev/null +++ b/backend/user_api/tests/tests_models.py @@ -0,0 +1,35 @@ +from django.test import TestCase + +from user_api.models import User + + +class UserModelTestCase(TestCase): + def setUp(self): + self.user = User.objects.create_user( + email='testuser@example.com', + username='testuser', + password='testpassword123', + name='Test User' + ) + + def test_user_creation(self): + self.assertEqual(self.user.email, 'testuser@example.com') + self.assertEqual(self.user.username, 'testuser') + self.assertTrue(self.user.check_password('testpassword123')) + self.assertEqual(self.user.name, 'Test User') + self.assertTrue(self.user.is_active) + self.assertFalse(self.user.is_staff) + self.assertFalse(self.user.is_superuser) + + def test_superuser_creation(self): + superuser = User.objects.create_superuser( + email='superuser@example.com', + username='superuser', + password='superpassword123' + ) + self.assertEqual(superuser.email, 'superuser@example.com') + self.assertEqual(superuser.username, 'superuser') + self.assertTrue(superuser.check_password('superpassword123')) + self.assertTrue(superuser.is_active) + self.assertTrue(superuser.is_staff) + self.assertTrue(superuser.is_superuser) From 889925067f01a57e6a96b463f9a0a267383cd971 Mon Sep 17 00:00:00 2001 From: Rezaul Karim Shaon Date: Wed, 7 Aug 2024 23:49:13 +0600 Subject: [PATCH 3/4] test: backend - user urls test separated --- backend/user_api/tests/tests.py | 21 --------------------- backend/user_api/tests/tests_urls.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 backend/user_api/tests/tests_urls.py diff --git a/backend/user_api/tests/tests.py b/backend/user_api/tests/tests.py index 8b432ee..ae9ee77 100644 --- a/backend/user_api/tests/tests.py +++ b/backend/user_api/tests/tests.py @@ -1,30 +1,9 @@ -from django.urls import resolve, reverse from django.test import TestCase -from django.test import SimpleTestCase from user_api.models import User from user_api.serializers import UserSerializer -from user_api.views import v1 as v1_views - - - -class UrlsTestCase(SimpleTestCase): - def test_user_registration_url_resolves(self): - url = reverse('user-registration') - self.assertEqual( - resolve(url).func.view_class, - v1_views.UserRegistrationView, - ) - - def test_user_login_url_resolves(self): - url = reverse('user-login') - self.assertEqual( - resolve(url).func.view_class, - v1_views.UserLoginView - ) - class UserSerializerTestCase(TestCase): def setUp(self): diff --git a/backend/user_api/tests/tests_urls.py b/backend/user_api/tests/tests_urls.py new file mode 100644 index 0000000..86e1b86 --- /dev/null +++ b/backend/user_api/tests/tests_urls.py @@ -0,0 +1,20 @@ +from django.test import SimpleTestCase +from django.urls import resolve, reverse + +from user_api.views import v1 as v1_views + + +class UrlsTestCase(SimpleTestCase): + def test_user_registration_url_resolves(self): + url = reverse('user-registration') + self.assertEqual( + resolve(url).func.view_class, + v1_views.UserRegistrationView, + ) + + def test_user_login_url_resolves(self): + url = reverse('user-login') + self.assertEqual( + resolve(url).func.view_class, + v1_views.UserLoginView + ) From 70152edd4426cf737642d01fd10b1866687326cd Mon Sep 17 00:00:00 2001 From: Rezaul Karim Shaon Date: Wed, 7 Aug 2024 23:50:18 +0600 Subject: [PATCH 4/4] test: backend - user serializers test separated --- backend/user_api/tests/{tests.py => tests_serializers.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename backend/user_api/tests/{tests.py => tests_serializers.py} (100%) diff --git a/backend/user_api/tests/tests.py b/backend/user_api/tests/tests_serializers.py similarity index 100% rename from backend/user_api/tests/tests.py rename to backend/user_api/tests/tests_serializers.py