-
Notifications
You must be signed in to change notification settings - Fork 167
Frontend regression testing #2566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fekoch
wants to merge
22
commits into
e-valuation:main
Choose a base branch
from
fekoch:frontend-regression-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
93fad2e
Implement visual regression testing
fekoch 0ac4044
vrt for grades:semester_view
fekoch 1dcb90b
structure vrt tests
fekoch 73e2327
add command
fekoch 976a8a1
nicer assertion error
fekoch 577f125
add to ci
fekoch 302c525
set branchname via context
fekoch 012021d
remove _-assignment
fekoch 2bb0fd3
simple baker.make calls, reposition decorators
fekoch f476414
move state to testclass
fekoch f1e50c7
refactor VisualRegressionTestCase
fekoch 4fdb85a
pretty
fekoch 809ac6d
set selenium & vrt tag on tests
fekoch ef3e7f0
format
fekoch 564acd6
lint
fekoch e3edc19
make linter happy
fekoch aafbf38
fixup startoptions setup evap
fekoch 1752b74
add missing import
fekoch bd9c38d
use correct secrets & vars
fekoch f4b4496
pull new code
fekoch 8640520
import self-signed certificate
fekoch 7ca97cd
fix: stop displaying test as running
fekoch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| name: Visual Test Suite | ||
| on: | ||
| pull_request_target: | ||
| types: [opened, synchronize] | ||
| jobs: | ||
| visual-regression-tests: | ||
| runs-on: ubuntu-22.04 | ||
| name: Visual Regression Tests | ||
| env: | ||
| VRT_APIURL: ${{ vars.VRT_APIURL }} | ||
| VRT_APIKEY: ${{ secrets.VRT_APIKEY }} | ||
| VRT_PROJECT: ${{ secrets.VRT_PROJECT }} | ||
| VRT_BRANCHNAME: ${{ github.event.pull_request.head.label }} | ||
| steps: | ||
| - name: Check if user is collaborator | ||
| uses: actions/github-script@v8 | ||
| env: | ||
| TRIGGERING_USERNAME: ${{ github.triggering_actor }} | ||
| with: | ||
| script: | | ||
| const username = process.env.TRIGGERING_USERNAME; | ||
|
|
||
| const isCollaborator = await github.rest.repos.checkCollaborator({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| username: username | ||
| }) | ||
| .then(({status}) => status === 204) | ||
| .catch((error) => { | ||
| if (error.status === 404) return false; | ||
| throw error; | ||
| }); | ||
|
|
||
| if(!isCollaborator) { | ||
| console.error(`Insufficient privileges, ${username} is not a collaborator`); | ||
| process.exit(1) | ||
| } | ||
|
|
||
| console.log(`User ${username} is a project collaborator, continuing...`) | ||
|
|
||
| - name: Checkout PR | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| submodules: true | ||
| repository: '${{ github.event.pull_request.head.repo.full_name }}' | ||
| ref: '${{ github.event.pull_request.head.ref }}' | ||
| - uses: ./.github/setup_evap | ||
| with: | ||
| shell: .#evap-frontend-dev | ||
| npm-ci: true | ||
| start-db: true | ||
| - name: Load Self-Signed Certificate | ||
| run: | | ||
| echo "${{ secrets.VRT_SSL_CERTIFICATE }}" > evap-vrt.crt | ||
| sudo cp evap-vrt.crt /usr/local/share/ca-certificates/ | ||
| sudo update-ca-certificates | ||
| - name: Run visual regression tests | ||
| run: python manage.py vrt_test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import os.path | ||
| import sys | ||
| from subprocess import run | ||
|
|
||
| from django.core.management import call_command | ||
| from django.core.management.base import BaseCommand | ||
|
|
||
| from evap.evaluation.management.commands.tools import subprocess_run_or_exit | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = "Run the visual regression testing suite" | ||
|
|
||
| def handle(self, *args, **options): | ||
| assert os.environ.get("VRT_APIURL"), "env var VRT_APIURL must be set" | ||
| assert os.environ.get("VRT_APIKEY"), "env var VRT_APIKEY must be set" | ||
| assert os.environ.get("VRT_PROJECT"), "env var VRT_PROJECT must be set" | ||
|
|
||
| commit_hash = os.environ.get("VRT_CIBUILDID") | ||
| if not commit_hash: | ||
| commit_hash = run(["git", "rev-parse", "--short", "HEAD"], capture_output=True, check=False) | ||
| if commit_hash.returncode != 0: | ||
| self.stderr.write(self.style.ERROR("Could not get commit hash: " + str(commit_hash.stderr))) | ||
| sys.exit(1) | ||
| commit_hash = commit_hash.stdout.decode().strip() | ||
| self.stdout.write(self.style.NOTICE(f"using VRT_CIBUILDID = '{commit_hash}'")) | ||
| os.environ["VRT_CIBUILDID"] = commit_hash | ||
|
|
||
| branch_name = os.environ.get("VRT_BRANCHNAME") | ||
| if not branch_name: | ||
| branch_name = run(["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, check=False) | ||
| if branch_name.returncode != 0: | ||
| self.stderr.write(self.style.ERROR("Could not get branch name: " + branch_name.stderr)) | ||
| sys.exit(1) | ||
| branch_name = branch_name.stdout.decode().strip() | ||
| self.stdout.write(self.style.NOTICE(f"using VRT_BRANCHNAME = '{branch_name}'")) | ||
| os.environ["VRT_BRANCHNAME"] = branch_name | ||
|
|
||
| call_command("ts", "compile") | ||
| call_command("scss") | ||
|
|
||
| # subprocess call so our sys.argv check in settings.py works | ||
| subprocess_run_or_exit(["./manage.py", "test", "--tag", "vrt"], self.stdout) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from model_bakery import baker | ||
|
|
||
| from evap.evaluation.models import Course, Evaluation, Group, Semester | ||
| from evap.evaluation.tests.tools import VisualRegressionTestCase | ||
|
|
||
|
|
||
| class GradesViewTest(VisualRegressionTestCase): | ||
| def test_grades_semester_view(self): | ||
| baker.seed(31902) | ||
|
|
||
| semester = baker.make(Semester) | ||
|
|
||
| self.manager.groups.add(Group.objects.get(name="Grade publisher")) | ||
| with self.enter_staff_mode(): | ||
| self.selenium.get(self.reverse("grades:semester_view", args=[semester.id])) | ||
| self.trigger_screenshot("grades:semester - no courses") | ||
|
|
||
| courses = baker.make(Course, semester=semester, _quantity=30) | ||
| baker.make( | ||
| Evaluation, | ||
| course=iter(courses), | ||
| wait_for_grade_upload_before_publishing=True, | ||
| state=Evaluation.State.IN_EVALUATION, | ||
| _quantity=len(courses), | ||
| ) | ||
| self.selenium.get(self.reverse("grades:semester_view", args=[semester.id])) | ||
|
|
||
| self.trigger_screenshot("grades:semester - 30 courses") |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also need to declare this dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, roughly how painful would it be to do this without
requests? If it's just 10-ish more lines of python withurllib, I'm tempted to use that insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, we have requests in our uv.lock either way through mozilla-django-oidc; I don't have a strong opinion towards either direction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah if we already install it anyway, fine with me
(although mozilla-django-oidc is a candidate for removal as soon as possible :D)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The python standard library documentation explicitly recommends using the Requests package: https://docs.python.org/3/library/http.client.html
Considering that, I think it is fair to explicitly depend on it.