From c0f89122c10af1f71f2547b661157b7625c7a085 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 29 May 2023 16:19:25 +0200 Subject: [PATCH] WIP --- .github/workflows/test-only.yml | 1 + changedetectionio/tests/test_request.py | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-only.yml b/.github/workflows/test-only.yml index e87e925a..1bcb5d2a 100644 --- a/.github/workflows/test-only.yml +++ b/.github/workflows/test-only.yml @@ -54,6 +54,7 @@ jobs: # 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 --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 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' diff --git a/changedetectionio/tests/test_request.py b/changedetectionio/tests/test_request.py index 06e518e1..2615659e 100644 --- a/changedetectionio/tests/test_request.py +++ b/changedetectionio/tests/test_request.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) # So we add our test here (was in a different file) def test_headers_in_request(client, live_server): + #live_server_setup(live_server) # Add our URL to the import page 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 res = client.post( @@ -30,7 +34,7 @@ def test_headers_in_request(client, live_server): ) 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;' @@ -40,7 +44,7 @@ def test_headers_in_request(client, live_server): data={ "url": test_url, "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}, 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 - time.sleep(5) + wait_for_all_checks(client) # The service should echo back the request headers res = client.get( @@ -64,7 +68,7 @@ def test_headers_in_request(client, live_server): from html import escape 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 watches_with_headers = 0 @@ -80,6 +84,9 @@ def test_headers_in_request(client, live_server): def test_body_in_request(client, live_server): # Add our URL to the import page 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( url_for("import_page"), @@ -168,6 +175,9 @@ def test_body_in_request(client, live_server): def test_method_in_request(client, live_server): # Add our URL to the import page 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 res = client.post( @@ -242,7 +252,11 @@ def test_headers_textfile_in_request(client, live_server): #live_server_setup(live_server) # Add our URL to the import page 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 res = client.post( url_for("import_page"), @@ -260,7 +274,7 @@ def test_headers_textfile_in_request(client, live_server): data={ "url": test_url, "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"}, follow_redirects=True )