Update unit test

This commit is contained in:
Ramon Wenger 2024-02-28 10:54:09 +01:00
parent 0e5eb0af0e
commit de77eeaff3
2 changed files with 146 additions and 136 deletions

View File

@ -45,8 +45,6 @@ query MyActivityQuery {
slug
}
mySubmissions {
edges {
node {
id
text
assignment {
@ -54,19 +52,13 @@ query MyActivityQuery {
title
}
}
}
}
myAnswers {
edges {
node {
id
survey {
id
title
}
}
}
}
myContentBookmarks {
edges {
node {

View File

@ -1,11 +1,17 @@
from api.test_utils import DefaultUserTestCase, create_client
from assignments.factories import AssignmentFactory, StudentSubmissionFactory
from books.factories import ModuleFactory, TopicFactory
from core.logger import get_logger
logger = get_logger(__name__)
class MyAssignmentsTest(DefaultUserTestCase):
def setUp(self):
super(MyAssignmentsTest, self).setUp()
self.assignment = AssignmentFactory(owner=self.teacher)
topic = TopicFactory()
module = ModuleFactory(parent=topic)
self.assignment = AssignmentFactory(owner=self.teacher, module=module)
self.submission1 = StudentSubmissionFactory(
student=self.student1, assignment=self.assignment
@ -18,114 +24,124 @@ class MyAssignmentsTest(DefaultUserTestCase):
def query_my_assignments(self):
query = """
query MyActivityQuery {
myActivity {
edges {
node {
fragment HighlightParts on HighlightNode {
id
contentIndex
paragraphIndex
selectionLength
contentUuid
startPosition
color
note {
text
}
text
page {
# only one of them should be necessary, but the client somehow doesn't like just the Node inline fragment
__typename
... on ContentBlockNode {
id
path
}
... on InstrumentNode {
id
slug
}
... on ModuleNode {
id
slug
path
}
... on ChapterNode {
id
path
slug
}
}
}
query MyActivitiesQuery {
myActivities {
instruments {
id
slug
title
path
highlights {
...HighlightParts
}
bookmarks {
... on InstrumentBookmarkNode {
path
}
}
}
topics {
id
title
modules {
id
slug
title
metaTitle
myHighlights {
...HighlightParts
}
myBookmarks {
... on ChapterBookmarkNode {
chapter {
path
}
path
note {
id
text
}
}
... on ContentBlockBookmarkNode {
id
uuid
path
contentBlock {
id
path
}
note {
id
text
}
}
... on ModuleBookmarkNode {
path
note {
id
text
}
}
}
mySubmissions {
edges {
node {
id
text
assignment {
id
title
}
path
module {
slug
}
}
}
myAnswers {
edges {
node {
id
survey {
path
id
title
}
}
}
}
myContentBookmarks {
edges {
node {
id
uuid
note {
id
text
}
contentBlock {
id
type
contents
}
}
}
}
myChapterBookmarks {
edges {
node {
id
note {
id
text
}
chapter {
id
title
description
}
}
}
}
bookmark {
id
note {
id
text
}
module {
id
teaser
metaTitle
intro
}
}
}
}
}
myInstrumentActivity {
edges {
node {
id
title
contents
type {
id
type
category {
id
name
}
}
slug
bookmarks {
id
uuid
note {
id
text
}
}
}
}
}
}
"""
result = self.client.execute(query)
@ -134,19 +150,21 @@ class MyAssignmentsTest(DefaultUserTestCase):
return result
@staticmethod
def get_content(result):
return result.get("data").get("myActivity").get("edges")
def get_submissions(result):
return (
result.get("data")
.get("myActivities")
.get("topics")[0]
.get("modules")[0]
.get("mySubmissions")
)
def test_my_assignment_query(self):
result = self.query_my_assignments()
contents = self.get_content(result)
self.assertEqual(len(contents), 1)
submissions = self.get_submissions(result)
logger.debug(submissions)
self.assertEqual(len(submissions), 1)
self.assertEqual(
contents[0]
.get("node")
.get("mySubmissions")
.get("edges")[0]
.get("node")
.get("text"),
submissions[0].get("text"),
self.submission1.text,
)