You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stacosys/tests/test_form.py

44 lines
1.1 KiB
Python

3 years ago
#!/usr/bin/python
# -*- coding: UTF-8 -*-
3 years ago
import logging
import pytest
from stacosys.db import database
from stacosys.interface import app
from stacosys.interface import form
3 years ago
@pytest.fixture
def client():
logger = logging.getLogger(__name__)
database.setup(":memory:")
3 years ago
logger.info(f"start interface {form}")
return app.test_client()
def test_new_comment_honeypot(client):
3 years ago
resp = client.post(
"/newcomment", content_type="multipart/form-data", data={"remarque": "trapped"}
)
assert resp.status == "400 BAD REQUEST"
3 years ago
def test_new_comment_success(client):
3 years ago
resp = client.post(
"/newcomment",
content_type="multipart/form-data",
data={"author": "Jack", "url": "/site3", "message": "comment 3"},
)
assert resp.status == "302 FOUND"
3 years ago
def test_check_form_data():
from stacosys.interface.form import check_form_data
3 years ago
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"}
)