-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
49 lines (39 loc) · 1.49 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from django.test import TestCase
from rest_framework import status
from django.contrib.auth.models import User
class LogInTest(TestCase):
def setUp(self):
self.credentials = {
'username': 'admin',
'password': 'unknown'}
User.objects.create_user(**self.credentials)
def test_login(self):
"""login"""
response = self.client.post('/api/login/', data=self.credentials)
self.assertEqual(response.status_code, status.HTTP_200_OK)
class RegisterInTest(TestCase):
def setUp(self):
self.user = {
'username': 'admin2',
'password': 'unknown@123',
'password_2': 'unknown@123',
'email': 'unknown2@gmail.com',
'first_name': 'unknown',
'last_name': 'unknown'
}
self.user_exist = {
'username': 'admin1',
'password': 'unknown@123',
'email': 'unknown1@gmail.com',
'first_name': 'unknown',
'last_name': 'unknown'
}
User.objects.create_user(**self.user_exist)
def test_register(self):
"""register"""
response = self.client.post('/api/register/', data=self.user)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_register_exist(self):
"""case: register a user that is exist"""
response = self.client.post('/api/register/', data=self.user_exist)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)