Skip to content

Commit

Permalink
Test school update (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 authored Feb 6, 2024
1 parent a8ff363 commit 0af7c1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
44 changes: 25 additions & 19 deletions backend/api/tests/views/test_school.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,50 @@
class TestSchoolViewSet(ModelViewSetTestCase[School]):
basename = "school"
model_view_set_class = SchoolViewSet
fixtures = ["non_school_teacher"]
fixtures = ["non_school_teacher", "school_1"]

def test_get_permissions__bulk(self):
"""
No one is allowed to perform bulk actions.
"""
"""No one is allowed to perform bulk actions."""

self.assert_get_permissions(
permissions=[AllowNone()],
action="bulk",
)

def test_get_permissions__list(self):
"""
No one is allowed to list schools.
"""
"""No one is allowed to list schools."""

self.assert_get_permissions(
permissions=[AllowNone()],
action="list",
)

def test_get_permissions__create(self):
"""
Only teachers not in a school can create a school.
"""
"""Only teachers not in a school can create a school."""

self.assert_get_permissions(
permissions=[IsTeacher(), NOT(InSchool())],
action="create",
)

def test_get_permissions__update(self):
"""
Only admin-teachers in a school can update a school.
"""
"""Only admin-teachers in a school can update a school."""

self.assert_get_permissions(
permissions=[IsTeacher(is_admin=True), InSchool()],
action="update",
)

def test_get_permissions__retrieve(self):
"""
Anyone in a school can retrieve a school.
"""
"""Anyone in a school can retrieve a school."""

self.assert_get_permissions(
permissions=[InSchool()],
action="retrieve",
)

def test_create(self):
"""
Can successfully create a school.
"""
"""Can successfully create a school."""

self.client.login_non_school_teacher(
email="[email protected]",
Expand All @@ -85,3 +73,21 @@ def test_create(self):
"country": "GB",
},
)

def test_partial_update(self):
"""Can successfully update a school."""

user = self.client.login_school_teacher(
is_admin=True,
email="[email protected]",
password="password",
)

self.client.partial_update(
user.teacher.school,
{
"name": "NewSchoolName",
"uk_county": "Surrey",
"country": "GB",
},
)
4 changes: 1 addition & 3 deletions backend/api/views/school.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
Created on 23/01/2024 at 17:53:50(+00:00).
"""

import typing as t

from codeforlife.permissions import NOT, AllowNone, Permission
from codeforlife.permissions import NOT, AllowNone
from codeforlife.user.permissions import InSchool, IsTeacher
from codeforlife.user.views import SchoolViewSet as _SchoolViewSet

Expand Down

0 comments on commit 0af7c1b

Please sign in to comment.