unit test form
This commit is contained in:
parent
cd24661ed0
commit
86702625a0
1 changed files with 34 additions and 16 deletions
|
@ -1,22 +1,40 @@
|
||||||
import unittest
|
#!/usr/bin/python
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from stacosys.db import database
|
||||||
|
from stacosys.interface import app
|
||||||
from stacosys.interface import form
|
from stacosys.interface import form
|
||||||
|
|
||||||
|
|
||||||
class FormInterfaceTestCase(unittest.TestCase):
|
@pytest.fixture
|
||||||
|
def client():
|
||||||
def test_check_form_data_ok(self):
|
logger = logging.getLogger(__name__)
|
||||||
d = {"url": "/", "message": "", "site": "", "remarque": "", "author": "", "token": "", "email": ""}
|
db = database.Database()
|
||||||
self.assertTrue(form.check_form_data(d))
|
db.setup(":memory:")
|
||||||
d = {"url": "/"}
|
app.config.update(SITE_TOKEN="ETC")
|
||||||
self.assertTrue(form.check_form_data(d))
|
logger.info(f"start interface {form}")
|
||||||
d = {}
|
return app.test_client()
|
||||||
self.assertTrue(form.check_form_data(d))
|
|
||||||
|
|
||||||
def test_check_form_data_ko(self):
|
|
||||||
d = {"url": "/", "message": "", "site": "", "remarque": "", "author": "", "token": "", "email": "", "bonus": ""}
|
|
||||||
self.assertFalse(form.check_form_data(d))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def test_new_comment_honeypot(client):
|
||||||
unittest.main()
|
resp = client.post('/newcomment',
|
||||||
|
content_type='multipart/form-data',
|
||||||
|
data={'remarque': 'trapped'})
|
||||||
|
assert resp.status == '400 BAD REQUEST'
|
||||||
|
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
|
||||||
|
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'})
|
||||||
|
|
Loading…
Add table
Reference in a new issue