Добавление тестов
This commit is contained in:
Binary file not shown.
@@ -341,6 +341,14 @@ def api_auth(request):
|
|||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
|
if login is None:
|
||||||
|
errors.append({ "login": "Параметр обязателен для заполнения" })
|
||||||
|
if password is None:
|
||||||
|
errors.append({ "password": "Параметр обязателен для заполнения" })
|
||||||
|
|
||||||
|
if errors:
|
||||||
|
return JsonResponse({"code": 409, "errors": errors}, safe=False, status=409)
|
||||||
|
|
||||||
if len(login) < 6:
|
if len(login) < 6:
|
||||||
errors.append({ "login": "Имя пользователя должно быть длинее 6 символов" })
|
errors.append({ "login": "Имя пользователя должно быть длинее 6 символов" })
|
||||||
elif len(login) > 60:
|
elif len(login) > 60:
|
||||||
|
|||||||
@@ -17,18 +17,53 @@ headers = {
|
|||||||
'Cookie': f'csrftoken={csrftoken}'
|
'Cookie': f'csrftoken={csrftoken}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
# "lastname": "Qweqov",
|
||||||
|
# "firstname": "Petr",
|
||||||
|
# "middlename": "Qweyekovich",
|
||||||
|
# "username": "PetrQweqov",
|
||||||
|
# "password": "PetrQweqov@yandex.ru",
|
||||||
|
# "email": "PetrQweqov@yandex.ru",
|
||||||
|
# "phone": "89009401234",
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
|
||||||
|
print('Сценарий 1. Не указаны никакие данные:')
|
||||||
|
print(f'Код ответа: {response.status_code}')
|
||||||
|
# print(response.content)
|
||||||
|
print(f'Данные: {response.json()}')
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"lastname": "Qweqov",
|
"lastname": "Qweqov",
|
||||||
"firstname": "Petr",
|
"firstname": "Petr",
|
||||||
"middlename": "Qweyekovich",
|
"middlename": "Qweyekovich",
|
||||||
"username": "PetrQweqov",
|
"username": "PetrQweqov",
|
||||||
"password": "PetrQweqov@yandex.ru",
|
"password": "PetrQweqov@yandex.ru",
|
||||||
"email": "PetrQweqov@yandex.ru",
|
"email": "PetrQweqovyandex.ru",
|
||||||
"phone": "89009401234",
|
"phone": "8900940134",
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(url, headers=headers, data=data)
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
|
||||||
print(response.status_code)
|
print('Сценарий 2. Некорректная длина имени:')
|
||||||
print(response.content)
|
print(f'Код ответа: {response.status_code}')
|
||||||
print(response.json())
|
# print(response.content)
|
||||||
|
print(f'Данные: {response.json()}')
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"lastname": "Qweqov",
|
||||||
|
"firstname": "Petreeee",
|
||||||
|
"middlename": "Qweyekovich",
|
||||||
|
"username": "PetrQweqov",
|
||||||
|
"password": "PetrQweqov@yandex.ru",
|
||||||
|
"email": "PetrQweqov@yandex.ru",
|
||||||
|
"phone": "89009401134",
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
|
||||||
|
print('Сценарий 3. Успешная регистрация:')
|
||||||
|
print(f'Код ответа: {response.status_code}')
|
||||||
|
# print(response.content)
|
||||||
|
print(f'Данные: {response.json()}')
|
||||||
67
Tests/2_auth.py
Normal file
67
Tests/2_auth.py
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
token = ''
|
||||||
|
url_x_csrftoken = 'http://127.0.0.1:8000/api/get_xcsrf/'
|
||||||
|
|
||||||
|
response = requests.get(url_x_csrftoken)
|
||||||
|
x_csrftoken = response.json().get('X-CSRFToken')
|
||||||
|
|
||||||
|
cookies = response.cookies
|
||||||
|
cookies_dict = cookies.get_dict()
|
||||||
|
csrftoken = cookies_dict.get('csrftoken')
|
||||||
|
|
||||||
|
url = 'http://127.0.0.1:8000/api/auth/'
|
||||||
|
headers = {
|
||||||
|
'Authorization': f'Bearer {token}',
|
||||||
|
'X-CSRFToken': x_csrftoken,
|
||||||
|
'Cookie': f'csrftoken={csrftoken}'
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
|
||||||
|
print('Сценарий 1. Не указаны никакие данные:')
|
||||||
|
print(f'Код ответа: {response.status_code}')
|
||||||
|
# print(response.content)
|
||||||
|
print(f'Данные: {response.json()}')
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"login": "123",
|
||||||
|
"password": "123"
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
|
||||||
|
print('Сценарий 2. Ошибка длины данных:')
|
||||||
|
print(f'Код ответа: {response.status_code}')
|
||||||
|
# print(response.content)
|
||||||
|
print(f'Данные: {response.json()}')
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"login": "123123",
|
||||||
|
"password": "123123123"
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
|
||||||
|
print('Сценарий 3. Неверные данные:')
|
||||||
|
print(f'Код ответа: {response.status_code}')
|
||||||
|
# print(response.content)
|
||||||
|
print(f'Данные: {response.json()}')
|
||||||
|
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"login": "qweqweqwe",
|
||||||
|
"password": "qweqweqwe"
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
token = response.json().get('token')
|
||||||
|
|
||||||
|
print('Сценарий 4. Успешный вход:')
|
||||||
|
print(f'Код ответа: {response.status_code}')
|
||||||
|
# print(response.content)
|
||||||
|
print(f'Данные: {response.json()}')
|
||||||
|
print(f'Токен: {response.json().get('token')}')
|
||||||
Reference in New Issue
Block a user