Skip to content
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

Polish tests #327

Merged
merged 15 commits into from
May 9, 2024
4 changes: 3 additions & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"qwtel.sqlite-viewer",
"njpwerner.autodocstring",
"tamasfe.even-better-toml",
"github.vscode-github-actions"
"github.vscode-github-actions",
"codecov.codecov",
"ritwickdey.liveserver"
]
}
},
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
jobs:
test-backend:
uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-python-code.yaml@main
secrets: inherit
with:
working-directory: backend

Expand Down
3 changes: 3 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"type": "debugpy"
},
{
"env": {
"PYTEST_ADDOPTS": "--no-cov"
},
"justMyCode": false,
"name": "Pytest",
"presentation": {
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
"python.testing.cwd": "${workspaceFolder}/backend",
"python.testing.pytestArgs": [
"-n=auto",
"--cov=.",
"--cov-report=html",
"-c=pyproject.toml",
"."
],
Expand Down
4 changes: 2 additions & 2 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name = "pypi"
# 5. Run `pipenv install --dev` in your terminal.

[packages]
codeforlife = {ref = "v0.16.2", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
codeforlife = {ref = "v0.16.7", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
# 🚫 Don't add [packages] below that are inhertited from the CFL package.
# TODO: check if we need the below packages
whitenoise = "==6.5.0"
Expand All @@ -47,7 +47,7 @@ google-cloud-container = "==2.3.0"
# "django-anymail[amazon_ses]" = "==7.0.*"

[dev-packages]
codeforlife = {ref = "v0.16.2", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
codeforlife = {ref = "v0.16.7", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
# codeforlife = {file = "../../codeforlife-package-python", editable = true, extras = ["dev"]}
# 🚫 Don't add [dev-packages] below that are inhertited from the CFL package.
# TODO: check if we need the below packages
Expand Down
119 changes: 55 additions & 64 deletions backend/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions backend/api/fixtures/school_1_teacher_invitations.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,22 @@
"from_teacher": 7,
"invited_teacher_first_name": "Invited",
"invited_teacher_last_name": "Teacher",
"invited_teacher_email": "[email protected]",
"invited_teacher_is_admin": false,
"invited_teacher_email": "[email protected]",
"invited_teacher_is_admin": true,
"expiry": "9999-02-09 20:26:08.298402+00:00"
}
},
{
"model": "common.schoolteacherinvitation",
"pk": 4,
"fields": {
"token": "pbkdf2_sha256$260000$hbsAadmrRo744BTM6NofUb$ePs/7vi6sSzOPpiWxNhXMZnNnE7aXOpzIhxrAa/rdiU=",
"school": 2,
"from_teacher": 7,
"invited_teacher_first_name": "Invited",
"invited_teacher_last_name": "Independent",
"invited_teacher_email": "[email protected]",
"invited_teacher_is_admin": true,
"expiry": "9999-02-09 20:26:08.298402+00:00"
}
}
Expand Down
30 changes: 30 additions & 0 deletions backend/api/fixtures/school_2_teacher_invitations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"model": "common.schoolteacherinvitation",
"pk": 5,
"fields": {
"token": "pbkdf2_sha256$260000$hbsAadmrRo744BTM6NofUb$ePs/7vi6sSzOPpiWxNhXMZnNnE7aXOpzIhxrAa/rdiU=",
"school": 3,
"from_teacher": 8,
"invited_teacher_first_name": "Invited",
"invited_teacher_last_name": "Teacher",
"invited_teacher_email": "[email protected]",
"invited_teacher_is_admin": false,
"expiry": "9999-02-09 20:26:08.298402+00:00"
}
},
{
"model": "common.schoolteacherinvitation",
"pk": 6,
"fields": {
"token": "pbkdf2_sha256$260000$hbsAadmrRo744BTM6NofUb$ePs/7vi6sSzOPpiWxNhXMZnNnE7aXOpzIhxrAa/rdiU=",
"school": 3,
"from_teacher": 8,
"invited_teacher_first_name": "Invited",
"invited_teacher_last_name": "Teacher",
"invited_teacher_email": "[email protected]",
"invited_teacher_is_admin": false,
"expiry": "9999-02-09 20:26:08.298402+00:00"
}
}
]
6 changes: 6 additions & 0 deletions backend/api/permissions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
© Ocado Group
Created on 24/04/2024 at 11:57:02(+01:00).
"""

from .is_invited_school_teacher import IsInvitedSchoolTeacher
32 changes: 32 additions & 0 deletions backend/api/permissions/is_invited_school_teacher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
© Ocado Group
Created on 24/04/2024 at 11:57:38(+01:00).
"""

import typing as t

from codeforlife.permissions import BasePermission
from django.contrib.auth.hashers import check_password
from rest_framework.viewsets import ModelViewSet

from ..models import SchoolTeacherInvitation


class IsInvitedSchoolTeacher(BasePermission):
"""The request is being made by the teacher invited to join a school."""

def has_permission( # type: ignore[override]
self, request, view: ModelViewSet
):
pk: t.Optional[str] = view.kwargs.get(
view.lookup_url_kwarg or view.lookup_field
)

token: t.Optional[str] = request.data.get("token")

if pk is not None and token is not None:
invitation = SchoolTeacherInvitation.objects.get(pk=int(pk))

return check_password(token, invitation.token)

return False
6 changes: 5 additions & 1 deletion backend/api/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from .auth_factor import AuthFactorSerializer
from .klass import ClassSerializer
from .school import SchoolSerializer
from .school_teacher_invitation import SchoolTeacherInvitationSerializer
from .school_teacher_invitation import (
AcceptSchoolTeacherInvitationSerializer,
RefreshSchoolTeacherInvitationSerializer,
SchoolTeacherInvitationSerializer,
)
from .student import (
CreateStudentSerializer,
ReleaseStudentSerializer,
Expand Down
Loading
Loading