From b7c15acddd77fac185cb11e50b06543b4ca86cd4 Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Thu, 4 Jan 2024 03:01:28 -0500 Subject: [PATCH] remove old tests make tests parallel clarify docs --- .github/workflows/tests.yml | 2 +- docs/onboarding.md | 2 +- flake.nix | 1 - package-lock.json | 75 ---------------------------- package.json | 21 -------- playwright.config.js | 78 ----------------------------- tests/Dockerfile | 8 --- tests/api3.spec.js | 99 ------------------------------------- tests/docker-compose.yml | 7 --- tests/example.spec.js | 19 ------- 10 files changed, 2 insertions(+), 310 deletions(-) delete mode 100644 package-lock.json delete mode 100644 package.json delete mode 100644 playwright.config.js delete mode 100644 tests/Dockerfile delete mode 100644 tests/api3.spec.js delete mode 100644 tests/docker-compose.yml delete mode 100644 tests/example.spec.js diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9e056fc6..97e0c645 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,6 @@ jobs: make metropolis/local_rsa_privkey.pem make metropolis/local_settings.py - name: Migrations - run: .venv/bin/python -Wa manage.py migrate + run: .venv/bin/python -Wa manage.py migrate --parallel - name: Django Tests run: .venv/bin/python -Wa manage.py test diff --git a/docs/onboarding.md b/docs/onboarding.md index 63f6fc6a..0c64d17e 100644 --- a/docs/onboarding.md +++ b/docs/onboarding.md @@ -33,7 +33,7 @@ poetry run python ./manage.py runserver ### Errors ##### Any issue with psycopg2 -- `pip install psycopg2-binary` and try again (pip3 if you have both python 2 and 3 installed) +- `pip install psycopg2-binary` and try again (pip or pip3 not poetry add) #### Windows ###### poetry ModuleNotFoundError: No module named 'charset_normalizer' reinstall poetry and run poetry install in an elevated (admin) terminal diff --git a/flake.nix b/flake.nix index 9b9873a7..8d7c8770 100644 --- a/flake.nix +++ b/flake.nix @@ -39,7 +39,6 @@ black isort mypy - nodejs act ]; }); diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 14137c92..00000000 --- a/package-lock.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "metropolis", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "metropolis", - "version": "1.0.0", - "license": "ISC", - "devDependencies": { - "@playwright/test": "^1.32.2" - } - }, - "node_modules/@playwright/test": { - "version": "1.40.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.1.tgz", - "integrity": "sha512-EaaawMTOeEItCRvfmkI9v6rBkF1svM8wjl/YPRrg2N2Wmp+4qJYkWtJsbew1szfKKDm6fPLy4YAanBhIlf9dWw==", - "dev": true, - "dependencies": { - "playwright": "1.40.1" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, - "node_modules/playwright": { - "version": "1.40.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.1.tgz", - "integrity": "sha512-2eHI7IioIpQ0bS1Ovg/HszsN/XKNwEG1kbzSDDmADpclKc7CyqkHw7Mg2JCz/bbCxg25QUPcjksoMW7JcIFQmw==", - "dev": true, - "dependencies": { - "playwright-core": "1.40.1" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=16" - }, - "optionalDependencies": { - "fsevents": "2.3.2" - } - }, - "node_modules/playwright-core": { - "version": "1.40.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.1.tgz", - "integrity": "sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==", - "dev": true, - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=16" - } - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 6ccca214..00000000 --- a/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "metropolis", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": {}, - "repository": { - "type": "git", - "url": "git+https://github.com/wlmac/metropolis.git" - }, - "keywords": [], - "author": "", - "license": "ISC", - "bugs": { - "url": "https://github.com/wlmac/metropolis/issues" - }, - "homepage": "https://github.com/wlmac/metropolis#readme", - "devDependencies": { - "@playwright/test": "^1.32.2" - } -} diff --git a/playwright.config.js b/playwright.config.js deleted file mode 100644 index bf72890d..00000000 --- a/playwright.config.js +++ /dev/null @@ -1,78 +0,0 @@ -// @ts-check -const { defineConfig, devices } = require('@playwright/test'); - -/** - * Read environment variables from file. - * https://github.com/motdotla/dotenv - */ -// require('dotenv').config(); - -/** - * @see https://playwright.dev/docs/test-configuration - */ -module.exports = defineConfig({ - testDir: './tests', - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ - use: { - baseURL: 'http://127.0.0.1:8000', - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, - }, - - { - name: 'firefox', - use: { ...devices['Desktop Firefox'] }, - }, - - { - name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, - - /* Test against mobile viewports. */ - { - name: 'Mobile Chrome', - use: { ...devices['Pixel 5'] }, - }, - { - name: 'Mobile Safari', - use: { ...devices['iPhone 12'] }, - }, - - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { ...devices['Desktop Edge'], channel: 'msedge' }, - // }, - // { - // name: 'Google Chrome', - // use: { ..devices['Desktop Chrome'], channel: 'chrome' }, - // }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: 'python3 manage.py runserver', - url: 'http://127.0.0.1:8000', - reuseExistingServer: !process.env.CI, - }, -}); - diff --git a/tests/Dockerfile b/tests/Dockerfile deleted file mode 100644 index e8d6e8ef..00000000 --- a/tests/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM mcr.microsoft.com/playwright - -RUN cd $(mktemp -d) && \ - npx playwright install --with-deps && \ - npm i -D @playwright/test - -CMD cd /proj && \ - npx playwright test diff --git a/tests/api3.spec.js b/tests/api3.spec.js deleted file mode 100644 index ad14c384..00000000 --- a/tests/api3.spec.js +++ /dev/null @@ -1,99 +0,0 @@ -// @ts-check -const {test, expect} = require('@playwright/test'); -import {request as req} from '@playwright/test'; - -test('sanity', async ({page}) => { - await page.goto('/'); - await expect(page).toHaveTitle(/Metropolis/); -}); - -test('Check OK', async ({request}) => { - const urls = [ - '/api/version', - '/api/v3/staff', - '/api/v3/feeds', - '/api/v3/banners', - ]; - for (let url of urls) { - const res = await request.get(url); - expect(res.ok()).toBeTruthy(); - expect(res.status()).toBe(200); - } -}); - -async function authenticate({request}) { - const auth = await request.post('/api/auth/token', { - data: { - username: 'sotokanda', - password: 'verysecure', - }, - }); - console.log("authenticate: auth:", auth); - expect(auth.ok()).toBeTruthy(); - const tokens = await auth.json(); - const ctx = await req.newContext({ - extraHTTPHeaders: { - "Authorization": `Bearer ${tokens.access}`, - }, - }); - // NOTE: not checking refresh token for now (token should work aniway) - // check access token works - const res1 = await ctx.get('/api/me'); - console.log("authenticate: res1:", res1); - expect(res1.ok()).toBeTruthy(); - expect(res1.status()).toBe(200); - return ctx; -} - -test('token auth', async({request}) => { - await authenticate({request}) -}); - -test('expo notif token', async ({request}) => { - const ctx = await authenticate({request}); - const fakeTokens = ["fakeExpoToken1", "ExponentPushToken[fakeExpoToken2]"]; - for (let fakeToken of fakeTokens) { - const res1 = await ctx.put('/api/v3/notif/token', { - data: {expo_push_token: fakeToken}, - }); - //expect(res1.ok()).toBeTruthy(); - //expect(res1.status()).toBe(200); - const res2 = await ctx.delete('/api/v3/notif/token', { - data: {expo_push_token: fakeToken}, - }); - //expect(res2.ok()).toBeTruthy(); fixme ken :D - //expect(res2.status()).toBe(200); - } - - // deleting nonexistent token should return 200 - const nonexistentToken = "nonexistentToken"; - const res = await ctx.delete('/api/v3/notif/token', { - data: {expo_push_token: nonexistentToken}, - }); - //expect(res.ok()).toBeTruthy(); - //expect(res.status()).toBe(200); -}); - -test('all: list', async ({request}) => { - const ctx = await authenticate({request}); - const cases = [ - {type: "announcement"}, - {type: "blog-post"}, - {type: "exhibit"}, - {type: "event"}, - {type: "organization"}, - {type: "user"}, - {type: "tag"}, - {type: "term"}, - {type: "timetable"}, - {type: "course"}, - - ]; - for (let case_ of cases) { - const res = await ctx.get(`/api/v3/obj/${case_.type}`) - expect(res.ok()).toBeTruthy(); - expect(res.status()).toBe(200); - } -}); - -// todo add tests for comments, likes, announcements, users, ect.. diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml deleted file mode 100644 index 2f2264f6..00000000 --- a/tests/docker-compose.yml +++ /dev/null @@ -1,7 +0,0 @@ -services: - playwright: - network_mode: host - build: . - volumes: - - ${PWD}/..:/proj:rw - #- ${PWD}/../test-results:/proj/test-results:rw diff --git a/tests/example.spec.js b/tests/example.spec.js deleted file mode 100644 index 6f0c5b5d..00000000 --- a/tests/example.spec.js +++ /dev/null @@ -1,19 +0,0 @@ -// @ts-check -const { test, expect } = require('@playwright/test'); - -test('has title', async ({ page }) => { - await page.goto('https://playwright.dev/'); - - // Expect a title "to contain" a substring. - await expect(page).toHaveTitle(/Playwright/); -}); - -test('get started link', async ({ page }) => { - await page.goto('https://playwright.dev/'); - - // Click the get started link. - await page.getByRole('link', { name: 'Get started' }).click(); - - // Expects the URL to contain intro. - await expect(page).toHaveURL(/.*intro/); -});