From 787937ddae127870cbb61e78c534e0909bea49e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleksis=20Fraga=20Men=C3=A9ndez?= Date: Thu, 5 Oct 2023 15:12:34 -0400 Subject: [PATCH 1/7] Using Python with Playwright adding black for formatting Add pytest.ini Add requirements-dev.txt --- .gitattributes | 18 ++++++++++-------- .github/workflows/playwright.yml | 9 ++++++--- .gitignore | 2 +- .pre-commit-config.yaml | 4 ++++ _config.yml | 2 ++ pytest.ini | 2 ++ requirements-dev.txt | 3 +++ tests/test.py | 13 ++++++++----- 8 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 pytest.ini create mode 100644 requirements-dev.txt diff --git a/.gitattributes b/.gitattributes index e81c44d..8de86f8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,16 +1,18 @@ * text=auto -* .md text -* .html text -* .css text -* .js text -* .yml text -* .xml text +* .md text eol=lf +* .html text eol=lf +* .css text eol=lf +* .js text eol=lf +* .yml text eol=lf +* .xml text eol=lf -* .bat eol=crlf +* .bat text eol=crlf -* .sh eol=lf +* .sh text eol=lf * .png binary * .jpg binary * .gif binary + +_site/* -text -diff -merge diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 8e25401..1cb694e 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,9 +1,12 @@ name: Playwright Tests +# https://devblogs.microsoft.com/python/announcing-playwright-for-python-reliable-end-to-end-testing-for-the-web/ +# https://github.com/marketplace/actions/run-playwright-tests on: push: branches: - gh-pages + workflow_dispatch: jobs: test: @@ -17,10 +20,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install playwright pytest pytest-playwright + pip install -r requirements-dev.txt python -m playwright install --with-deps - - name: Sleep for 30 seconds + - name: Sleep for 45 seconds run: sleep 45s shell: bash - name: Run tests - run: python -m pytest + run: python -m pytest -v diff --git a/.gitignore b/.gitignore index 29ebeb7..19561ff 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ _site venv .venv .jekyll-metadata -*/__pycache__ +**/__pycache__ .pytest_cache diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 14bfd45..70a6f43 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,7 @@ repos: hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] + - repo: https://github.com/psf/black + rev: 23.9.1 + hooks: + - id: black diff --git a/_config.yml b/_config.yml index f115e5f..3e3ca22 100644 --- a/_config.yml +++ b/_config.yml @@ -63,6 +63,8 @@ exclude: - vendor - venv - .venv + - requirements*.txt + - pytest.ini # timezone: America/Toronto permalink: "/:path/" diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..7c47955 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +python_files = *.py diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..f2c92ba --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +black +pre-commit +pytest-playwright diff --git a/tests/test.py b/tests/test.py index f34455f..ba6c322 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,4 +1,3 @@ - import pytest from playwright.sync_api import Page, expect @@ -12,6 +11,7 @@ ("events.html"), ] + @pytest.mark.parametrize("url", routes) def test_destination_options( page: Page, @@ -22,6 +22,7 @@ def test_destination_options( page.goto(f"{live_server_url}/{url}") page.on("response", lambda response: expect(response.status).to_equal(200)) + @pytest.mark.parametrize("url", routes) def test_destination_( page: Page, @@ -32,16 +33,18 @@ def test_destination_( page.goto(f"{live_server_url}/{url}") page.on("response", lambda response: expect(response.status).to_equal(200)) + @pytest.mark.parametrize( - "title, url",( - ("Acerca de", '/es/about/'), + "title, url", + ( + ("Acerca de", "/es/about/"), ("Inicio", "/es/"), ("Eventos", "/es/events/"), ("Comunidad", "/es/community/"), ("Conferencias", "/es/conferences/"), - ) + ), ) -def test_headers_in_language(page: Page, title:str, url:str) -> None: +def test_headers_in_language(page: Page, title: str, url: str) -> None: page.goto("https://blackpythondevs.github.io/") page.get_by_label("Language").select_option("es") page.get_by_role("link", name=title).click() From fcb95ed87145f9c365996d372126ab7f2c8c0f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleksis=20Fraga=20Men=C3=A9ndez?= Date: Thu, 5 Oct 2023 15:57:21 -0400 Subject: [PATCH 2/7] Update test : check the page use html language code english/spanish test_destination_options and test_destination_ look the same --- .github/workflows/playwright.yml | 2 +- pytest.ini | 1 + tests/test.py | 18 +++++------------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 1cb694e..c9613ef 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -26,4 +26,4 @@ jobs: run: sleep 45s shell: bash - name: Run tests - run: python -m pytest -v + run: python -m pytest diff --git a/pytest.ini b/pytest.ini index 7c47955..7f1d01e 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] python_files = *.py +addopts = -v diff --git a/tests/test.py b/tests/test.py index ba6c322..63a3af8 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,7 +1,6 @@ import pytest from playwright.sync_api import Page, expect - live_server_url = "https://blackpythondevs.github.io" routes = [ @@ -13,18 +12,7 @@ @pytest.mark.parametrize("url", routes) -def test_destination_options( - page: Page, - url: str, -): - """Test that the destinations page loads with seeded data""" - # Create a destination - page.goto(f"{live_server_url}/{url}") - page.on("response", lambda response: expect(response.status).to_equal(200)) - - -@pytest.mark.parametrize("url", routes) -def test_destination_( +def test_destination( page: Page, url: str, ) -> None: @@ -46,6 +34,10 @@ def test_destination_( ) def test_headers_in_language(page: Page, title: str, url: str) -> None: page.goto("https://blackpythondevs.github.io/") + lang = page.evaluate("document.documentElement.lang") + assert lang == "en" page.get_by_label("Language").select_option("es") page.get_by_role("link", name=title).click() expect(page).to_have_url(f"https://blackpythondevs.github.io{url}") + lang = page.evaluate("document.documentElement.lang") + assert lang == "es" From 4f08ad633c827601e5bed2ffe8fd15ab94b4dfee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleksis=20Fraga=20Men=C3=A9ndez?= Date: Thu, 5 Oct 2023 16:10:12 -0400 Subject: [PATCH 3/7] Add Pages for ES [events, community, conferences] --- _articles/es/community.md | 9 +++++++++ _articles/es/conferences.md | 9 +++++++++ _articles/es/events.md | 9 +++++++++ 3 files changed, 27 insertions(+) create mode 100644 _articles/es/community.md create mode 100644 _articles/es/conferences.md create mode 100644 _articles/es/events.md diff --git a/_articles/es/community.md b/_articles/es/community.md new file mode 100644 index 0000000..1477491 --- /dev/null +++ b/_articles/es/community.md @@ -0,0 +1,9 @@ +--- +layout: index +lang: es +title: Comunidad +--- + +# Comunidad + +Esta es la página de ejemplo Comunidad diff --git a/_articles/es/conferences.md b/_articles/es/conferences.md new file mode 100644 index 0000000..d318782 --- /dev/null +++ b/_articles/es/conferences.md @@ -0,0 +1,9 @@ +--- +layout: index +lang: es +title: Conferencias +--- + +# Conferencias + +Esta es la página de ejemplo Conferencias diff --git a/_articles/es/events.md b/_articles/es/events.md new file mode 100644 index 0000000..57b460f --- /dev/null +++ b/_articles/es/events.md @@ -0,0 +1,9 @@ +--- +layout: index +lang: es +title: Eventos +--- + +# Eventos + +Esta es la página de ejemplo Eventos From 4551f14ace5b09e41ef1bed7dea7fcf525b9f9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleksis=20Fraga=20Men=C3=A9ndez?= Date: Thu, 5 Oct 2023 16:56:49 -0400 Subject: [PATCH 4/7] Add Black formatter, Playwright and Pytest to Devcontainer --- .devcontainer/devcontainer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9fe6b87..5d92d1d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -16,10 +16,11 @@ 4000, // Live reload server 35729 - ] + ], // Uncomment the next line to run commands after the container is created. - // "postCreateCommand": "jekyll --version" + // git config --global --add safe.directory /workspaces/blackpythondevs.github.io + "postCreateCommand": "python3 -m pip install black pytest-playwright && python3 -m playwright install --with-deps" // Configure tool-specific properties. // "customizations": {}, From 12faf5034de102ee894cf203f9ea37f50286d251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleksis=20Fraga=20Men=C3=A9ndez?= Date: Thu, 5 Oct 2023 16:58:06 -0400 Subject: [PATCH 5/7] Update Playwright workflow: Add Jekyll detached --- .github/workflows/playwright.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index c9613ef..0089644 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -22,6 +22,8 @@ jobs: python -m pip install --upgrade pip pip install -r requirements-dev.txt python -m playwright install --with-deps + - name: Jekyll detached + run: bundle exec jekyll serve --detach - name: Sleep for 45 seconds run: sleep 45s shell: bash From a092ccb5b7bcd24642ed2aa4ebccd11ad7d12fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleksis=20Fraga=20Men=C3=A9ndez?= Date: Thu, 5 Oct 2023 16:59:40 -0400 Subject: [PATCH 6/7] Update live_server_url to use localhost:4000 Jekyll --- tests/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test.py b/tests/test.py index 63a3af8..f2999fb 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,7 +1,7 @@ import pytest from playwright.sync_api import Page, expect -live_server_url = "https://blackpythondevs.github.io" +live_server_url = "http://localhost:4000" routes = [ ("about.html"), @@ -33,11 +33,11 @@ def test_destination( ), ) def test_headers_in_language(page: Page, title: str, url: str) -> None: - page.goto("https://blackpythondevs.github.io/") + page.goto(live_server_url) lang = page.evaluate("document.documentElement.lang") assert lang == "en" page.get_by_label("Language").select_option("es") page.get_by_role("link", name=title).click() - expect(page).to_have_url(f"https://blackpythondevs.github.io{url}") + expect(page).to_have_url(f"{live_server_url}{url}") lang = page.evaluate("document.documentElement.lang") assert lang == "es" From 8f3498623f4c29d8d5d2f8964c33269c0d207e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleksis=20Fraga=20Men=C3=A9ndez?= <44526468+oleksis@users.noreply.github.com> Date: Fri, 6 Oct 2023 02:56:21 +0000 Subject: [PATCH 7/7] Update Playwright workflow use Jekyll detached and pytest Update test for use live server url to 127.0.0.1:4000 Add docker-in-docker and act devcontainer features --- .devcontainer/devcontainer.json | 4 +++- .github/workflows/playwright.yml | 15 ++++++++------- .gitignore | 1 + .ruby-version | 1 + tests/test.py | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 .ruby-version diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5d92d1d..c913313 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,9 @@ // Features to add to the dev container. More info: https://containers.dev/features. "features": { - "ghcr.io/devcontainers-contrib/features/pre-commit:2": {} + "ghcr.io/devcontainers-contrib/features/pre-commit:2": {}, + "ghcr.io/devcontainers/features/docker-in-docker": {}, + "ghcr.io/devcontainers-contrib/features/act:1": {} }, // Use 'forwardPorts' to make a list of ports inside the container available locally. diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 0089644..22f10f6 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -22,10 +22,11 @@ jobs: python -m pip install --upgrade pip pip install -r requirements-dev.txt python -m playwright install --with-deps - - name: Jekyll detached - run: bundle exec jekyll serve --detach - - name: Sleep for 45 seconds - run: sleep 45s - shell: bash - - name: Run tests - run: python -m pytest + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Jekyll detached and pytest + run: | + bundle exec jekyll serve --detach + python -m pytest diff --git a/.gitignore b/.gitignore index 19561ff..840c086 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ venv .jekyll-metadata **/__pycache__ .pytest_cache +bin/ diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..be94e6f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2.2 diff --git a/tests/test.py b/tests/test.py index f2999fb..c970c23 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,7 +1,7 @@ import pytest from playwright.sync_api import Page, expect -live_server_url = "http://localhost:4000" +live_server_url = "http://127.0.0.1:4000" routes = [ ("about.html"),