From ed7a9ae18c9a20af1a9b4714132af90ccf8c12c6 Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Thu, 1 Feb 2024 14:58:45 -0700 Subject: [PATCH 01/12] wip - fixing UI builds, pulling pre-built files, groundwork for python playwright test --- .github/workflows/publish.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- Dockerfile | 18 +++++++---------- MANIFEST.in | 1 + Makefile | 9 +++------ docs/tutorials/install.rst | 4 ++-- kinto/plugins/admin/VERSION | 2 +- kinto/plugins/admin/public/help.html | 4 ++-- kinto/plugins/admin/views.py | 2 +- scripts/build-kinto-admin.sh | 29 ---------------------------- scripts/pull-kinto-admin.sh | 14 ++++++++++++++ 11 files changed, 35 insertions(+), 56 deletions(-) create mode 100644 MANIFEST.in delete mode 100755 scripts/build-kinto-admin.sh create mode 100755 scripts/pull-kinto-admin.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cd36fd9ab..48600ba6b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,8 +28,8 @@ jobs: node --version npm --version - - name: Build Admin UI - run: make build-kinto-admin + - name: Pull Admin UI + run: make pull-kinto-admin - name: Install pypa/build run: python3 -m pip install build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 696078a0e..b870b6531 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -229,8 +229,8 @@ jobs: which firefox firefox --version - - name: make build-kinto-admin - run: make build-kinto-admin + - name: make pull-kinto-admin + run: make pull-kinto-admin - name: Install dependencies run: make install-dev diff --git a/Dockerfile b/Dockerfile index d855cea9a..5e4402047 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,19 @@ # Mozilla Kinto server - -FROM node:lts-bullseye-slim as node-builder -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl -COPY scripts/build-kinto-admin.sh . -COPY /kinto/plugins/admin ./kinto/plugins/admin -RUN bash build-kinto-admin.sh - FROM python:3.10-slim-bullseye as python-builder RUN python -m venv /opt/venv -RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev +RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev ca-certificates curl ARG KINTO_VERSION=1 ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_KINTO=${KINTO_VERSION} \ PATH="/opt/venv/bin:$PATH" # At this stage we only fetch and build all dependencies. WORKDIR /pkg-kinto -COPY constraints.txt . -COPY pyproject.toml . +COPY constraints.txt pyproject.toml MANIFEST.in ./ COPY kinto/ kinto/ + +COPY scripts/pull-kinto-admin.sh . +RUN ls ./kinto/plugins/admin/build +RUN bash pull-kinto-admin.sh + RUN pip install --upgrade pip && \ pip install ".[postgresql,memcached,monitoring]" -c constraints.txt && \ pip install kinto-attachment kinto-emailer httpie @@ -27,7 +24,6 @@ RUN groupadd --gid 10001 app && \ useradd --uid 10001 --gid 10001 --home /app --create-home app COPY --from=python-builder /opt/venv /opt/venv -COPY --from=node-builder /kinto/plugins/admin/build ./kinto/plugins/admin/build ENV KINTO_INI=/etc/kinto/kinto.ini \ PORT=8888 \ diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000..89998231f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include kinto/plugins/admin/build * diff --git a/Makefile b/Makefile index 87610c854..c57ebbdbc 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ help: @echo " install-monitoring enable monitoring features like StatsD and Newrelic" @echo " install-postgres install postgresql support" @echo " install-dev install dependencies and everything needed to run tests" - @echo " build-kinto-admin build the Kinto admin UI plugin (requires npm)" + @echo " pull-kinto-admin pull the Kinto admin UI plugin (requires npm)" @echo " serve start the kinto server on default port" @echo " migrate run the kinto migrations" @echo " lint run the code linters" @@ -67,8 +67,8 @@ $(DOC_STAMP): $(PYTHON) docs/requirements.txt constraints.txt: constraints.in pip-compile -o constraints.txt constraints.in -build-kinto-admin: need-npm - scripts/build-kinto-admin.sh +pull-kinto-admin: + scripts/pull-kinto-admin.sh $(SERVER_CONFIG): $(VENV)/bin/kinto init --ini $(SERVER_CONFIG) @@ -105,9 +105,6 @@ format: install-dev tdd: install-dev $(VENV)/bin/ptw --runner $(VENV)/bin/py.test -need-npm: - @npm --version 2>/dev/null 1>&2 || (echo "The 'npm' command is required to build the Kinto Admin UI." && exit 1) - need-kinto-running: @curl http://localhost:8888/v0/ 2>/dev/null 1>&2 || (echo "Run 'make runkinto' before starting tests." && exit 1) diff --git a/docs/tutorials/install.rst b/docs/tutorials/install.rst index efaad1fc4..5d265652e 100644 --- a/docs/tutorials/install.rst +++ b/docs/tutorials/install.rst @@ -316,9 +316,9 @@ Kinto Admin ----------- In order to run a local `Kinto Admin UI `_ from a cloned -repo, the ``npm`` command must be available in order to build it with :: +repo, run :: - make build-kinto-admin + make pull-kinto-admin Go further diff --git a/kinto/plugins/admin/VERSION b/kinto/plugins/admin/VERSION index cb2b00e4f..75a22a26a 100644 --- a/kinto/plugins/admin/VERSION +++ b/kinto/plugins/admin/VERSION @@ -1 +1 @@ -3.0.1 +3.0.3 diff --git a/kinto/plugins/admin/public/help.html b/kinto/plugins/admin/public/help.html index 588f98228..6688223a4 100644 --- a/kinto/plugins/admin/public/help.html +++ b/kinto/plugins/admin/public/help.html @@ -11,7 +11,7 @@

