From a5d4ae40345cc4312d1d3ae0f0be51ded3cf4b21 Mon Sep 17 00:00:00 2001 From: Aayush Badoni Date: Thu, 7 Mar 2024 18:57:40 +0530 Subject: [PATCH 1/4] added e2e test for broken reddit activity in TWP45 --- tests/test_TWP45.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_TWP45.py b/tests/test_TWP45.py index b6e8fd0474..a809df5b6a 100644 --- a/tests/test_TWP45.py +++ b/tests/test_TWP45.py @@ -18,7 +18,34 @@ def test_l45_1(page): # Test the src attribute from image matches the Facebook URL assert img_src == "https://graph.facebook.com/ACDC/picture?type=large" +@pytest.mark.vcr() +def test_reddit_activity(page): + # Go to TWP45_2 page + page.goto("lectures/TWP45/TWP45_2.html") + + # Run the exercise + page.click("#ac_l45_2 >> *css=button >> text=Save & Run") + + # Wait for the output iframe to load + page.wait_for_load_state("networkidle") + + # Select the output iframe + iframe = page.query_selector( + '//*[@id="ac_l45_2"]/div/div[5]/iframe').content_frame() + + # Get the Reddit titles and number of comments + titles = iframe.query_selector_all(".reddit-title") + num_comments = iframe.query_selector_all(".reddit-comments") + + # Check if there are any visible Reddit titles and number of comments + assert len(titles) > 0, "No Reddit titles found. CORS issue detected." + assert len(num_comments) > 0, "No number of comments found. CORS issue detected." + + # Check for any JavaScript errors in the console + console_errors = page.evaluate("() => window.errors") + assert not console_errors, f"JavaScript errors found: {console_errors}" + @pytest.mark.vcr() def test_l45_3(page): # Go to TWP45 page From b1affee112e1896553e0161effd2fc9324ca6640 Mon Sep 17 00:00:00 2001 From: Aayush Badoni Date: Thu, 7 Mar 2024 22:35:17 +0530 Subject: [PATCH 2/4] fixed broken reddit exercise due to cors --- _sources/lectures/TWP45/TWP45_2.rst | 2 +- _sources/lectures/TWP45/TWP45_2_en.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_sources/lectures/TWP45/TWP45_2.rst b/_sources/lectures/TWP45/TWP45_2.rst index f06701a342..d9b99bc945 100644 --- a/_sources/lectures/TWP45/TWP45_2.rst +++ b/_sources/lectures/TWP45/TWP45_2.rst @@ -17,7 +17,7 @@ En este ejercicio vamos a acceder a Reddit para obetener datos como los de la si import json # La url de Reddit a la que accederemos - url = "https://cors.bridged.cc/http://www.reddit.com/r/Python/.json" + url = "https://api.reddit.com/r/Python/.json" resp = urllib.request.urlopen(url).read() # La respuesta se da en formato json, se debe transformar a diff --git a/_sources/lectures/TWP45/TWP45_2_en.rst b/_sources/lectures/TWP45/TWP45_2_en.rst index ce13cce510..c44099b934 100644 --- a/_sources/lectures/TWP45/TWP45_2_en.rst +++ b/_sources/lectures/TWP45/TWP45_2_en.rst @@ -17,7 +17,7 @@ In this exercise we are going to access Reddit to obtain data like the one in th import json # The Reddit URL we'll access - url = "https://cors.bridged.cc/http://www.reddit.com/r/Python/.json" + url = "https://api.reddit.com/r/Python/.json" resp = urllib.request.urlopen(url).read() # The response is in JSON format, it needs to be transformed From c0a7ce7a048fb8ca50ffdb104260fa420f3fe6d1 Mon Sep 17 00:00:00 2001 From: Aayush Badoni Date: Thu, 7 Mar 2024 22:47:15 +0530 Subject: [PATCH 3/4] fixed overlapping edits --- requirements.txt | 2 +- tests/test_TWP45.py | 28 ---------------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/requirements.txt b/requirements.txt index bc0e67c4ae..9310bc4c75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ git+https://github.com/PyAr/RunestoneComponents.git@master#runestone pytest==6.2.4 -playwright==1.13.1 +playwright==1.11.2 pytest-playwright==0.1.1 pytest-html==3.1.1 pytest-vcr==1.0.2 diff --git a/tests/test_TWP45.py b/tests/test_TWP45.py index a809df5b6a..ddb19d797e 100644 --- a/tests/test_TWP45.py +++ b/tests/test_TWP45.py @@ -17,34 +17,6 @@ def test_l45_1(page): # Test the src attribute from image matches the Facebook URL assert img_src == "https://graph.facebook.com/ACDC/picture?type=large" - -@pytest.mark.vcr() -def test_reddit_activity(page): - # Go to TWP45_2 page - page.goto("lectures/TWP45/TWP45_2.html") - - # Run the exercise - page.click("#ac_l45_2 >> *css=button >> text=Save & Run") - - # Wait for the output iframe to load - page.wait_for_load_state("networkidle") - - # Select the output iframe - iframe = page.query_selector( - '//*[@id="ac_l45_2"]/div/div[5]/iframe').content_frame() - - # Get the Reddit titles and number of comments - titles = iframe.query_selector_all(".reddit-title") - num_comments = iframe.query_selector_all(".reddit-comments") - - # Check if there are any visible Reddit titles and number of comments - assert len(titles) > 0, "No Reddit titles found. CORS issue detected." - assert len(num_comments) > 0, "No number of comments found. CORS issue detected." - - # Check for any JavaScript errors in the console - console_errors = page.evaluate("() => window.errors") - assert not console_errors, f"JavaScript errors found: {console_errors}" - @pytest.mark.vcr() def test_l45_3(page): From 78888b8b751489d6a3db67d7dabef462975fbd5d Mon Sep 17 00:00:00 2001 From: Aayush Badoni Date: Fri, 8 Mar 2024 15:59:45 +0530 Subject: [PATCH 4/4] fixed possible merge conflicts --- tests/test_TWP45.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_TWP45.py b/tests/test_TWP45.py index ddb19d797e..2f0a8ed1f0 100644 --- a/tests/test_TWP45.py +++ b/tests/test_TWP45.py @@ -17,7 +17,8 @@ def test_l45_1(page): # Test the src attribute from image matches the Facebook URL assert img_src == "https://graph.facebook.com/ACDC/picture?type=large" - + + @pytest.mark.vcr() def test_l45_3(page): # Go to TWP45 page