Add assignment solution to mutation, add unit tests
This commit is contained in:
parent
41d8e973e8
commit
8987a99d61
|
|
@ -26,6 +26,7 @@ class ContentElementValueInput(InputObjectType):
|
||||||
title = graphene.String(description="To be used for image_block, assignment type")
|
title = graphene.String(description="To be used for image_block, assignment type")
|
||||||
assignment = graphene.String(description="To be used for assignment type")
|
assignment = graphene.String(description="To be used for assignment type")
|
||||||
id = 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):
|
class ContentElementInput(InputObjectType):
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ def handle_content_block(
|
||||||
assignment = Assignment.objects.create(
|
assignment = Assignment.objects.create(
|
||||||
title=value.get("title"),
|
title=value.get("title"),
|
||||||
assignment=value.get("assignment"),
|
assignment=value.get("assignment"),
|
||||||
|
solution=value.get("solution"),
|
||||||
owner=context.user,
|
owner=context.user,
|
||||||
module=module,
|
module=module,
|
||||||
user_created=True,
|
user_created=True,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ mutation AddContentBlock($input: AddContentBlockInput!) {
|
||||||
addContentBlock(input: $input) {
|
addContentBlock(input: $input) {
|
||||||
newContentBlock {
|
newContentBlock {
|
||||||
id
|
id
|
||||||
|
contents
|
||||||
}
|
}
|
||||||
errors
|
errors
|
||||||
clientMutationId
|
clientMutationId
|
||||||
|
|
@ -106,7 +107,6 @@ class TestCreateCustomContentBlock:
|
||||||
)
|
)
|
||||||
assert new_content_block.title == content_block_title
|
assert new_content_block.title == content_block_title
|
||||||
content_list_content = new_content_block.contents.raw_data[0]
|
content_list_content = new_content_block.contents.raw_data[0]
|
||||||
logger.debug(content_list_content)
|
|
||||||
content_list_id = content_list_content.get("id")
|
content_list_id = content_list_content.get("id")
|
||||||
assert content_list_id is not None
|
assert content_list_id is not None
|
||||||
text_content = content_list_content.get("value")[0]
|
text_content = content_list_content.get("value")[0]
|
||||||
|
|
@ -212,7 +212,6 @@ class TestCreateCustomContentBlock:
|
||||||
input = create_block_input(content_type=content_type, value=value)
|
input = create_block_input(content_type=content_type, value=value)
|
||||||
new_content_block = self._add_content_block(client=client, input=input)
|
new_content_block = self._add_content_block(client=client, input=input)
|
||||||
assignment_block = new_content_block.contents.raw_data[0]
|
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("id") is not None
|
||||||
assert assignment_block.get("value").get("assignment_id") is not None
|
assert assignment_block.get("value").get("assignment_id") is not None
|
||||||
assert Assignment.objects.count() == 1
|
assert Assignment.objects.count() == 1
|
||||||
|
|
@ -285,6 +284,50 @@ class TestCreateCustomContentBlock:
|
||||||
value.get("text")
|
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):
|
# def test_add_readonly(self):
|
||||||
# content_type = "readonly"
|
# content_type = "readonly"
|
||||||
# value = {"text": "some subtitle"}
|
# value = {"text": "some subtitle"}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue