This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/test/test_text.py

30 lines
887 B
Python
Raw Normal View History

2019-11-12 16:09:47 +00:00
import pytest
from data.text import match_mysql, match_like
from data.database import Repository
from test.fixtures import *
@pytest.mark.parametrize('input', [
('hello world'),
('hello \' world'),
('hello " world'),
('hello ` world'),
])
def test_mysql_text_escaping(input):
query, values = Repository.select().where(match_mysql(Repository.description, input)).sql()
assert input not in query
@pytest.mark.parametrize('input, expected', [
('hello world', 'hello world'),
('hello \'world', 'hello world'),
('hello "world', 'hello world'),
('hello `world', 'hello world'),
('hello !world', 'hello !!world'),
('hello %world', 'hello !%world'),
])
def test_postgres_text_escaping(input, expected):
query, values = Repository.select().where(match_like(Repository.description, input)).sql()
assert input not in query
assert values[0] == '%' + expected + '%'