Fakultas Ilmu Komputer UI

Commit f597ab22 authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[RED] Add custom auth test for case insensitive auth

parent dd0932b4
Pipeline #47728 passed with stages
in 4 minutes and 48 seconds
from rest_framework import status
from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
class CustomAuthTest(APITestCase):
@classmethod
def setUpTestData(cls):
cls.URL = "/auth/token/"
user = User.objects.create(username="jonathan")
user.set_password("justpass")
user.save()
cls.user = user
def test_login_success_with_case_insensitive_username(self):
data = {
"username": "JoNaThAn",
"password": "justpass",
}
response = self.client.post(path=self.URL, data=data, format="json")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(Token.objects.filter(user=self.user).exists())
def test_login_success_with_exact_username(self):
data = {
"username": "jonathan",
"password": "justpass",
}
response = self.client.post(path=self.URL, data=data, format="json")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(Token.objects.filter(user=self.user).exists())
def test_login_fails_with_incomplete_credentials(self):
data = {
"username": "JoNaThAn",
}
response = self.client.post(path=self.URL, data=data, format="json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_login_fails_with_wrong_credentials(self):
data = {
"username": "jonathanjojo",
"password": "cantpass",
}
response = self.client.post(path=self.URL, data=data, format="json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment