Added more tests
This commit is contained in:
parent
4aaf2fa117
commit
2a9f7f5701
1 changed files with 79 additions and 2 deletions
|
|
@ -5,9 +5,63 @@ import pytest
|
|||
sys.path.insert(0, os.path.realpath(os.path.dirname(__file__))+'/../../')
|
||||
|
||||
#from settings import config
|
||||
from cuchulu.libraries.db.webmodel import WebModel
|
||||
from cuchulu.libraries.db.webmodel import WebModel, PhangoField, PrimaryKeyField
|
||||
from cuchulu.libraries.db import corefields
|
||||
|
||||
class TestPhangoField:
|
||||
def test_check_strips_and_escapes_basic_html_when_escape_false(self):
|
||||
|
||||
f=PhangoField("title")
|
||||
|
||||
out=f.check(' <b>"hola"</b> ')
|
||||
assert out=="<b>"hola"</b>"
|
||||
assert f.error==False
|
||||
assert f.txt_error==""
|
||||
|
||||
def test_check_does_not_escape_when_escape_true(self):
|
||||
|
||||
f = PhangoField("title")
|
||||
f.escape=True
|
||||
out = f.check(' <b>"hola"</b> ')
|
||||
assert out=='<b>"hola"</b>'
|
||||
assert f.error==False
|
||||
assert f.txt_error==""
|
||||
|
||||
def test_check_blank_sets_error_and_default_message(self):
|
||||
|
||||
f=PhangoField("title")
|
||||
out=f.check(" ")
|
||||
assert out==""
|
||||
assert f.error==True
|
||||
assert f.txt_error==f.error_default
|
||||
|
||||
|
||||
class TestPrimaryKeyField:
|
||||
|
||||
def test_check_empty_becomes_zero_and_errors(self):
|
||||
|
||||
pk=PrimaryKeyField("id")
|
||||
out=pk.check("")
|
||||
|
||||
assert out=="0"
|
||||
assert pk.error==True
|
||||
assert pk.txt_error==pk.error_default
|
||||
|
||||
def test_check_non_int_becomes_zero_and_errors(self):
|
||||
|
||||
pk=PrimaryKeyField("id")
|
||||
out=pk.check("abc")
|
||||
|
||||
assert out=="0"
|
||||
assert pk.error==True
|
||||
assert pk.txt_error==pk.error_default
|
||||
|
||||
def test_check_valid_int_is_string_and_no_error(self):
|
||||
pk=PrimaryKeyField("id")
|
||||
out=pk.check("5")
|
||||
assert out=="5"
|
||||
|
||||
assert pk.error==False
|
||||
|
||||
class ExampleModel(WebModel):
|
||||
|
||||
|
|
@ -313,7 +367,30 @@ def test_test_check_connections(webmodel_conn):
|
|||
assert model.drop()
|
||||
assert model2.drop()
|
||||
|
||||
print('last_test')
|
||||
|
||||
def test_check_in_list_converts_to_int_strings():
|
||||
|
||||
out=WebModel.check_in_list([1, "2", "003"])
|
||||
|
||||
assert out=="(1, 2, 3)"
|
||||
|
||||
def test_check_in_list_invalid_becomes_zero():
|
||||
|
||||
out=WebModel.check_in_list(["x", None, 7])
|
||||
|
||||
assert out=="(0, 0, 7)"
|
||||
|
||||
def test_check_in_list_str_uses_field_check(webmodel_conn):
|
||||
|
||||
connection=webmodel_conn
|
||||
|
||||
model=ExampleModel(connection)
|
||||
|
||||
model.register(PhangoField("name"))
|
||||
|
||||
out=model.check_in_list_str("name", [' <a> ', ' "x" '])
|
||||
|
||||
assert out=='("<a>", ""x"")'
|
||||
|
||||
@pytest.mark.skip
|
||||
def prepare_table(model):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue