69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
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/users/'
|
||
headers = {
|
||
'Authorization': f'Bearer {token}',
|
||
'X-CSRFToken': x_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 = {
|
||
"lastname": "Qweqov",
|
||
"firstname": "Petr",
|
||
"middlename": "Qweyekovich",
|
||
"username": "PetrQweqov",
|
||
"password": "PetrQweqov@yandex.ru",
|
||
"email": "PetrQweqovyandex.ru",
|
||
"phone": "8900940134",
|
||
}
|
||
|
||
response = requests.post(url, headers=headers, data=data)
|
||
|
||
print('Сценарий 2. Некорректная длина имени:')
|
||
print(f'Код ответа: {response.status_code}')
|
||
# 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()}') |