39 lines
980 B
Python
39 lines
980 B
Python
from librefi.utils import regex_search_string
|
|
|
|
HTML_STRING = """
|
|
<form method="POST" action="/?your=mother">
|
|
<input type="hidden" value="tesco" />
|
|
</form>
|
|
"""
|
|
|
|
PATTERN = r'<form [^>]+action="([^"]+)'
|
|
|
|
EXPECTED_RESULT = "/?your=mother"
|
|
|
|
|
|
def test_regex_search_single():
|
|
result = regex_search_string(PATTERN, HTML_STRING)
|
|
assert result is not None
|
|
assert result == EXPECTED_RESULT
|
|
|
|
|
|
def test_regex_search_multiple():
|
|
result = regex_search_string(
|
|
[r'dupsko', PATTERN, r'byle jakie'], HTML_STRING)
|
|
assert result is not None
|
|
assert result == EXPECTED_RESULT
|
|
|
|
|
|
def test_regex_search_invalid():
|
|
result = regex_search_string([r'dupsko', r'czorne'], HTML_STRING)
|
|
assert result is None
|
|
assert result != EXPECTED_RESULT
|
|
|
|
|
|
def test_regex_search_default():
|
|
default = "sth"
|
|
result = regex_search_string(
|
|
[r'dupsko', r'czorne'], HTML_STRING, default=default)
|
|
assert result is not None
|
|
assert result == default
|