46a7d2571f
tests/ — 19 тестов: validators (телефон/имя/формат), database (услуги, FAQ, вакансии, отклики, админы, лиды, подписчики), интеграция (полный флоу заявки, карьера игрока, анти-флуд не роняет бота, доступ к админке). Работают на временной БД, реальную не трогают. Запуск: python -m pytest tests/ -q Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
59 lines
2.4 KiB
Python
59 lines
2.4 KiB
Python
def test_services_crud(tmp_db):
|
|
assert len(tmp_db.get_services()) >= 1 # сид
|
|
nid = tmp_db.add_service("X-услуга", "100 ₽", "описание")
|
|
assert nid in tmp_db.get_services()
|
|
tmp_db.update_service(nid, "price", "200 ₽")
|
|
assert tmp_db.get_services()[nid]["price"] == "200 ₽"
|
|
tmp_db.delete_service(nid)
|
|
assert nid not in tmp_db.get_services()
|
|
|
|
|
|
def test_custom_faq(tmp_db):
|
|
fid = tmp_db.add_custom_faq("привет", "Здравствуйте!")
|
|
assert tmp_db.match_custom_faq("ну привет всем") == "Здравствуйте!"
|
|
assert tmp_db.delete_custom_faq(fid)
|
|
assert tmp_db.match_custom_faq("привет") is None
|
|
|
|
|
|
def test_vacancy_options(tmp_db):
|
|
assert len(tmp_db.get_vacancy_options("player")) == 3
|
|
vid = tmp_db.add_vacancy_option("worker", "Аналитик")
|
|
assert any(l == "Аналитик" for _, l in tmp_db.get_vacancy_options("worker"))
|
|
tmp_db.delete_vacancy_option(vid)
|
|
assert not any(l == "Аналитик" for _, l in tmp_db.get_vacancy_options("worker"))
|
|
|
|
|
|
def test_applications_and_stats(tmp_db):
|
|
tmp_db.add_application(1, "player", {
|
|
"discipline": "CS2", "rank": "8", "role": "awp", "experience": "x", "contact": "@a"})
|
|
st = tmp_db.get_application_stats()
|
|
assert st["players"] == 1 and st["total"] == 1
|
|
rows = tmp_db.get_recent_applications()
|
|
assert tmp_db.set_application_status(rows[0]["id"], "принят")
|
|
|
|
|
|
def test_admins(tmp_db):
|
|
assert tmp_db.add_admin(555)
|
|
assert 555 in tmp_db.get_admins()
|
|
assert not tmp_db.add_admin(555) # дубль
|
|
assert tmp_db.remove_admin(555)
|
|
assert 555 not in tmp_db.get_admins()
|
|
|
|
|
|
def test_leads_and_vac_data(tmp_db):
|
|
tmp_db.add_lead(user_id=1, source="bot", name="A", phone="+79990001122",
|
|
service="CS2", call_time="завтра", promo=None, marketing=True)
|
|
s = tmp_db.get_lead_stats()
|
|
assert s["total"] == 1 and s["from_bot"] == 1 and s["marketing_yes"] == 1
|
|
tmp_db.set_vac_field(2, "discipline", "CS2")
|
|
assert tmp_db.get_vac_data(2)["discipline"] == "CS2"
|
|
tmp_db.clear_vac_data(2)
|
|
assert tmp_db.get_vac_data(2) == {}
|
|
|
|
|
|
def test_marketing_subscribers(tmp_db):
|
|
tmp_db.update_user_field(10, "consent_2", "Согласен")
|
|
tmp_db.update_user_field(11, "consent_2", "Не согласен")
|
|
subs = tmp_db.get_marketing_subscribers()
|
|
assert 10 in subs and 11 not in subs
|