Add test for empty bang behavior

Also fix pep8 issue
main
Ben Busby 2022-03-01 12:13:40 -07:00
parent 809520ec70
commit 69f845a047
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
2 changed files with 7 additions and 1 deletions

View File

@ -61,7 +61,8 @@ def resolve_bang(query: str, bangs_dict: dict, fallback: str) -> str:
continue continue
bang_query = query.replace( bang_query = query.replace(
operator if operator in split_query else operator[1:] + operator[0], '' operator if operator in split_query else operator[1:] +
operator[0], ''
).strip() ).strip()
if bang_query: if bang_query:

View File

@ -47,6 +47,11 @@ def test_ddg_bang(client):
assert rv._status_code == 302 assert rv._status_code == 302
assert rv.headers.get('Location').startswith('https://github.com') assert rv.headers.get('Location').startswith('https://github.com')
# Ensure bang without content doesn't redirect to the result
rv = client.get(f'/{Endpoint.search}?q=!gh')
assert rv._status_code == 302
assert not rv.headers.get('Location').startswith('https://github.com')
def test_config(client): def test_config(client):
rv = client.post(f'/{Endpoint.config}', data=demo_config) rv = client.post(f'/{Endpoint.config}', data=demo_config)