From 6d0d8fd5cd08f1e7447ac5c2a941278bb3ea540e Mon Sep 17 00:00:00 2001 From: Restioson Date: Thu, 17 Oct 2024 15:38:49 +0200 Subject: [PATCH 1/2] refactor(build): make dev requirements inherit from test This means we don't have to keep the two files in sync manually anymore --- Dockerfile-dev | 2 +- requirements-dev.txt | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Dockerfile-dev b/Dockerfile-dev index 465abf5d..a59cdeba 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -12,7 +12,7 @@ SHELL ["/bin/bash", "-c"] WORKDIR /app # Install dependencies -COPY requirements.txt requirements-dev.txt /app/ +COPY requirements.txt requirements-test.txt requirements-dev.txt /app/ RUN < Date: Thu, 17 Oct 2024 15:44:31 +0200 Subject: [PATCH 2/2] test(frontend): add basic Selenium testing So far, this just checks that the main pages (as listed in the navigation bar) do not 404, have a Django ProgrammingError page displayed, etc. The test uses the Chromium webdriver because it is more complex to set up one test to run with two different webdrivers in sequence. It also opts for emulating the common _desktop_ resolution of 1080p (future tests could check that the navbar expander, etc., work properly, but this is out of scope for test #1). --- Dockerfile-dev | 2 +- app/general/tests/test_frontend.py | 64 ++++++++++++++++++++++++++++++ requirements-test.txt | 1 + 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 app/general/tests/test_frontend.py diff --git a/Dockerfile-dev b/Dockerfile-dev index a59cdeba..468ce882 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -18,7 +18,7 @@ RUN < - Search' + try: + wait = WebDriverWait(self.driver, timeout=WAIT_TIMEOUT) + wait.until(lambda d: link_text in self.driver.title) + except TimeoutException: + assert link_text in self.driver.title, ( + f"Expected title for page {link_text} to have {link_text};" + f" was {self.driver.title}" + ) + self.assert_current_page_not_error() + + def assert_current_page_not_error(self): + assert not self.driver.title.startswith("Error"), f"Actual title was {self.driver.title}" + assert not self.driver.title.startswith( + "ProgrammingError" + ), f"Actual title was {self.driver.title}" + assert not self.driver.find_element(By.ID, "error-block").is_displayed() diff --git a/requirements-test.txt b/requirements-test.txt index bfe3dc05..a5743332 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -3,3 +3,4 @@ django-debug-toolbar django-extensions faker ruff +selenium==4.25.0