mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
test cases for web admin article
This commit is contained in:
@ -1,5 +1,61 @@
|
||||
"""Test cases file of account"""
|
||||
"""Django import"""
|
||||
"""
|
||||
test cases file of account
|
||||
"""
|
||||
# django imports
|
||||
from django.test import TestCase
|
||||
from rest_framework.test import APIClient
|
||||
from rest_framework import status
|
||||
from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
|
||||
class UserLoginTestCase(TestCase):
|
||||
"""
|
||||
test cases for login
|
||||
"""
|
||||
def setUp(self):
|
||||
"""
|
||||
set up data
|
||||
:return:
|
||||
"""
|
||||
self.client = APIClient()
|
||||
self.user = User.objects.create_superuser(
|
||||
username='admin@example.com',
|
||||
email='admin@example.com',
|
||||
password='admin@1234'
|
||||
)
|
||||
|
||||
def test_admin_login_success(self):
|
||||
"""
|
||||
test admin login with valid credentials
|
||||
:return:
|
||||
"""
|
||||
url = reverse('account:admin-login')
|
||||
data = {
|
||||
'email': 'admin@example.com',
|
||||
'password': 'admin@1234',
|
||||
}
|
||||
response = self.client.post(url, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn('auth_token', response.data['data'])
|
||||
self.assertIn('refresh_token', response.data['data'])
|
||||
self.assertEqual(response.data['data']['username'], data['email'])
|
||||
|
||||
def test_admin_login_invalid_credentials(self):
|
||||
"""
|
||||
test admin login with invalid credentials
|
||||
:return:
|
||||
"""
|
||||
url = reverse('account:admin-login')
|
||||
data = {
|
||||
'email': 'admin@example.com',
|
||||
'password': 'admin@1235',
|
||||
}
|
||||
response = self.client.post(url, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertNotIn('auth_token', response.data)
|
||||
self.assertNotIn('refresh_token', response.data)
|
||||
|
||||
# Add more test cases as needed
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
Reference in New Issue
Block a user