mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 10:05:21 +00:00
added test cases for auth
This commit is contained in:
@ -19,7 +19,7 @@ User = get_user_model()
|
||||
|
||||
class AdminOTPTestCase(BaseSetUp):
|
||||
"""
|
||||
|
||||
test case to send otp to admin email
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
@ -28,36 +28,35 @@ class AdminOTPTestCase(BaseSetUp):
|
||||
:return:
|
||||
"""
|
||||
super(AdminOTPTestCase, self).setUp()
|
||||
self.url = reverse('web_admin:admin-otp')
|
||||
|
||||
def test_admin_otp_for_valid_email(self):
|
||||
"""
|
||||
|
||||
test admin otp for valid email
|
||||
:return:
|
||||
"""
|
||||
url = reverse('web_admin:admin-otp')
|
||||
data = {
|
||||
'email': 'admin@example.com'
|
||||
'email': self.admin_email
|
||||
}
|
||||
response = self.client.post(url, data, format='json')
|
||||
response = self.client.post(self.url, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(UserEmailOtp.objects.count(), 1)
|
||||
|
||||
def test_admin_otp_for_invalid_email(self):
|
||||
"""
|
||||
|
||||
test admin otp for invalid email
|
||||
:return:
|
||||
"""
|
||||
url = reverse('web_admin:admin-otp')
|
||||
data = {
|
||||
'email': 'notadmin@example.com'
|
||||
}
|
||||
response = self.client.post(url, data, format='json')
|
||||
response = self.client.post(self.url, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class AdminVerifyOTPTestCase(BaseSetUp):
|
||||
"""
|
||||
|
||||
test case to verify otp for admin email
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
@ -68,32 +67,94 @@ class AdminVerifyOTPTestCase(BaseSetUp):
|
||||
super(AdminVerifyOTPTestCase, self).setUp()
|
||||
self.verification_code = generate_otp()
|
||||
expiry = timezone.now() + timezone.timedelta(days=1)
|
||||
self.user_email_otp = UserEmailOtp.objects.create(email='admin@example.com',
|
||||
self.user_email_otp = UserEmailOtp.objects.create(email=self.admin_email,
|
||||
otp=self.verification_code,
|
||||
expired_at=expiry,
|
||||
user_type=dict(USER_TYPE).get('3'),
|
||||
)
|
||||
self.url = reverse('web_admin:admin-verify-otp')
|
||||
|
||||
def test_admin_verify_otp_with_valid_otp(self):
|
||||
url = reverse('web_admin:admin-verify-otp')
|
||||
"""
|
||||
test admin verify otp with valid otp
|
||||
:return:
|
||||
"""
|
||||
|
||||
data = {
|
||||
'email': 'admin@example.com',
|
||||
'email': self.admin_email,
|
||||
"otp": self.verification_code
|
||||
}
|
||||
|
||||
response = self.client.post(url, data)
|
||||
response = self.client.post(self.url, data)
|
||||
self.user_email_otp.refresh_from_db()
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(self.user_email_otp.is_verified, True)
|
||||
|
||||
def test_admin_verify_otp_with_invalid_otp(self):
|
||||
url = reverse('web_admin:admin-verify-otp')
|
||||
"""
|
||||
test admin verify otp with invalid otp
|
||||
:return:
|
||||
"""
|
||||
data = {
|
||||
'email': 'admin@example.com',
|
||||
'email': self.admin_email,
|
||||
"otp": generate_otp()
|
||||
}
|
||||
|
||||
response = self.client.post(url, data)
|
||||
response = self.client.post(self.url, data)
|
||||
self.user_email_otp.refresh_from_db()
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(self.user_email_otp.is_verified, False)
|
||||
|
||||
|
||||
class AdminCreateNewPassword(BaseSetUp):
|
||||
"""
|
||||
test case to create new password for admin email
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
inherit data here
|
||||
:return:
|
||||
"""
|
||||
super(AdminCreateNewPassword, self).setUp()
|
||||
self.verification_code = generate_otp()
|
||||
expiry = timezone.now() + timezone.timedelta(days=1)
|
||||
self.user_email_otp = UserEmailOtp.objects.create(email=self.admin_email,
|
||||
otp=self.verification_code,
|
||||
expired_at=expiry,
|
||||
user_type=dict(USER_TYPE).get('3'),
|
||||
)
|
||||
self.url = reverse('web_admin:admin-create-password')
|
||||
|
||||
def test_admin_create_new_password_after_verification(self):
|
||||
"""
|
||||
test admin create new password
|
||||
:return:
|
||||
"""
|
||||
self.user_email_otp.is_verified = True
|
||||
self.user_email_otp.save()
|
||||
|
||||
data = {
|
||||
'email': self.admin_email,
|
||||
"new_password": "New@1234",
|
||||
"confirm_password": "New@1234"
|
||||
}
|
||||
|
||||
response = self.client.post(self.url, data)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(UserEmailOtp.objects.count(), 0)
|
||||
|
||||
def test_admin_create_new_password_without_verification(self):
|
||||
"""
|
||||
test admin create new password
|
||||
:return:
|
||||
"""
|
||||
data = {
|
||||
'email': self.admin_email,
|
||||
"new_password": "Some@1234",
|
||||
"confirm_password": "Some@1234"
|
||||
}
|
||||
|
||||
response = self.client.post(self.url, data)
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(UserEmailOtp.objects.count(), 1)
|
||||
|
Reference in New Issue
Block a user