-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
113 lines (84 loc) · 4.22 KB
/
Copy pathtest_app.py
File metadata and controls
113 lines (84 loc) · 4.22 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""Смоук-тесты Планёрки: авторизация, создание встречи, проверка конфликтов."""
import pytest
import app as planerka
@pytest.fixture()
def client(tmp_path):
planerka.app.config.update(TESTING=True, DB_PATH=tmp_path / "test.db")
with planerka.app.test_client() as c:
yield c
def register(client, name, username, password="1234"):
return client.post(
"/register",
data={"name": name, "username": username, "password": password},
follow_redirects=True,
)
def login(client, username, password="1234"):
return client.post("/login", data={"username": username, "password": password})
def create(client, title, date, start, end, people=()):
return client.post(
"/meetings/new",
data={
"title": title,
"date": date,
"start": start,
"end": end,
"people": [str(p) for p in people],
},
)
def test_anonymous_redirected_to_login(client):
assert client.get("/day").status_code == 302
def test_register_login_and_duplicate_username(client):
assert "Планёрка" in register(client, "Иван Петров", "ivan").text
r = register(client, "Другой Иван", "ivan")
assert "уже занят" in r.text
def test_wrong_password(client):
register(client, "Иван Петров", "ivan")
r = login(client, "ivan", "wrong")
assert "Неверный логин или пароль" in r.text
def test_create_meeting_and_conflict(client):
register(client, "Иван Петров", "ivan") # id 1
register(client, "Мария Орлова", "maria") # id 2, залогинена как Мария
# Мария зовёт Ивана на 10:00–11:00
r = create(client, "Синк по релизу", "2026-07-08", "10:00", "11:00", people=[1])
assert r.status_code == 302
# встреча видна всем: Иван видит её в списке дня
login(client, "ivan")
day = client.get("/day?d=2026-07-08").text
assert "Синк по релизу" in day and "Мария Орлова" in day
# пересечение с занятым участником — отказ
r = create(client, "Планирование", "2026-07-08", "10:30", "11:30", people=[2])
assert "Слот занят" in r.text and "Мария Орлова" in r.text
assert "Планирование" not in client.get("/day?d=2026-07-08").text
# сам создатель тоже занят в 10:00–11:00 — отказ даже без других участников
r = create(client, "Соло-фокус", "2026-07-08", "10:00", "10:15")
assert "Слот занят" in r.text
# встык (11:00–12:00) — конфликта нет
r = create(client, "Ретро", "2026-07-08", "11:00", "12:00", people=[2])
assert r.status_code == 302
def test_validation(client):
register(client, "Иван Петров", "ivan")
assert (
"Окончание должно быть позже начала"
in create(client, "Встреча", "2026-07-08", "11:00", "10:00").text
)
assert "Укажите тему" in create(client, " ", "2026-07-08", "10:00", "11:00").text
assert (
"Проверьте дату и время"
in create(client, "Встреча", "мусор", "10:00", "11:00").text
)
def test_delete_only_by_creator(client):
register(client, "Иван Петров", "ivan")
register(client, "Мария Орлова", "maria")
create(client, "Синк", "2026-07-08", "10:00", "11:00", people=[1])
login(client, "ivan")
assert client.post("/meetings/1/delete").status_code == 403
login(client, "maria")
assert client.post("/meetings/1/delete").status_code == 302
assert "Синк" not in client.get("/day?d=2026-07-08").text
def test_stats_counts_participant_minutes(client):
register(client, "Иван Петров", "ivan")
register(client, "Мария Орлова", "maria")
create(client, "Синк", "2026-07-08", "10:00", "11:30", people=[1])
stats = client.get("/stats?d=2026-07-08").text
assert "1 ч 30 мин" in stats
assert "Иван Петров" in stats