51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
|
import pytest
|
||
|
|
||
|
from ooze import exceptions
|
||
|
from ooze import sanitation
|
||
|
|
||
|
def test_string():
|
||
|
|
||
|
sanitizer = sanitation.STRING
|
||
|
|
||
|
assert sanitizer.sanitize('The quick brown fox jumps over the lazy dog') == 'The quick brown fox jumps over the lazy dog'
|
||
|
|
||
|
def test_integer():
|
||
|
|
||
|
sanitizer = sanitation.INTEGER
|
||
|
|
||
|
assert sanitizer.sanitize('23') == 23
|
||
|
|
||
|
with pytest.raises(exceptions.SanitationException):
|
||
|
sanitizer.sanitize('Fnord')
|
||
|
|
||
|
with pytest.raises(exceptions.SanitationException):
|
||
|
sanitizer.sanitize([])
|
||
|
|
||
|
def test_bool():
|
||
|
|
||
|
sanitizer = sanitation.BOOL
|
||
|
|
||
|
assert sanitizer.sanitize('true') == True
|
||
|
assert sanitizer.sanitize('True') == True
|
||
|
assert sanitizer.sanitize('TRUE') == True
|
||
|
assert sanitizer.sanitize('yes') == True
|
||
|
assert sanitizer.sanitize('Yes') == True
|
||
|
assert sanitizer.sanitize('YES') == True
|
||
|
assert sanitizer.sanitize('false') == False
|
||
|
assert sanitizer.sanitize('False') == False
|
||
|
assert sanitizer.sanitize('FALSE') == False
|
||
|
assert sanitizer.sanitize('no') == False
|
||
|
assert sanitizer.sanitize('No') == False
|
||
|
assert sanitizer.sanitize('NO') == False
|
||
|
assert sanitizer.sanitize('1') == True
|
||
|
assert sanitizer.sanitize('0') == False
|
||
|
|
||
|
with pytest.raises(exceptions.SanitationException):
|
||
|
sanitizer.sanitize('Fnord')
|
||
|
|
||
|
with pytest.raises(exceptions.SanitationException):
|
||
|
sanitizer.sanitize(23)
|
||
|
|
||
|
with pytest.raises(exceptions.SanitationException):
|
||
|
sanitizer.sanitize([])
|