stacosys/tests/test_form.py

49 lines
1.3 KiB
Python
Raw Normal View History

2023-11-26 17:51:51 +01:00
#!/usr/bin/env python
2021-09-10 18:09:35 +02:00
# -*- coding: UTF-8 -*-
2021-07-17 11:42:04 +02:00
2021-09-10 18:09:35 +02:00
import logging
import pytest
from stacosys.db import database
2022-12-02 08:59:55 +01:00
from stacosys.interface import app, form
2024-04-12 21:35:15 +02:00
from stacosys.service.configuration import Config
from stacosys.service.mail import Mailer
from stacosys.service.rssfeed import Rss
2021-07-17 11:42:04 +02:00
2021-09-10 18:09:35 +02:00
@pytest.fixture
def client():
logger = logging.getLogger(__name__)
2022-12-01 20:35:48 +01:00
database.configure("sqlite:memory://db.sqlite")
2021-09-10 18:09:35 +02:00
logger.info(f"start interface {form}")
2024-04-12 21:36:11 +02:00
app.config["CONFIG"] = Config()
app.config["MAILER"] = Mailer()
app.config["RSS"] = Rss()
2021-09-10 18:09:35 +02:00
return app.test_client()
def test_new_comment_honeypot(client):
2022-04-26 20:51:42 +02:00
resp = client.post(
"/newcomment", content_type="multipart/form-data", data={"remarque": "trapped"}
)
assert resp.status == "400 BAD REQUEST"
2021-07-17 11:42:04 +02:00
2021-09-10 18:09:35 +02:00
def test_new_comment_success(client):
2022-04-26 20:51:42 +02:00
resp = client.post(
"/newcomment",
content_type="multipart/form-data",
data={"author": "Jack", "url": "/site3", "message": "comment 3"},
)
assert resp.status == "302 FOUND"
2021-07-17 11:42:04 +02:00
2021-09-10 18:09:35 +02:00
def test_check_form_data():
from stacosys.interface.form import check_form_data
2022-04-26 20:51:42 +02:00
assert check_form_data({"author": "Jack", "url": "/site3", "message": "comment 3"})
assert not check_form_data(
{"author": "Jack", "url": "/site3", "message": "comment 3", "extra": "ball"}
)