Remove school class from new room mutation
This commit is contained in:
parent
07a7079fdf
commit
6b3f84a619
|
|
@ -0,0 +1,4 @@
|
|||
class GQLResult:
|
||||
def __init__(self, result):
|
||||
self.data = result.get('data')
|
||||
self.errors = result.get('errors')
|
||||
|
|
@ -38,12 +38,13 @@ class AddRoom(MutateRoom):
|
|||
|
||||
@classmethod
|
||||
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||
|
||||
if not info.context.user.has_perm('users.can_manage_school_class_content'):
|
||||
user = info.context.user
|
||||
if not user.has_perm('users.can_manage_school_class_content'):
|
||||
return cls(room=None, errors=['not allowed'])
|
||||
|
||||
room_data = kwargs.get('room')
|
||||
room_data['school_class'] = get_object(SchoolClass, room_data.get('school_class').id).id
|
||||
school_class_id = user.selected_class.id
|
||||
room_data['school_class'] = school_class_id
|
||||
serializer = RoomSerializer(data=room_data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
from graphql_relay import to_global_id
|
||||
|
||||
from core.tests.base_test import SkillboxTestCase
|
||||
from core.tests.helpers import GQLResult
|
||||
from rooms.factories import CommentFactory, RoomEntryFactory, RoomFactory
|
||||
|
||||
|
||||
class GQLResult:
|
||||
def __init__(self, result):
|
||||
self.data = result.get('data')
|
||||
self.errors = result.get('errors')
|
||||
|
||||
|
||||
class CommentTestCase(SkillboxTestCase):
|
||||
def setUp(self) -> None:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
from graphql_relay import from_global_id
|
||||
|
||||
from core.tests.base_test import SkillboxTestCase
|
||||
from core.tests.helpers import GQLResult
|
||||
|
||||
class GQLRoom:
|
||||
def __init__(self, room_data):
|
||||
self.id = room_data.get('id')
|
||||
self.slug = room_data.get('slug')
|
||||
self.title = room_data.get('title')
|
||||
self.entry_count = room_data.get('entryCount')
|
||||
self.appearance = room_data.get('appearance')
|
||||
self.description = room_data.get('description')
|
||||
self.school_class = room_data.get('schoolClass')
|
||||
|
||||
class AddRoomResult:
|
||||
def __init__(self, result: GQLResult):
|
||||
self.room = GQLRoom(result.data.get('addRoom').get('room'))
|
||||
# id
|
||||
# slug
|
||||
# title
|
||||
# entryCount
|
||||
# appearance
|
||||
# description
|
||||
# schoolClass {
|
||||
# id
|
||||
# name
|
||||
# }
|
||||
|
||||
class NewRoomMutationTestCase(SkillboxTestCase):
|
||||
def setUp(self) -> None:
|
||||
self.createDefault()
|
||||
|
||||
def test_create_new_room(self):
|
||||
mutation = """
|
||||
mutation AddRoom($input: AddRoomInput!){
|
||||
addRoom(input: $input) {
|
||||
room {
|
||||
id
|
||||
slug
|
||||
title
|
||||
entryCount
|
||||
appearance
|
||||
description
|
||||
schoolClass {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
title = 'some title'
|
||||
appearance='blue'
|
||||
res = self.get_client().execute(mutation, variables={
|
||||
'input': {
|
||||
'room': {
|
||||
'title': title,
|
||||
# description
|
||||
'appearance': appearance
|
||||
}
|
||||
}
|
||||
})
|
||||
result = GQLResult(res)
|
||||
self.assertIsNone(result.errors)
|
||||
room = GQLRoom(result.data.get('addRoom').get('room'))
|
||||
self.assertEqual(room.title, title)
|
||||
self.assertEqual(room.appearance, appearance)
|
||||
self.assertIsNone(room.description)
|
||||
self.assertEqual(int(from_global_id(room.school_class.get('id'))[1]), self.teacher.selected_class.id)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue