headers-webdriver
dgtlmoon 2 years ago
parent ba8d2e0c2d
commit c0f89122c1

@ -54,6 +54,7 @@ jobs:
# Playwright/Browserless fetch # Playwright/Browserless fetch
docker run --rm -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/fetchers/test_content.py && pytest tests/test_errorhandling.py && pytest tests/visualselector/test_fetch_data.py' docker run --rm -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/fetchers/test_content.py && pytest tests/test_errorhandling.py && pytest tests/visualselector/test_fetch_data.py'
docker run --hostname cdio --rm -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/test_request.py'
# restock detection via playwright - added name=changedet here so that playwright/browserless can connect to it # restock detection via playwright - added name=changedet here so that playwright/browserless can connect to it
docker run --rm --name "changedet" -e "FLASK_SERVER_NAME=changedet" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest --live-server-port=5004 --live-server-host=0.0.0.0 tests/restock/test_restock.py' docker run --rm --name "changedet" -e "FLASK_SERVER_NAME=changedet" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest --live-server-port=5004 --live-server-host=0.0.0.0 tests/restock/test_restock.py'

@ -10,8 +10,12 @@ def test_setup(live_server):
# Hard to just add more live server URLs when one test is already running (I think) # Hard to just add more live server URLs when one test is already running (I think)
# So we add our test here (was in a different file) # So we add our test here (was in a different file)
def test_headers_in_request(client, live_server): def test_headers_in_request(client, live_server):
#live_server_setup(live_server)
# Add our URL to the import page # Add our URL to the import page
test_url = url_for('test_headers', _external=True) test_url = url_for('test_headers', _external=True)
if os.getenv('PLAYWRIGHT_DRIVER_URL'):
# Because its no longer calling back to localhost but from browserless, set in test-only.yml
test_url = test_url.replace('localhost', 'cdio')
# Add the test URL twice, we will check # Add the test URL twice, we will check
res = client.post( res = client.post(
@ -30,7 +34,7 @@ def test_headers_in_request(client, live_server):
) )
assert b"1 Imported" in res.data assert b"1 Imported" in res.data
time.sleep(3) wait_for_all_checks(client)
cookie_header = '_ga=GA1.2.1022228332; cookie-preferences=analytics:accepted;' cookie_header = '_ga=GA1.2.1022228332; cookie-preferences=analytics:accepted;'
@ -40,7 +44,7 @@ def test_headers_in_request(client, live_server):
data={ data={
"url": test_url, "url": test_url,
"tag": "", "tag": "",
"fetch_backend": "html_requests", "fetch_backend": 'html_webdriver' if os.getenv('PLAYWRIGHT_DRIVER_URL') else 'html_requests',
"headers": "xxx:ooo\ncool:yeah\r\ncookie:"+cookie_header}, "headers": "xxx:ooo\ncool:yeah\r\ncookie:"+cookie_header},
follow_redirects=True follow_redirects=True
) )
@ -48,7 +52,7 @@ def test_headers_in_request(client, live_server):
# Give the thread time to pick up the first version # Give the thread time to pick up the first version
time.sleep(5) wait_for_all_checks(client)
# The service should echo back the request headers # The service should echo back the request headers
res = client.get( res = client.get(
@ -64,7 +68,7 @@ def test_headers_in_request(client, live_server):
from html import escape from html import escape
assert escape(cookie_header).encode('utf-8') in res.data assert escape(cookie_header).encode('utf-8') in res.data
time.sleep(5) wait_for_all_checks(client)
# Re #137 - Examine the JSON index file, it should have only one set of headers entered # Re #137 - Examine the JSON index file, it should have only one set of headers entered
watches_with_headers = 0 watches_with_headers = 0
@ -80,6 +84,9 @@ def test_headers_in_request(client, live_server):
def test_body_in_request(client, live_server): 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)
if os.getenv('PLAYWRIGHT_DRIVER_URL'):
# Because its no longer calling back to localhost but from browserless, set in test-only.yml
test_url = test_url.replace('localhost', 'cdio')
res = client.post( res = client.post(
url_for("import_page"), url_for("import_page"),
@ -168,6 +175,9 @@ def test_body_in_request(client, live_server):
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)
if os.getenv('PLAYWRIGHT_DRIVER_URL'):
# Because its no longer calling back to localhost but from browserless, set in test-only.yml
test_url = test_url.replace('localhost', 'cdio')
# Add the test URL twice, we will check # Add the test URL twice, we will check
res = client.post( res = client.post(
@ -242,7 +252,11 @@ def test_headers_textfile_in_request(client, live_server):
#live_server_setup(live_server) #live_server_setup(live_server)
# Add our URL to the import page # Add our URL to the import page
test_url = url_for('test_headers', _external=True) test_url = url_for('test_headers', _external=True)
if os.getenv('PLAYWRIGHT_DRIVER_URL'):
# Because its no longer calling back to localhost but from browserless, set in test-only.yml
test_url = test_url.replace('localhost', 'cdio')
print ("TEST URL IS ",test_url)
# Add the test URL twice, we will check # Add the test URL twice, we will check
res = client.post( res = client.post(
url_for("import_page"), url_for("import_page"),
@ -260,7 +274,7 @@ def test_headers_textfile_in_request(client, live_server):
data={ data={
"url": test_url, "url": test_url,
"tag": "testtag", "tag": "testtag",
"fetch_backend": "html_requests", "fetch_backend": 'html_webdriver' if os.getenv('PLAYWRIGHT_DRIVER_URL') else 'html_requests',
"headers": "xxx:ooo\ncool:yeah\r\n"}, "headers": "xxx:ooo\ncool:yeah\r\n"},
follow_redirects=True follow_redirects=True
) )

Loading…
Cancel
Save