From 8987a99d61e1f001acc23896b23a664b6ba9ce23 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Tue, 30 Apr 2024 18:24:48 +0200 Subject: [PATCH] Add assignment solution to mutation, add unit tests --- server/books/schema/inputs.py | 1 + server/books/schema/mutations/utils.py | 1 + .../tests/test_create_custom_content_block.py | 47 ++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/server/books/schema/inputs.py b/server/books/schema/inputs.py index 0afd5f86..d3312390 100644 --- a/server/books/schema/inputs.py +++ b/server/books/schema/inputs.py @@ -26,6 +26,7 @@ class ContentElementValueInput(InputObjectType): title = graphene.String(description="To be used for image_block, assignment type") assignment = graphene.String(description="To be used for assignment type") id = graphene.String(description="To be used for assignment type") + solution = graphene.String(description="To be used for assignment type") class ContentElementInput(InputObjectType): diff --git a/server/books/schema/mutations/utils.py b/server/books/schema/mutations/utils.py index 322a96fe..116fb0a3 100644 --- a/server/books/schema/mutations/utils.py +++ b/server/books/schema/mutations/utils.py @@ -115,6 +115,7 @@ def handle_content_block( assignment = Assignment.objects.create( title=value.get("title"), assignment=value.get("assignment"), + solution=value.get("solution"), owner=context.user, module=module, user_created=True, diff --git a/server/books/tests/test_create_custom_content_block.py b/server/books/tests/test_create_custom_content_block.py index 605ade89..cfc3511f 100644 --- a/server/books/tests/test_create_custom_content_block.py +++ b/server/books/tests/test_create_custom_content_block.py @@ -14,6 +14,7 @@ mutation AddContentBlock($input: AddContentBlockInput!) { addContentBlock(input: $input) { newContentBlock { id + contents } errors clientMutationId @@ -106,7 +107,6 @@ class TestCreateCustomContentBlock: ) assert new_content_block.title == content_block_title content_list_content = new_content_block.contents.raw_data[0] - logger.debug(content_list_content) content_list_id = content_list_content.get("id") assert content_list_id is not None text_content = content_list_content.get("value")[0] @@ -212,7 +212,6 @@ class TestCreateCustomContentBlock: input = create_block_input(content_type=content_type, value=value) new_content_block = self._add_content_block(client=client, input=input) assignment_block = new_content_block.contents.raw_data[0] - logger.debug(assignment_block) assert assignment_block.get("id") is not None assert assignment_block.get("value").get("assignment_id") is not None assert Assignment.objects.count() == 1 @@ -285,6 +284,50 @@ class TestCreateCustomContentBlock: value.get("text") ) + def test_add_assignment_without_solution(self, teacher, get_client): + content_type = "assignment" + assignment_text = "assignment text" + assignment_title = "some title" + value = { + "title": assignment_title, + "assignment": assignment_text, + } + client = get_client(teacher) + assert Assignment.objects.count() == 0 + input = create_block_input(content_type=content_type, value=value) + new_content_block = self._add_content_block(client=client, input=input) + assert Assignment.objects.count() == 1 + assignment_block = new_content_block.contents.raw_data[0] + assert assignment_block.get("id") is not None + assignment_id = assignment_block.get("value").get("assignment_id") + assignment = Assignment.objects.get(id=assignment_id) + assert assignment.assignment == assignment_text + assert assignment.title == assignment_title + assert assignment.solution is None + + def test_add_assignment_with_solution(self, teacher, get_client): + content_type = "assignment" + assignment_text = "assignment text" + assignment_title = "some title" + assignment_solution = "some solution" + value = { + "solution": assignment_solution, + "title": assignment_title, + "assignment": assignment_text, + } + client = get_client(teacher) + assert Assignment.objects.count() == 0 + input = create_block_input(content_type=content_type, value=value) + new_content_block = self._add_content_block(client=client, input=input) + assert Assignment.objects.count() == 1 + assignment_block = new_content_block.contents.raw_data[0] + assert assignment_block.get("id") is not None + assignment_id = assignment_block.get("value").get("assignment_id") + assignment = Assignment.objects.get(id=assignment_id) + assert assignment.assignment == assignment_text + assert assignment.title == assignment_title + assert assignment.solution == assignment_solution + # def test_add_readonly(self): # content_type = "readonly" # value = {"text": "some subtitle"}