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

41 lines
1.2 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__)
db = database.Database()
db.setup(":memory:")
app.config.update(SITE_TOKEN="ETC")
logger.info(f"start interface {form}")
return app.test_client()
def test_new_comment_honeypot(client):
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):
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
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'})