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,26 +45,18 @@ query MyActivityQuery {
slug slug
} }
mySubmissions { mySubmissions {
edges { id
node { text
id assignment {
text id
assignment { title
id
title
}
}
} }
} }
myAnswers { myAnswers {
edges { id
node { survey {
id id
survey { title
id
title
}
}
} }
} }
myContentBookmarks { myContentBookmarks {

View File

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