From ad7f414ec81bc5891a5674dbb14373a40415765c Mon Sep 17 00:00:00 2001 From: Alex Oladele Date: Sun, 22 Sep 2024 17:09:54 -0400 Subject: [PATCH 1/4] Remove sleep fixture Playwright has a built-in "slowmo" feature that would be easiest to use. https://playwright.dev/python/docs/test-runners#cli-arguments --- tests/test.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/test.py b/tests/test.py index 819a3ec..61b0ee6 100644 --- a/tests/test.py +++ b/tests/test.py @@ -14,13 +14,6 @@ ] -# Add a delay to each test to help with playwright race conditions -@pytest.fixture(autouse=True) -def slow_down_tests(): - yield - time.sleep(1) - - @pytest.mark.parametrize("url", routes) def test_destination( page: Page, From d44ff4fd78b6920cd8d25498c39559d5bfca0b6e Mon Sep 17 00:00:00 2001 From: Alex Oladele Date: Sun, 22 Sep 2024 17:26:41 -0400 Subject: [PATCH 2/4] Use standard python comparison operator The `to_equal` doesn't seem to exist in playwright for python. There is a NodeJS equivalent, but there is no supported GenericAssertion equivalent for python https://playwright.dev/docs/api/class-genericassertions --- tests/test.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/test.py b/tests/test.py index 61b0ee6..fc237d3 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,5 +1,3 @@ -import time - import pytest from playwright.sync_api import Page, expect @@ -16,23 +14,23 @@ @pytest.mark.parametrize("url", routes) def test_destination( - page: Page, - url: str, + page: Page, + url: str, ) -> None: """Test that the destinations page loads with seeded data""" # Create a destination response = page.goto(f"{live_server_url}/{url}") - page.on("response", lambda response: expect(response.status).to_equal(200)) + assert response.status == 200 assert response.url.endswith(f"/{url}/") # Load the index.html @pytest.mark.parametrize( "title, url", ( - ("Acerca de", "/es/about/"), - ("Inicio", "/es/"), - ("Eventos", "/es/events/"), - ("Comunidad", "/es/community/"), + ("Acerca de", "/es/about/"), + ("Inicio", "/es/"), + ("Eventos", "/es/events/"), + ("Comunidad", "/es/community/"), ), ) def test_headers_in_language(page: Page, title: str, url: str) -> None: @@ -57,10 +55,10 @@ def test_switching_lang_es_about(page: Page) -> None: @pytest.mark.parametrize( "title, url", ( - ("Kutuhusu", "/sw/about/"), - ("Nyumbani", "/sw/"), - ("Matukio", "/sw/events/"), - ("Jumuiya", "/sw/community/"), + ("Kutuhusu", "/sw/about/"), + ("Nyumbani", "/sw/"), + ("Matukio", "/sw/events/"), + ("Jumuiya", "/sw/community/"), ), ) def test_headers_in_sw(page: Page, title: str, url: str) -> None: @@ -85,11 +83,11 @@ def test_switching_lang_sw_about(page: Page) -> None: @pytest.mark.parametrize( "title, url", ( - ("Black Python Devs | Home", "/"), - ("Black Python Devs | Blog", "/blog"), - ("Black Python Devs | About Us", "/about/"), - ("Black Python Devs | Events", "/events/"), - ("Black Python Devs | Community", "/community/"), + ("Black Python Devs | Home", "/"), + ("Black Python Devs | Blog", "/blog"), + ("Black Python Devs | About Us", "/about/"), + ("Black Python Devs | Events", "/events/"), + ("Black Python Devs | Community", "/community/"), ), ) def test_bpdevs_title_en(page: Page, title: str, url: str) -> None: From 3605f87306722900f0a12c678fd970f74a21d323 Mon Sep 17 00:00:00 2001 From: Alex Oladele Date: Sun, 22 Sep 2024 17:50:34 -0400 Subject: [PATCH 3/4] Add explanation to test assertion --- tests/test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test.py b/tests/test.py index fc237d3..9e102be 100644 --- a/tests/test.py +++ b/tests/test.py @@ -20,7 +20,8 @@ def test_destination( """Test that the destinations page loads with seeded data""" # Create a destination response = page.goto(f"{live_server_url}/{url}") - assert response.status == 200 + + assert response.status == 200 # Check that the page loaded successfully assert response.url.endswith(f"/{url}/") # Load the index.html From 90e624c1dcab68a1b748b65200f6d7c50c47a7b2 Mon Sep 17 00:00:00 2001 From: Alex Oladele Date: Sun, 22 Sep 2024 17:54:01 -0400 Subject: [PATCH 4/4] Fix linting issues --- tests/test.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/test.py b/tests/test.py index 9e102be..11509d2 100644 --- a/tests/test.py +++ b/tests/test.py @@ -14,8 +14,8 @@ @pytest.mark.parametrize("url", routes) def test_destination( - page: Page, - url: str, + page: Page, + url: str, ) -> None: """Test that the destinations page loads with seeded data""" # Create a destination @@ -28,10 +28,10 @@ def test_destination( @pytest.mark.parametrize( "title, url", ( - ("Acerca de", "/es/about/"), - ("Inicio", "/es/"), - ("Eventos", "/es/events/"), - ("Comunidad", "/es/community/"), + ("Acerca de", "/es/about/"), + ("Inicio", "/es/"), + ("Eventos", "/es/events/"), + ("Comunidad", "/es/community/"), ), ) def test_headers_in_language(page: Page, title: str, url: str) -> None: @@ -56,10 +56,10 @@ def test_switching_lang_es_about(page: Page) -> None: @pytest.mark.parametrize( "title, url", ( - ("Kutuhusu", "/sw/about/"), - ("Nyumbani", "/sw/"), - ("Matukio", "/sw/events/"), - ("Jumuiya", "/sw/community/"), + ("Kutuhusu", "/sw/about/"), + ("Nyumbani", "/sw/"), + ("Matukio", "/sw/events/"), + ("Jumuiya", "/sw/community/"), ), ) def test_headers_in_sw(page: Page, title: str, url: str) -> None: @@ -84,11 +84,11 @@ def test_switching_lang_sw_about(page: Page) -> None: @pytest.mark.parametrize( "title, url", ( - ("Black Python Devs | Home", "/"), - ("Black Python Devs | Blog", "/blog"), - ("Black Python Devs | About Us", "/about/"), - ("Black Python Devs | Events", "/events/"), - ("Black Python Devs | Community", "/community/"), + ("Black Python Devs | Home", "/"), + ("Black Python Devs | Blog", "/blog"), + ("Black Python Devs | About Us", "/about/"), + ("Black Python Devs | Events", "/events/"), + ("Black Python Devs | Community", "/community/"), ), ) def test_bpdevs_title_en(page: Page, title: str, url: str) -> None: