Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/rating/QA104/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
from dotenv import load_dotenv
from pathlib import Path
import requests
import pytest
import json


load_dotenv(dotenv_path="C:/.env/.env")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

путь убери

# Загружает переменные из .env файла

# Теперь их можно использовать в тестах
LOGIN_RATING = os.getenv("LOGIN_RATING")
PASSWORD_RATING = os.getenv("PASSWORD_RATING")
BASE_URL = os.getenv("BASE_URL")

def get_token():
url = f"{BASE_URL}/auth/email/login"
data ={
"email": LOGIN_RATING,
"password": PASSWORD_RATING,
"scopes": [],
"session_name": "string"
}
post_response_token = requests.post(url, json=data)
post_response_token_status_code = post_response_token.status_code
post_response_token_json=post_response_token.json()
return post_response_token_json["token"]

API_TOKEN_USER_A = os.getenv("API_TOKEN_USER_A")
BASE_HEADERS = {
"Authorization": get_token()
}

HEADERS_USER_A = {
"Authorization": API_TOKEN_USER_A
}
LAST_TIMETABLE_ID = 10



#@pytest.fixture()
#def get_last_timetable_id():
"""getall_limit = 1
getall_ofset = 0
timetable_id_list=[]
get_response_all = requests.get(f"{BASE_URL}/lecturer?limit={getall_limit}&offset={getall_ofset}&order_by=mark_weighted&asc_order=false")
get_response_all_json = get_response_all.json()
while len(timetable_id_list) < get_response_all_json["total"]:
getall_ofset+=1
get_response_all = requests.get(f"{BASE_URL}/lecturer?limit={getall_limit}&offset={getall_ofset}&order_by=mark_weighted&asc_order=false")
get_response_all_json = get_response_all.json()
print(get_response_all_json["lecturers"][0]["timetable_id"])
timetable_id_list.append(get_response_all_json["lecturers"][0]["timetable_id"])
print(getall_ofset)
print(len(timetable_id_list))
print(getall_ofset)
sorted(timetable_id_list)"""
Comment on lines +42 to +58
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

комменты уберем

79 changes: 79 additions & 0 deletions tests/rating/QA104/test_comment_life_QA109.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import requests
import pytest
import json
from conftest import BASE_URL, BASE_HEADERS, HEADERS_USER_A

lecturer_id = 6799
text_filename = "text_example_3000_plus.txt"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а что за файл?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

текстовый файл на 3000+ символов для проверки ограничения

Copy link
Copy Markdown
Member

@Temmmmmo Temmmmmo Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно проще
питон умеет умножать строки

поэтому можно вот так:
big_3000_symbols_string = 3000 * 'a'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошо, спасибо

try:
with open(text_filename, "r", encoding="utf-8") as file:
text_3000_plus=file.read()
except FileNotFoundError:
print("файл не найден, создаю новый")
with open(text_filename, "w") as new_file:
new_file.write("base")
text_3000_plus = new_file.read()
if len(text_3000_plus)<=3000:
try:
with open(text_filename,"a", encoding="utf-8") as file:
while len(text_3000_plus)<=3000:
text_3000_plus+="hello"
file.write(text_3000_plus)
except IOError as e:
print(f"ошибка записи в файл: {e}")
exit()

