Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools
python -m pip install -r requirements/tests.txt
- name: Install playwright browsers
run: |
python -m playwright install --with-deps
- name: Set up databases
run: |
PGPASSWORD="postgres" createuser -U postgres -d djangoproject --superuser -h localhost
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could someone that uses Docker review the change to this file?

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ COPY ./requirements ./requirements
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends ${BUILD_DEPENDENCIES} \
&& python3 -m pip install --no-cache-dir -r ${REQ_FILE} \
&& if [ "${REQ_FILE}" = "requirements/tests.txt" ]; then \
echo "Installing Playwright browsers..."; \
playwright install --with-deps; \
fi \
&& apt-get purge --assume-yes --auto-remove ${BUILD_DEPENDENCIES} \
Comment on lines 33 to 38
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may choose to install and test on chromium if not all broswers are necessary:

python3 -m playwright install --with-deps chromium; \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will reduce the docker image size as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would test at least for chromium and firefox to at least cover the 2 more used open source browser engine.

&& apt-get distclean

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ APP_LIST ?= accounts aggregator blog checklists contact dashboard djangoproject
SCSS = djangoproject/scss
STATIC = djangoproject/static

ci: compilemessages test
ci: compilemessages collectstatics test
@python -m coverage report

compilemessages:
Expand Down
53 changes: 53 additions & 0 deletions djangoproject/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os
from http import HTTPStatus
from io import StringIO

from django.conf import settings
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core.management import call_command
from django.test import TestCase
from django.urls import NoReverseMatch, get_resolver
from django.utils.translation import activate, gettext as _
from django_hosts.resolvers import reverse
from playwright.sync_api import expect, sync_playwright

from docs.models import DocumentRelease, Release

Expand Down Expand Up @@ -211,3 +214,53 @@ def test_single_h1_per_page(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "<h1", count=1)


class EndToEndTests(ReleaseMixin, StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
super().setUpClass()
cls.playwright = sync_playwright().start()
cls.browser = cls.playwright.chromium.launch()
cls.mac_user_agent = "Mozilla/5.0 (Macintosh) AppleWebKit"
cls.windows_user_agent = "Mozilla/5.0 (Windows NT 10.0)"
cls.mobile_linux_user_agent = "Mozilla/5.0 (Linux; Android 10; Mobile)"

@classmethod
def tearDownClass(cls):
super().tearDownClass()
cls.browser.close()
cls.playwright.stop()

def setUp(self):
super().setUp()
self.setUpTestData()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean self.setUp() here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no, we need setUpTestData to be called as it isn't called from StaticLiveServerTestCase

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok, for ReleaseMixin? I think I understand now. It feels odd to call setUpTestData since it's intended to be used to set up data for the whole test case. It seems safe though.


def test_search_ctrl_k_hotkey(self):
page1 = self.browser.new_page(user_agent=self.windows_user_agent)
page2 = self.browser.new_page(
user_agent=self.mobile_linux_user_agent,
viewport={"width": 375, "height": 812},
)
for page in [page1, page2]:
with self.subTest(page=page):
page.goto(self.live_server_url)
search_bar = page.locator("#id_q")
expect(search_bar).to_have_attribute("placeholder", "Search (Ctrl+K)")
is_focused = page.evaluate("document.activeElement.id === 'id_q'")
self.assertFalse(is_focused)

page.keyboard.press("Control+KeyK")
is_focused = page.evaluate("document.activeElement.id === 'id_q'")
self.assertTrue(is_focused)
page.close()

def test_search_placeholder_mac_mode(self):
page = self.browser.new_page(user_agent=self.mac_user_agent)
page.goto(self.live_server_url)

desktop_search_bar = page.locator("#id_q")
expect(desktop_search_bar).to_have_attribute("placeholder", "Search (⌘\u200aK)")
Comment thread
sarahboyce marked this conversation as resolved.

page.close()
1 change: 1 addition & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r dev.txt
coverage==7.13.1
playwright==1.58.0
requests-mock==1.12.1
tblib>=3.0.0