Files
stacosys/tests/test_form.py
T

44 lines
1.1 KiB
Python
Raw Normal View History

2021-09-10 18:09:35 +02:00
#!/usr/bin/python
# -*- 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
from stacosys.interface import app
2021-07-17 11:42:04 +02:00
from stacosys.interface import form
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}")
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"}
)