Testing - Refactor HTTP Request Type test (#453)

pull/457/head
dgtlmoon 3 years ago committed by GitHub
parent 3cc6586695
commit 7ce9e4dfc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -77,14 +77,6 @@ def test_body_in_request(client, live_server):
# Add our URL to the import page # Add our URL to the import page
test_url = url_for('test_body', _external=True) test_url = url_for('test_body', _external=True)
# Add the test URL twice, we will check
res = client.post(
url_for("import_page"),
data={"urls": test_url},
follow_redirects=True
)
assert b"1 Imported" in res.data
res = client.post( res = client.post(
url_for("import_page"), url_for("import_page"),
data={"urls": test_url}, data={"urls": test_url},
@ -94,19 +86,6 @@ def test_body_in_request(client, live_server):
body_value = 'Test Body Value' body_value = 'Test Body Value'
# Attempt to add a body with a GET method
res = client.post(
url_for("edit_page", uuid="first"),
data={
"url": test_url,
"tag": "",
"method": "GET",
"fetch_backend": "html_requests",
"body": "invalid"},
follow_redirects=True
)
assert b"Body must be empty when Request Method is set to GET" in res.data
# Add a properly formatted body with a proper method # Add a properly formatted body with a proper method
res = client.post( res = client.post(
url_for("edit_page", uuid="first"), url_for("edit_page", uuid="first"),
@ -120,8 +99,7 @@ def test_body_in_request(client, live_server):
) )
assert b"Updated watch." in res.data assert b"Updated watch." in res.data
# Give the thread time to pick up the first version time.sleep(3)
time.sleep(5)
# The service should echo back the body # The service should echo back the body
res = client.get( res = client.get(
@ -129,9 +107,20 @@ def test_body_in_request(client, live_server):
follow_redirects=True follow_redirects=True
) )
# Check if body returned contains the specified data # If this gets stuck something is wrong, something should always be there
assert b"No history found" not in res.data
# We should see what we sent in the reply
assert str.encode(body_value) in res.data assert str.encode(body_value) in res.data
####### data sanity checks
# Add the test URL twice, we will check
res = client.post(
url_for("import_page"),
data={"urls": test_url},
follow_redirects=True
)
assert b"1 Imported" in res.data
watches_with_body = 0 watches_with_body = 0
with open('test-datastore/url-watches.json') as f: with open('test-datastore/url-watches.json') as f:
app_struct = json.load(f) app_struct = json.load(f)
@ -142,6 +131,20 @@ def test_body_in_request(client, live_server):
# Should be only one with body set # Should be only one with body set
assert watches_with_body==1 assert watches_with_body==1
# Attempt to add a body with a GET method
res = client.post(
url_for("edit_page", uuid="first"),
data={
"url": test_url,
"tag": "",
"method": "GET",
"fetch_backend": "html_requests",
"body": "invalid"},
follow_redirects=True
)
assert b"Body must be empty when Request Method is set to GET" in res.data
def test_method_in_request(client, live_server): def test_method_in_request(client, live_server):
# Add our URL to the import page # Add our URL to the import page
test_url = url_for('test_method', _external=True) test_url = url_for('test_method', _external=True)

Loading…
Cancel
Save