Build and run locally

In order to get a local Kinto Admin running at this address, just run the following command:

- make build-kinto-admin + make pull-kinto-admin

Restart the server and refresh!

@@ -22,4 +22,4 @@

...or use our online version!

and set the server address to http://localhost:8888/v1.
- \ No newline at end of file + diff --git a/kinto/plugins/admin/views.py b/kinto/plugins/admin/views.py index eb68e36ea..fba56f790 100644 --- a/kinto/plugins/admin/views.py +++ b/kinto/plugins/admin/views.py @@ -16,7 +16,7 @@ def admin_home_view(request): This requires the Admin UI to be built with ``ASSET_PATH="/v1/admin/"``. """ # Default location of the Admin UI is relative to this plugin source folder, - # as built with the ``make build-kinto-admin`` command. + # as pulled with the ``make pull-kinto-admin`` command. admin_assets_path = request.registry.settings["admin_assets_path"] or os.path.join( HERE, "build" ) diff --git a/scripts/build-kinto-admin.sh b/scripts/build-kinto-admin.sh deleted file mode 100755 index 1ee0e914d..000000000 --- a/scripts/build-kinto-admin.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -set -euo pipefail - -VERSION=$(cat kinto/plugins/admin/VERSION) -TAG="v${VERSION}" -TARBALL_NAME="${TAG}.tar.gz" -SRC_DIR="kinto-admin-${VERSION}" - -# download and unzip release -cd kinto/plugins/admin/ -curl -OL "https://github.com/Kinto/kinto-admin/archive/refs/tags/${TAG}.tar.gz" -tar -xf "${TARBALL_NAME}" && rm "${TARBALL_NAME}" - -# build kinto-admin bundle -pushd "${SRC_DIR}" -npm ci -export ASSET_PATH="/v1/admin/" -# kinto-admin <= 2.1.1 -export SINGLE_SERVER=1 -# kinto-admin >= 2.1.2 -export KINTO_ADMIN_SINGLE_SERVER=1 -npm run build -popd - -# move build and delete source -TARGET_DIR=./build -rm -rf "${TARGET_DIR}" -mv "${SRC_DIR}/build" "${TARGET_DIR}" -rm -rf "${SRC_DIR}" diff --git a/scripts/pull-kinto-admin.sh b/scripts/pull-kinto-admin.sh new file mode 100755 index 000000000..e2d659690 --- /dev/null +++ b/scripts/pull-kinto-admin.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -euo pipefail + +VERSION=$(cat kinto/plugins/admin/VERSION) +TAG="v${VERSION}" + +echo $PWD + +# download and unzip release +curl -OL https://github.com/Kinto/kinto-admin/releases/download/${TAG}/kinto-admin-release.tar +rm -r ./kinto/plugins/admin/build || echo "admin/build folder doesn't exist yet" +mkdir ./kinto/plugins/admin/build +tar -xf kinto-admin-release.tar -C ./kinto/plugins/admin/build && rm kinto-admin-release.tar +echo $VERSION > ./kinto/plugins/admin/build/VERSION From 0e42d69f6ac1b00efa778a445a9a1747c608bd94 Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Thu, 1 Feb 2024 15:11:30 -0700 Subject: [PATCH 02/12] removed unnecesary ls --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5e4402047..b910ceb8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,6 @@ COPY constraints.txt pyproject.toml MANIFEST.in ./ COPY kinto/ kinto/ COPY scripts/pull-kinto-admin.sh . -RUN ls ./kinto/plugins/admin/build RUN bash pull-kinto-admin.sh RUN pip install --upgrade pip && \ From 3a131ca58b891313604ea11a7231955a74124739 Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Fri, 2 Feb 2024 08:36:13 -0700 Subject: [PATCH 03/12] Cleaning up --- MANIFEST.in | 1 - pyproject.toml | 2 +- scripts/pull-kinto-admin.sh | 6 ++---- 3 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 89998231f..000000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -recursive-include kinto/plugins/admin/build * diff --git a/pyproject.toml b/pyproject.toml index 838f76075..61d27e547 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ main = "kinto:main" include = ["kinto*"] [tool.setuptools.package-data] -"*" = ["*.tpl", "*.sql", "*.html", "VERSION"] +"*" = ["*.tpl", "*.sql", "kinto/plugins/admin/build/*", "VERSION"] [tool.setuptools.dynamic] readme = {file = ["README.rst", "CONTRIBUTORS.rst"]} diff --git a/scripts/pull-kinto-admin.sh b/scripts/pull-kinto-admin.sh index e2d659690..d308bebe9 100755 --- a/scripts/pull-kinto-admin.sh +++ b/scripts/pull-kinto-admin.sh @@ -4,11 +4,9 @@ set -euo pipefail VERSION=$(cat kinto/plugins/admin/VERSION) TAG="v${VERSION}" -echo $PWD - # download and unzip release -curl -OL https://github.com/Kinto/kinto-admin/releases/download/${TAG}/kinto-admin-release.tar +curl -OL "https://github.com/Kinto/kinto-admin/releases/download/${TAG}/kinto-admin-release.tar" rm -r ./kinto/plugins/admin/build || echo "admin/build folder doesn't exist yet" mkdir ./kinto/plugins/admin/build tar -xf kinto-admin-release.tar -C ./kinto/plugins/admin/build && rm kinto-admin-release.tar -echo $VERSION > ./kinto/plugins/admin/build/VERSION +echo "$VERSION" > ./kinto/plugins/admin/build/VERSION From baf28d41ed40d86c762377e47316da98987db138 Mon Sep 17 00:00:00 2001 From: Alex Cottner <148472676+alexcottner@users.noreply.github.com> Date: Fri, 2 Feb 2024 08:51:42 -0700 Subject: [PATCH 04/12] Removed manifest.in from dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b910ceb8a..b401f552b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_KINTO=${KINTO_VERSION} \ PATH="/opt/venv/bin:$PATH" # At this stage we only fetch and build all dependencies. WORKDIR /pkg-kinto -COPY constraints.txt pyproject.toml MANIFEST.in ./ +COPY constraints.txt pyproject.toml ./ COPY kinto/ kinto/ COPY scripts/pull-kinto-admin.sh . From 9fea0403273c722ab310a46c077977a0473d1412 Mon Sep 17 00:00:00 2001 From: Alex Cottner <148472676+alexcottner@users.noreply.github.com> Date: Fri, 2 Feb 2024 08:55:55 -0700 Subject: [PATCH 05/12] Fixing package-data in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 61d27e547..dc911617a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ main = "kinto:main" include = ["kinto*"] [tool.setuptools.package-data] -"*" = ["*.tpl", "*.sql", "kinto/plugins/admin/build/*", "VERSION"] +"*" = ["*.tpl", "*.sql", "*.html", "*.css", "*.js", "*.png", "VERSION"] [tool.setuptools.dynamic] readme = {file = ["README.rst", "CONTRIBUTORS.rst"]} From 5eb9bbdf47578cbb0595ea6ff2d9db8280b757fe Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Fri, 2 Feb 2024 09:04:25 -0700 Subject: [PATCH 06/12] Adding basic python playwright test --- Makefile | 1 + constraints.in | 2 +- constraints.txt | 207 ++++++----------------------------------------- tests/browser.py | 78 ++++++------------ 4 files changed, 50 insertions(+), 238 deletions(-) diff --git a/Makefile b/Makefile index c57ebbdbc..5726bf295 100644 --- a/Makefile +++ b/Makefile @@ -116,6 +116,7 @@ functional: install-dev need-kinto-running $(VENV)/bin/py.test tests/functional.py browser-test: need-kinto-running + $(VENV)/bin/playwright install firefox $(VENV)/bin/py.test tests/browser.py clean: diff --git a/constraints.in b/constraints.in index b706aa9ec..1a2c98377 100644 --- a/constraints.in +++ b/constraints.in @@ -33,7 +33,7 @@ bravado_core pytest pytest-cache pytest-cov -selenium +playwright webtest # dev build diff --git a/constraints.txt b/constraints.txt index 0ad1011a8..7ddc65142 100644 --- a/constraints.txt +++ b/constraints.txt @@ -1,108 +1,49 @@ # -# This file is autogenerated by pip-compile with Python 3.9 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --strip-extras +# pip-compile --output-file=constraints.txt --strip-extras # -arrow==1.3.0 - # via isoduration attrs==23.2.0 # via # jsonschema - # outcome # referencing - # trio bcrypt==4.1.2 - # via -r constraints.in -beautifulsoup4==4.12.3 - # via webtest -bravado-core==6.1.1 - # via -r constraints.in -build==1.0.3 - # via -r constraints.in + # via kinto (pyproject.toml) certifi==2023.11.17 - # via - # requests - # selenium - # sentry-sdk + # via requests charset-normalizer==3.3.2 # via requests colander==2.0 # via - # -r constraints.in # cornice-swagger + # kinto (pyproject.toml) colorama==0.4.6 # via logging-color-formatter cornice==6.0.1 # via - # -r constraints.in # cornice-swagger + # kinto (pyproject.toml) cornice-swagger==1.0.1 - # via -r constraints.in -coverage==7.4.0 - # via - # coverage - # pytest-cov + # via kinto (pyproject.toml) dockerflow==2024.1.0 - # via -r constraints.in -exceptiongroup==1.2.0 - # via - # pytest - # trio - # trio-websocket -execnet==2.0.2 - # via pytest-cache -fqdn==1.5.1 - # via jsonschema -greenlet==3.0.3 - # via sqlalchemy -h11==0.14.0 - # via wsproto + # via kinto (pyproject.toml) hupper==1.12 # via pyramid idna==3.6 - # via - # jsonschema - # requests - # trio -importlib-metadata==7.0.1 - # via build -iniconfig==2.0.0 - # via pytest + # via requests iso8601==2.1.0 # via colander -isoduration==20.11.0 - # via jsonschema jsonpatch==1.33 - # via -r constraints.in + # via kinto (pyproject.toml) jsonpointer==2.4 - # via - # jsonpatch - # jsonschema -jsonref==1.1.0 - # via bravado-core + # via jsonpatch jsonschema==4.21.1 - # via - # -r constraints.in - # bravado-core - # swagger-spec-validator + # via kinto (pyproject.toml) jsonschema-specifications==2023.12.1 # via jsonschema logging-color-formatter==1.1.0 - # via -r constraints.in -markupsafe==2.1.4 - # via werkzeug -msgpack==1.0.7 - # via bravado-core -newrelic==9.6.0 - # via -r constraints.in -outcome==1.3.0.post0 - # via trio -packaging==23.2 - # via - # build - # pytest - # zope-sqlalchemy + # via kinto (pyproject.toml) pastedeploy==3.1.0 # via plaster-pastedeploy plaster==1.1.2 @@ -111,51 +52,23 @@ plaster==1.1.2 # pyramid plaster-pastedeploy==1.0.1 # via pyramid -pluggy==1.3.0 - # via pytest -psycopg2==2.9.9 - # via -r constraints.in -pyproject-hooks==1.0.0 - # via build pyramid==2.0.2 # via - # -r constraints.in # cornice + # kinto (pyproject.toml) # pyramid-mailer # pyramid-multiauth # pyramid-tm pyramid-mailer==0.15.1 - # via -r constraints.in + # via kinto (pyproject.toml) pyramid-multiauth==1.0.1 - # via -r constraints.in + # via kinto (pyproject.toml) pyramid-tm==2.5 - # via -r constraints.in -pysocks==1.7.1 - # via urllib3 -pytest==7.4.4 - # via - # -r constraints.in - # pytest-cache - # pytest-cov -pytest-cache==1.0 - # via -r constraints.in -pytest-cov==4.1.0 - # via -r constraints.in + # via kinto (pyproject.toml) python-dateutil==2.8.2 - # via - # -r constraints.in - # arrow - # bravado-core -python-memcached==1.62 - # via -r constraints.in + # via kinto (pyproject.toml) python-rapidjson==1.14 - # via -r constraints.in -pytz==2023.3.post1 - # via bravado-core -pyyaml==6.0.1 - # via - # bravado-core - # swagger-spec-validator + # via kinto (pyproject.toml) referencing==0.32.1 # via # jsonschema @@ -163,104 +76,35 @@ referencing==0.32.1 repoze-sendmail==4.4.1 # via pyramid-mailer requests==2.31.0 - # via - # -r constraints.in - # bravado-core -rfc3339-validator==0.1.4 - # via jsonschema -rfc3986-validator==0.1.1 - # via jsonschema + # via kinto (pyproject.toml) rpds-py==0.17.1 # via # jsonschema # referencing -ruff==0.1.15 - # via -r constraints.in -selenium==4.12.0 - # via -r constraints.in -sentry-sdk==1.39.2 - # via -r constraints.in -simplejson==3.19.2 - # via bravado-core six==1.16.0 # via - # bravado-core # cornice-swagger # python-dateutil - # rfc3339-validator -sniffio==1.3.0 - # via trio -sortedcontainers==2.4.0 - # via trio -soupsieve==2.5 - # via beautifulsoup4 -sqlalchemy==2.0.25 - # via - # -r constraints.in - # sentry-sdk - # zope-sqlalchemy -statsd==4.0.1 - # via -r constraints.in -swagger-spec-validator==3.0.3 - # via bravado-core -tomli==2.0.1 - # via - # build - # coverage - # pyproject-hooks - # pytest transaction==4.0 # via - # -r constraints.in + # kinto (pyproject.toml) # pyramid-mailer # pyramid-tm # repoze-sendmail - # zope-sqlalchemy translationstring==1.4 # via # colander # pyramid -trio==0.24.0 - # via - # selenium - # trio-websocket -trio-websocket==0.11.1 - # via selenium -types-python-dateutil==2.8.19.20240106 - # via arrow -typing-extensions==4.9.0 - # via - # sqlalchemy - # swagger-spec-validator -uri-template==1.3.0 - # via jsonschema urllib3==2.1.0 - # via - # requests - # selenium - # sentry-sdk + # via requests venusian==3.1.0 # via # cornice # pyramid waitress==2.1.2 - # via - # -r constraints.in - # webtest -webcolors==1.13 - # via jsonschema + # via kinto (pyproject.toml) webob==1.8.7 - # via - # pyramid - # webtest -webtest==3.0.0 - # via -r constraints.in -werkzeug==3.0.1 - # via -r constraints.in -wsproto==1.2.0 - # via trio-websocket -zipp==3.17.0 - # via importlib-metadata + # via pyramid zope-deprecation==5.0 # via pyramid zope-interface==6.1 @@ -268,9 +112,6 @@ zope-interface==6.1 # pyramid # repoze-sendmail # transaction - # zope-sqlalchemy -zope-sqlalchemy==3.1 - # via -r constraints.in # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/tests/browser.py b/tests/browser.py index 3496aaf6d..eaca64dfa 100644 --- a/tests/browser.py +++ b/tests/browser.py @@ -1,68 +1,38 @@ -import time +import re import unittest -from urllib.parse import urljoin -import requests -from selenium import webdriver -from selenium.webdriver.common.by import By +from playwright.sync_api import expect, sync_playwright -SERVER_URL = "http://localhost:8888/v1" -DEFAULT_AUTH = ("user", "p4ssw0rd") +baseUrl = "http://localhost:8888/v1/" +auth = {"user": "user", "password": "p4ssw0rd"} + +browser = sync_playwright().start().firefox.launch() +context = browser.new_context(base_url=baseUrl) +page = browser.new_page() class BrowserTest(unittest.TestCase): def setUp(self): - options = webdriver.FirefoxOptions() - options.headless = True - self.driver = webdriver.Firefox(options=options) - self.driver.implicitly_wait(10) # seconds - - @classmethod - def setUpClass(cls): - # Make sure our user exists. - requests.post( - urljoin(SERVER_URL, "/accounts"), - json={"data": {"id": DEFAULT_AUTH[0], "password": DEFAULT_AUTH[1]}}, - ) - - # Create a bucket and a collection for our user. - bucket_url = urljoin(SERVER_URL, "/buckets/workspace") - collection_url = f"{bucket_url}/collections/articles" - session = requests.Session() - session.auth = DEFAULT_AUTH - resp = session.put(bucket_url) - resp.raise_for_status() - resp = session.put(collection_url) - resp.raise_for_status() + request = context.request - def tearDown(self): - self.driver.close() + request.post("accounts", data={"data": {"id": auth["user"], "password": auth["password"]}}) - def test_admin_ui_renders_properly(self): - base_url = urljoin(SERVER_URL, "/v1/admin/") - self.driver.get(base_url) + def test_login_and_view_home_page(self): + page.goto(f"{baseUrl}admin/") - # Load auth page. - header = self.driver.find_element(By.CSS_SELECTOR, ".content div > h1") - self.assertIn("Administration", header.text) - self.assertTrue(header.is_displayed()) + expect(page).to_have_title(re.compile("Kinto Administration")) - # Select Kinto Accounts. - radio = self.driver.find_element(By.XPATH, "//label[contains(.,'Kinto Account Auth')]") - radio.click() + page.get_by_label("Kinto Account Auth").click() + txtUsername = page.get_by_label(re.compile("Username")) + txtPassword = page.get_by_label(re.compile("Password")) - # Fill username and password. - user_field = self.driver.find_element(By.ID, "root_credentials_username") - user_field.send_keys(DEFAULT_AUTH[0]) - user_pass = self.driver.find_element(By.ID, "root_credentials_password") - user_pass.send_keys(DEFAULT_AUTH[1]) - # Login - submit = self.driver.find_element(By.CSS_SELECTOR, "button[type='submit']") - submit.click() + txtUsername.fill(auth["user"]) + txtPassword.fill(auth["password"]) + page.get_by_text(re.compile("Sign in using Kinto Account Auth")).click() - # Navigate to simple review page (uses React Hooks and broke a few times) - review_url = base_url + "#/buckets/workspace/collections/articles/simple-review" - self.driver.get(review_url) - time.sleep(1) - self.assertTrue(self.driver.find_element(By.CSS_SELECTOR, ".alert-warning").is_displayed()) + expect(page.get_by_text("Kinto Administration")).to_be_visible() + expect(page.get_by_text("project_name")).to_be_visible() + expect(page.get_by_text("project_version")).to_be_visible() + expect(page.get_by_text("http_api_version")).to_be_visible() + expect(page.get_by_text("project_docs")).to_be_visible() From e304e2deb8e457e3d25249ba2b235e1883cc7edd Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Fri, 2 Feb 2024 09:05:32 -0700 Subject: [PATCH 07/12] Updated pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index dc911617a..3b9e8ae68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,7 +87,7 @@ test = [ "pytest", "pytest-cache", "pytest-cov", - "selenium", + "playwright", "webtest", ] dev = [ From 61a86392b76be1d36d24247777fc240b8ec4853f Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Fri, 2 Feb 2024 09:07:04 -0700 Subject: [PATCH 08/12] updated community.rst browser tests section --- docs/community.rst | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/docs/community.rst b/docs/community.rst index 1abc7afc3..3751913c3 100644 --- a/docs/community.rst +++ b/docs/community.rst @@ -235,16 +235,7 @@ In another terminal, run the end-to-end tests with: Browser Tests ------------- - -Make sure the `geckodriver `_ binary is available in your path. - -.. note:: - - If your installation of *Firefox* is custom, specify the path of its binary using an alias: - - :: - - alias geckodriver="geckodriver --binary /path/to/firefox" +We use `playwright `_ for browser testing. The tests included in this repo are very simple and verify the admin UI can at least authenticate with the current kinto back-end. Comprehensive unit tests are maintained in the kinto-admin repo. In a terminal, run an instance with the provided ``browser.ini`` configuration: From e67d65907c502e753a995aadc677dd9c231db41b Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Fri, 2 Feb 2024 10:25:17 -0700 Subject: [PATCH 09/12] Adjustements based on PR feedback --- Dockerfile | 18 ++++++++++-------- pyproject.toml | 2 +- scripts/pull-kinto-admin.sh | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index b401f552b..f6d491802 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,23 @@ # Mozilla Kinto server -FROM python:3.10-slim-bullseye as python-builder +FROM python:3.10-bullseye as python-builder RUN python -m venv /opt/venv -RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev ca-certificates curl ARG KINTO_VERSION=1 ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_KINTO=${KINTO_VERSION} \ PATH="/opt/venv/bin:$PATH" # At this stage we only fetch and build all dependencies. -WORKDIR /pkg-kinto -COPY constraints.txt pyproject.toml ./ -COPY kinto/ kinto/ +# Pull kinto-admin before building kinto so we can cache it +WORKDIR /kinto-admin +COPY kinto/plugins/admin kinto/plugins/admin COPY scripts/pull-kinto-admin.sh . RUN bash pull-kinto-admin.sh -RUN pip install --upgrade pip && \ - pip install ".[postgresql,memcached,monitoring]" -c constraints.txt && \ - pip install kinto-attachment kinto-emailer httpie +WORKDIR /pkg-kinto +COPY constraints.txt pyproject.toml ./ +RUN pip install --upgrade pip && pip install -r constraints.txt +COPY kinto/ kinto/ +RUN cp -r /kinto-admin/kinto/plugins/admin/build kinto/plugins/admin/ +RUN pip install ".[postgresql,memcached,monitoring]" -c constraints.txt && pip install kinto-attachment kinto-emailer httpie FROM python:3.10-slim-bullseye RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev diff --git a/pyproject.toml b/pyproject.toml index dc911617a..b21d218c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ main = "kinto:main" include = ["kinto*"] [tool.setuptools.package-data] -"*" = ["*.tpl", "*.sql", "*.html", "*.css", "*.js", "*.png", "VERSION"] +"*" = ["*.tpl", "*.sql", "plugins/admin/build/**", "VERSION"] [tool.setuptools.dynamic] readme = {file = ["README.rst", "CONTRIBUTORS.rst"]} diff --git a/scripts/pull-kinto-admin.sh b/scripts/pull-kinto-admin.sh index d308bebe9..dd8f931ae 100755 --- a/scripts/pull-kinto-admin.sh +++ b/scripts/pull-kinto-admin.sh @@ -9,4 +9,4 @@ curl -OL "https://github.com/Kinto/kinto-admin/releases/download/${TAG}/kinto-ad rm -r ./kinto/plugins/admin/build || echo "admin/build folder doesn't exist yet" mkdir ./kinto/plugins/admin/build tar -xf kinto-admin-release.tar -C ./kinto/plugins/admin/build && rm kinto-admin-release.tar -echo "$VERSION" > ./kinto/plugins/admin/build/VERSION +echo "$VERSION" > ./kinto/plugins/admin/build/VERSION # will not be needed after kinto-admin@8400176 (version 3.0.4?) From e04687f1a0fa787b3565d4a0846890d05115b2e3 Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Fri, 2 Feb 2024 11:28:35 -0700 Subject: [PATCH 10/12] specifying timeout minutes --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b870b6531..f746baea6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,7 @@ jobs: name: Unit Tests needs: lint runs-on: ubuntu-latest + timeout-minutes: 10 strategy: matrix: pyenv: [py38, py39, py310, py311, py312, py312-raw] From 6d9f7f1e119515e1fe370dd679a706c0ce9364fa Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Fri, 2 Feb 2024 12:14:03 -0700 Subject: [PATCH 11/12] rebuilding constraints.txt --- constraints.txt | 180 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 157 insertions(+), 23 deletions(-) diff --git a/constraints.txt b/constraints.txt index 7ddc65142..f24719053 100644 --- a/constraints.txt +++ b/constraints.txt @@ -2,48 +2,96 @@ # This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --output-file=constraints.txt --strip-extras +# pip-compile --output-file=constraints.txt --strip-extras constraints.in # +arrow==1.3.0 + # via isoduration attrs==23.2.0 # via # jsonschema # referencing bcrypt==4.1.2 - # via kinto (pyproject.toml) + # via -r constraints.in +beautifulsoup4==4.12.3 + # via webtest +bravado-core==6.1.1 + # via -r constraints.in +build==1.0.3 + # via -r constraints.in certifi==2023.11.17 - # via requests + # via + # requests + # sentry-sdk charset-normalizer==3.3.2 # via requests colander==2.0 # via + # -r constraints.in # cornice-swagger - # kinto (pyproject.toml) colorama==0.4.6 # via logging-color-formatter cornice==6.0.1 # via + # -r constraints.in # cornice-swagger - # kinto (pyproject.toml) cornice-swagger==1.0.1 - # via kinto (pyproject.toml) + # via -r constraints.in +coverage==7.4.0 + # via + # coverage + # pytest-cov dockerflow==2024.1.0 - # via kinto (pyproject.toml) + # via -r constraints.in +exceptiongroup==1.2.0 + # via pytest +execnet==2.0.2 + # via pytest-cache +fqdn==1.5.1 + # via jsonschema +greenlet==3.0.3 + # via + # playwright + # sqlalchemy hupper==1.12 # via pyramid idna==3.6 - # via requests + # via + # jsonschema + # requests +iniconfig==2.0.0 + # via pytest iso8601==2.1.0 # via colander +isoduration==20.11.0 + # via jsonschema jsonpatch==1.33 - # via kinto (pyproject.toml) + # via -r constraints.in jsonpointer==2.4 - # via jsonpatch + # via + # jsonpatch + # jsonschema +jsonref==1.1.0 + # via bravado-core jsonschema==4.21.1 - # via kinto (pyproject.toml) + # via + # -r constraints.in + # bravado-core + # swagger-spec-validator jsonschema-specifications==2023.12.1 # via jsonschema logging-color-formatter==1.1.0 - # via kinto (pyproject.toml) + # via -r constraints.in +markupsafe==2.1.4 + # via werkzeug +msgpack==1.0.7 + # via bravado-core +newrelic==9.6.0 + # via -r constraints.in +packaging==23.2 + # via + # build + # pytest + # zope-sqlalchemy pastedeploy==3.1.0 # via plaster-pastedeploy plaster==1.1.2 @@ -52,23 +100,53 @@ plaster==1.1.2 # pyramid plaster-pastedeploy==1.0.1 # via pyramid +playwright==1.41.1 + # via -r constraints.in +pluggy==1.3.0 + # via pytest +psycopg2==2.9.9 + # via -r constraints.in +pyee==11.0.1 + # via playwright +pyproject-hooks==1.0.0 + # via build pyramid==2.0.2 # via + # -r constraints.in # cornice - # kinto (pyproject.toml) # pyramid-mailer # pyramid-multiauth # pyramid-tm pyramid-mailer==0.15.1 - # via kinto (pyproject.toml) + # via -r constraints.in pyramid-multiauth==1.0.1 - # via kinto (pyproject.toml) + # via -r constraints.in pyramid-tm==2.5 - # via kinto (pyproject.toml) + # via -r constraints.in +pytest==7.4.4 + # via + # -r constraints.in + # pytest-cache + # pytest-cov +pytest-cache==1.0 + # via -r constraints.in +pytest-cov==4.1.0 + # via -r constraints.in python-dateutil==2.8.2 - # via kinto (pyproject.toml) + # via + # -r constraints.in + # arrow + # bravado-core +python-memcached==1.62 + # via -r constraints.in python-rapidjson==1.14 - # via kinto (pyproject.toml) + # via -r constraints.in +pytz==2023.3.post1 + # via bravado-core +pyyaml==6.0.1 + # via + # bravado-core + # swagger-spec-validator referencing==0.32.1 # via # jsonschema @@ -76,35 +154,88 @@ referencing==0.32.1 repoze-sendmail==4.4.1 # via pyramid-mailer requests==2.31.0 - # via kinto (pyproject.toml) + # via + # -r constraints.in + # bravado-core +rfc3339-validator==0.1.4 + # via jsonschema +rfc3986-validator==0.1.1 + # via jsonschema rpds-py==0.17.1 # via # jsonschema # referencing +ruff==0.1.15 + # via -r constraints.in +sentry-sdk==1.39.2 + # via -r constraints.in +simplejson==3.19.2 + # via bravado-core six==1.16.0 # via + # bravado-core # cornice-swagger # python-dateutil + # rfc3339-validator +soupsieve==2.5 + # via beautifulsoup4 +sqlalchemy==2.0.25 + # via + # -r constraints.in + # sentry-sdk + # zope-sqlalchemy +statsd==4.0.1 + # via -r constraints.in +swagger-spec-validator==3.0.3 + # via bravado-core +tomli==2.0.1 + # via + # build + # coverage + # pyproject-hooks + # pytest transaction==4.0 # via - # kinto (pyproject.toml) + # -r constraints.in # pyramid-mailer # pyramid-tm # repoze-sendmail + # zope-sqlalchemy translationstring==1.4 # via # colander # pyramid +types-python-dateutil==2.8.19.20240106 + # via arrow +typing-extensions==4.9.0 + # via + # pyee + # sqlalchemy + # swagger-spec-validator +uri-template==1.3.0 + # via jsonschema urllib3==2.1.0 - # via requests + # via + # requests + # sentry-sdk venusian==3.1.0 # via # cornice # pyramid waitress==2.1.2 - # via kinto (pyproject.toml) + # via + # -r constraints.in + # webtest +webcolors==1.13 + # via jsonschema webob==1.8.7 - # via pyramid + # via + # pyramid + # webtest +webtest==3.0.0 + # via -r constraints.in +werkzeug==3.0.1 + # via -r constraints.in zope-deprecation==5.0 # via pyramid zope-interface==6.1 @@ -112,6 +243,9 @@ zope-interface==6.1 # pyramid # repoze-sendmail # transaction + # zope-sqlalchemy +zope-sqlalchemy==3.1 + # via -r constraints.in # The following packages are considered to be unsafe in a requirements file: # setuptools From c1744fafa0ba6fe22e1ec72b2994b397bcd6fda2 Mon Sep 17 00:00:00 2001 From: Alex Cottner Date: Fri, 2 Feb 2024 12:20:41 -0700 Subject: [PATCH 12/12] removing temout --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f746baea6..b870b6531 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,6 @@ jobs: name: Unit Tests needs: lint runs-on: ubuntu-latest - timeout-minutes: 10 strategy: matrix: pyenv: [py38, py39, py310, py311, py312, py312-raw]