From 86f983f6f5f388710c932f35514fbf03c0ddd348 Mon Sep 17 00:00:00 2001 From: shidron Date: Thu, 18 Jun 2026 09:17:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/__pycache__/views.cpython-314.pyc | Bin 17346 -> 17571 bytes Project/nn_project/api/views.py | 8 +++ Tests/1_user.py | 45 ++++++++++-- Tests/2_auth.py | 67 ++++++++++++++++++ 4 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 Tests/2_auth.py diff --git a/Project/nn_project/api/__pycache__/views.cpython-314.pyc b/Project/nn_project/api/__pycache__/views.cpython-314.pyc index 53b6eba6148f17ae2c20f3f0ab194b7b5a7dc13d..2379207757788251dcd94e6da549449a4532f4af 100644 GIT binary patch delta 393 zcmX@q&bYXfkx!eCmx}=i9&{UL6-RC4n`h1RjCpdrdO8PV${q#=83z5y=hXAL^%x3R z!kE%TfFhGG@QP37vlWvbTY}T9FITilSN|;a3z5V#a`oSP;m+cK6p?=>^-x=-~R5LC}WnJOPo-AV_F*(6XX7gEx YKt?8S#?A6hvluxw7^9hr#DPWv0RAdlj{pDw delta 324 zcmZ47$#|%pkx!eCmx}=iYGWi0th)5875T`z)2_r~91A{z+uQFJPJVbi(IvW8dpuh%O#mN_$ zg;|0)g19F?u+dcI3E~Z7(Ps)`3E~N2HD`wCR%VFdhp-qJg7|{?C!5*DG73zdVyDk7 z7{nAL1XeFN`JA0Jvv82e 60: diff --git a/Tests/1_user.py b/Tests/1_user.py index 4a60175..b9a65cc 100644 --- a/Tests/1_user.py +++ b/Tests/1_user.py @@ -17,18 +17,53 @@ headers = { '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": "PetrQweqov@yandex.ru", - "phone": "89009401234", + "email": "PetrQweqovyandex.ru", + "phone": "8900940134", } response = requests.post(url, headers=headers, data=data) -print(response.status_code) -print(response.content) -print(response.json()) \ No newline at end of file +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()}') \ No newline at end of file diff --git a/Tests/2_auth.py b/Tests/2_auth.py new file mode 100644 index 0000000..97b1ad8 --- /dev/null +++ b/Tests/2_auth.py @@ -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')}') \ No newline at end of file