@pytest.mark.parametrize("subject", ["physics", 909, "", text_3000_plus])
@pytest.mark.parametrize("text", ["nhfkkff", 999, "", text_3000_plus])
@pytest.mark.parametrize("mark_kindness", [0, 1, 2, -2, -1, 3, -3, "huhuhuh"])
@pytest.mark.parametrize("mark_clarity", [0, 1, 2, -2, -1, 3, -3, "huhuhuh"])
@pytest.mark.parametrize("mark_freebie", [0, 1, 2, -2, -1, 3, -3, "huhuhuh"])
@pytest.mark.parametrize("is_anonymous", [0, True, False, "True"])
@pytest.mark.parametrize("subject_patch", ["physics", 909, "", text_3000_plus])
@pytest.mark.parametrize("text_patch", ["nhfkkff", 999, "", text_3000_plus])
@pytest.mark.parametrize("mark_kindness_patch", [0, 1, 2, -2, -1, 3, -3, "huhuhuh"])
@pytest.mark.parametrize("mark_freebie_patch", [0, 1, 2, -2, -1, 3, -3, "huhuhuh"])
@pytest.mark.parametrize("mark_clarity_patch", [0, 1, 2, -2, -1, 3, -3, "huhuhuh"])
def test_comment_life_cicle(
subject, text, mark_kindness, mark_freebie,
mark_clarity, is_anonymous, subject_patch, text_patch,
mark_kindness_patch, mark_freebie_patch, mark_clarity_patch
):
url = f"{BASE_URL}/rating/comment?lecturer_id={lecturer_id}"
data = {
"subject": subject,
"text": text,
"create_ts": "2025-08-08T09:22:54.745Z",
"update_ts": "2025-08-08T09:22:54.745Z",
"mark_kindness": mark_kindness,
"mark_freebie": mark_freebie,
"mark_clarity": mark_clarity,
"is_anonymous": is_anonymous
}
expected_status_code = 200
response_post = requests.post(url, headers=BASE_HEADERS, json=data)
#assert response_post.status_code == expected_status_code
print(response_post.status_code)
response_post_json = response_post.json()
print(response_post_json["subject"])
print(response_post_json["text"])
print(response_post_json["mark_kindness"])
print(response_post_json["mark_freebie"])
print(response_post_json["mark_clarity"])
print(response_post_json["is_anonymous"])
if expected_status_code == 200:
response_get = requests.get(f"{url}/{response_post_json['uuid']}")
assert response_get.status_code == 200
"""data_patch = {
"subject": subject_patch,
"text": text_patch,
"mark_kindness": mark_kindness_patch,
"mark_freebie": mark_freebie_patch,
"mark_clarity": mark_clarity_patch
}
response_patch = requests.patch(f"{url}/{response_post_json['uuid']}",headers=BASE_HEADERS, json = data_patch)
assert response_patch.status_code==200"""
response_delete = requests.delete(f"{url}/{response_post_json['uuid']}",headers=BASE_HEADERS)
assert response_delete.status_code == 200
response_get = requests.get(f"{url}/{response_post_json['uuid']}")
assert response_get.status_code == 404
40 changes: 40 additions & 0 deletions tests/rating/QA104/test_lecturer_postQA104LOG.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import requests
import pytest
import json
from conftest import BASE_URL, BASE_HEADERS

timetable_idbase = 5896550


@pytest.mark.parametrize("first_name", ["", "Николай", 999, "string"])
@pytest.mark.parametrize("last_name", ["", "Николаев", 999, "string"])
@pytest.mark.parametrize("timetable_id", [timetable_idbase, "ag"])
def test_create_profile(first_name, last_name, timetable_id):
url = f"{BASE_URL}/rating/lecturer"
data = {
"first_name": first_name,
"last_name": last_name,
"middle_name": "Иванович",
"avatar_link": "",
"timetable_id": timetable_id
}
if type(first_name) == int or type(last_name) == int or type(timetable_id) == str : expected_status = 422
else: expected_status=200
response = requests.post(url, headers=BASE_HEADERS, json=data)
assert response.status_code == expected_status
response_json = response.json()


if expected_status == 200:
#проверка_поста
get_response = requests.get(f"{url}/{response_json['id']}")
assert get_response.status_code == 200
assert get_response.json()["first_name"] == data["first_name"]
assert get_response.json()["last_name"] == data["last_name"]
#удаление_поста
delete_response = requests.delete(f"{url}/{response_json['id']}", headers=BASE_HEADERS)
assert delete_response.status_code == 200
# проверка_удалённого_поста
get_deleted_response = requests.get(f"{url}/{response_json['id']}")
assert get_deleted_response.status_code == 404

58 changes: 58 additions & 0 deletions tests/rating/QA104/test_lecturer_post_QA104unlog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import requests
import pytest
from conftest import BASE_URL





@pytest.mark.parametrize("first_name, last_name, timetable_id, expected_status", [
("Николай", "Николаев", 100, 403),
("Николай", 999, 100, 403),
(999, "Николаев", 100, 403),
(999, 999, 100, 403),
("", "Николаев", 100, 403),
("Николай", "", 100, 403),
("", "", 100, 403),
(999, "", 100, 403),
("", 999, 100, 403),
("string", "Николаев", 100, 403),
("string", 999, 100, 403),
(999, "string", 100, 403),
("Николай", "string", 100, 403),
("string", "", 100, 403),
("", "string", 100, 403),
("string", "string", 100, 403),
("Николай", "Николаев", "ag", 403),
("Николай", 999, "ag", 403),
(999, "Николаев", "ag", 403),
(999, 999, "ag", 403),
("", "Николаев", "ag", 403),
("Николай", "", "ag", 403),
("", "", "ag", 403),
(999, "", "ag", 403),
("", 999, "ag", 403),
("string", "Николаев", "ag", 403),
("string", 999, "ag", 403),
(999, "string", "ag", 403),
("Николай", "string", "ag", 403),
("string", "", "ag", 403),
("", "string", "ag", 403),
("string", "string", "ag", 403)
])
def test_create_profile(first_name, last_name, timetable_id, expected_status):
url = f"{BASE_URL}/rating/lecturer"
data = {
"first_name":first_name,
"last_name":last_name,
"middle_name": "Иванович",
"avatar_link": "",
"timetable_id": 0
}

response = requests.post(url, json=data)
assert response.status_code == expected_status
response_json = response.json()