From de77eeaff33af5d6623c3db78b2cabb18b179b1d Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Wed, 28 Feb 2024 10:54:09 +0100 Subject: [PATCH] Update unit test --- client/src/graphql/gql/queries/myActivity.gql | 26 +- .../assignments/tests/test_myassignments.py | 256 ++++++++++-------- 2 files changed, 146 insertions(+), 136 deletions(-) diff --git a/client/src/graphql/gql/queries/myActivity.gql b/client/src/graphql/gql/queries/myActivity.gql index 7d1991c0..90953537 100644 --- a/client/src/graphql/gql/queries/myActivity.gql +++ b/client/src/graphql/gql/queries/myActivity.gql @@ -45,26 +45,18 @@ query MyActivityQuery { slug } mySubmissions { - edges { - node { - id - text - assignment { - id - title - } - } + id + text + assignment { + id + title } } myAnswers { - edges { - node { - id - survey { - id - title - } - } + id + survey { + id + title } } myContentBookmarks { diff --git a/server/assignments/tests/test_myassignments.py b/server/assignments/tests/test_myassignments.py index 62898035..c6659d3b 100644 --- a/server/assignments/tests/test_myassignments.py +++ b/server/assignments/tests/test_myassignments.py @@ -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,115 +24,125 @@ class MyAssignmentsTest(DefaultUserTestCase): def query_my_assignments(self): query = """ - query MyActivityQuery { - myActivity { - edges { - node { - id - title - slug - metaTitle - mySubmissions { - edges { - node { - id - text - assignment { - id - title - } - } - } - } - myAnswers { - edges { - node { - id - survey { - 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 - } - } - } - } - } + 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 { + id + text + assignment { + id + title + path + module { + slug + } + } + } + myAnswers { + id + survey { + path + id + title + } + } + } + } + } + } + """ 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, )