Skip to content

Commit

Permalink
Update search tests to only perform GET requests
Browse files Browse the repository at this point in the history
Since POST requests are now redirected to GET requests (with an
encrypted query string), POST searches are no longer the correct
approach to use for testing purposes.
  • Loading branch information
benbusby committed Oct 16, 2023
1 parent 2950aa8 commit cdf0b50
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,11 @@ def test_get_results(client):

def test_post_results(client):
rv = client.post(f'/{Endpoint.search}', data=dict(q='test'))
assert rv._status_code == 200

# Depending on the search, there can be more
# than 10 result divs
results = get_search_results(rv.data)
assert len(results) >= 10
assert len(results) <= 15
assert rv._status_code == 302


def test_translate_search(client):
rv = client.post(f'/{Endpoint.search}', data=dict(q='translate hola'))
rv = client.get(f'/{Endpoint.search}?q=translate hola')
assert rv._status_code == 200

# Pretty weak test, but better than nothing
Expand All @@ -64,7 +58,7 @@ def test_translate_search(client):


def test_block_results(client):
rv = client.post(f'/{Endpoint.search}', data=dict(q='pinterest'))
rv = client.get(f'/{Endpoint.search}?q=pinterest')
assert rv._status_code == 200

has_pinterest = False
Expand All @@ -79,7 +73,7 @@ def test_block_results(client):
rv = client.post(f'/{Endpoint.config}', data=demo_config)
assert rv._status_code == 302

rv = client.post(f'/{Endpoint.search}', data=dict(q='pinterest'))
rv = client.get(f'/{Endpoint.search}?q=pinterest')
assert rv._status_code == 200

for link in BeautifulSoup(rv.data, 'html.parser').find_all('a', href=True):
Expand All @@ -90,7 +84,7 @@ def test_block_results(client):


def test_view_my_ip(client):
rv = client.post(f'/{Endpoint.search}', data=dict(q='my ip address'))
rv = client.get(f'/{Endpoint.search}?q=my ip address')
assert rv._status_code == 200

# Pretty weak test, but better than nothing
Expand All @@ -107,7 +101,7 @@ def test_recent_results(client):
}

for time, num_days in times.items():
rv = client.post(f'/{Endpoint.search}', data=dict(q='test :' + time))
rv = client.get(f'/{Endpoint.search}?q=test :' + time)
result_divs = get_search_results(rv.data)

current_date = datetime.now()
Expand Down

0 comments on commit cdf0b50

Please sign in to comment.