Fakultas Ilmu Komputer UI

Commit 76f57efb authored by Kefas Satrio Bangkit Solidedantyo's avatar Kefas Satrio Bangkit Solidedantyo
Browse files

Pbi 5 login

parent 9549a1f0
......@@ -176,3 +176,44 @@ class UserModelTests(APITestCase):
response = self.client.post('/auth/link-user-and-diet-profile/', data, format='json')
self.assertEqual(json.loads(response.content).get('message'), 'Diet profile is not found.')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_post_login_user_succeed(self):
data = {
'email': 'email@email.com',
'password': 'abc',
}
response = self.client.post('/auth/login/', data, format='json')
json_response = json.loads(response.content)
self.assertIn('access_token', json_response)
self.assertIn('refresh_token', json_response)
self.assertIn('user', json_response)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_post_login_user_failed_because_non_existing_email(self):
data = {
'email': 'email123123123@email.com',
'password': 'abc',
}
response = self.client.post('/auth/login/', data, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_post_login_user_failed_because_invalid_email_format(self):
data = {
'email': 'email123123123@email',
'password': 'abc',
}
response = self.client.post('/auth/login/', data, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_post_login_user_failed_because_invalid_password(self):
data = {
'email': 'email@email.com',
'password': 'abc1234',
}
response = self.client.post('/auth/login/', data, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
......@@ -8,6 +8,7 @@ router.register('auth/link-user-and-diet-profile', LinkUserAndDietProfileViewSet
urlpatterns = [
path('auth/registration/', include('dj_rest_auth.registration.urls')),
path('auth/', include('dj_rest_auth.urls')),
]
urlpatterns += router.urls
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