add myActivity query
This commit is contained in:
parent
f8c1f372cb
commit
fa98141f3c
|
|
@ -6,7 +6,7 @@ from graphene_django.debug import DjangoDebug
|
|||
# noinspection PyUnresolvedReferences
|
||||
from api import graphene_wagtail # Keep this import exactly here, it's necessary for StreamField conversion
|
||||
from assignments.schema.mutations import AssignmentMutations
|
||||
from assignments.schema.queries import AssignmentsQuery, StudentSubmissionQuery
|
||||
from assignments.schema.queries import AssignmentsQuery, StudentSubmissionQuery, MyActivityQuery
|
||||
from basicknowledge.queries import BasicKnowledgeQuery
|
||||
from books.schema.mutations.main import BookMutations
|
||||
from books.schema.queries import BookQuery
|
||||
|
|
@ -22,7 +22,7 @@ from users.mutations import ProfileMutations
|
|||
|
||||
|
||||
class Query(UsersQuery, RoomsQuery, ObjectivesQuery, BookQuery, AssignmentsQuery, StudentSubmissionQuery,
|
||||
BasicKnowledgeQuery, PortfolioQuery, graphene.ObjectType):
|
||||
BasicKnowledgeQuery, PortfolioQuery, MyActivityQuery, graphene.ObjectType):
|
||||
node = relay.Node.Field()
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ import random
|
|||
import factory
|
||||
|
||||
from books.factories import ModuleFactory
|
||||
from .models import Assignment
|
||||
from .models import Assignment, StudentSubmission
|
||||
|
||||
from core.factories import fake
|
||||
|
||||
|
||||
class AssignmentFactory(factory.django.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Assignment
|
||||
|
|
@ -14,3 +15,12 @@ class AssignmentFactory(factory.django.DjangoModelFactory):
|
|||
title = factory.LazyAttribute(lambda x: fake.sentence(nb_words=random.randint(4, 8)))
|
||||
assignment = factory.LazyAttribute(lambda x: fake.sentence(nb_words=random.randint(4, 8)))
|
||||
module = factory.SubFactory(ModuleFactory)
|
||||
|
||||
|
||||
class StudentSubmissionFactory(factory.django.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = StudentSubmission
|
||||
|
||||
text = factory.LazyAttribute(lambda x: fake.sentence(nb_words=random.randint(4, 8)))
|
||||
assignment = factory.SubFactory(AssignmentFactory)
|
||||
final = False
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from graphene import relay
|
||||
from graphene_django.filter import DjangoFilterConnectionField
|
||||
|
||||
from assignments.models import StudentSubmission
|
||||
from assignments.schema.types import AssignmentNode, StudentSubmissionNode
|
||||
|
||||
|
||||
|
|
@ -12,3 +13,11 @@ class AssignmentsQuery(object):
|
|||
class StudentSubmissionQuery(object):
|
||||
student_submission = relay.Node.Field(StudentSubmissionNode)
|
||||
|
||||
|
||||
class MyActivityQuery(object):
|
||||
# my_activity = relay.Node.Field(StudentSubmissionNode)
|
||||
my_activity = DjangoFilterConnectionField(StudentSubmissionNode)
|
||||
|
||||
def resolve_my_activity(self, info, **kwargs):
|
||||
user = info.context.user
|
||||
return StudentSubmission.objects.filter(student=user)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from books.utils import are_solutions_enabled_for
|
|||
class StudentSubmissionNode(DjangoObjectType):
|
||||
class Meta:
|
||||
model = StudentSubmission
|
||||
filter_fields = []
|
||||
interfaces = (relay.Node,)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# ITerativ GmbH
|
||||
# http://www.iterativ.ch/
|
||||
#
|
||||
# Copyright (c) 2019 ITerativ GmbH. All rights reserved.
|
||||
#
|
||||
# Created on 2019-04-11
|
||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||
from django.conf import settings
|
||||
import json
|
||||
|
||||
from django.test import TestCase, RequestFactory
|
||||
from graphene.test import Client
|
||||
|
||||
from api import schema
|
||||
from api.schema import schema
|
||||
from api.test_utils import DefaultUserTestCase, create_client
|
||||
from assignments.factories import AssignmentFactory, StudentSubmissionFactory
|
||||
from assignments.models import Assignment
|
||||
from books.factories import ModuleFactory
|
||||
from books.models import ContentBlock, Chapter
|
||||
from core.factories import UserFactory
|
||||
from users.models import User
|
||||
from users.services import create_users
|
||||
|
||||
|
||||
class MyAssignemntsText(DefaultUserTestCase):
|
||||
def setUp(self):
|
||||
super(MyAssignemntsText, self).setUp()
|
||||
self.assignment = AssignmentFactory(
|
||||
owner=self.teacher
|
||||
)
|
||||
|
||||
self.submission1 = StudentSubmissionFactory(student=self.student1, assignment=self.assignment)
|
||||
self.submission2 = StudentSubmissionFactory(student=self.student2, assignment=self.assignment)
|
||||
|
||||
self.client = create_client(self.student1)
|
||||
|
||||
def query_my_assignments(self):
|
||||
query = '''
|
||||
query {
|
||||
myActivity {
|
||||
edges {
|
||||
node {
|
||||
text
|
||||
assignment {
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
result = self.client.execute(query)
|
||||
|
||||
self.assertIsNone(result.get('errors'))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def get_content(result):
|
||||
return result.get('data').get('myActivity').get('edges')
|
||||
|
||||
def test_my_assignment_query(self):
|
||||
result = self.query_my_assignments()
|
||||
contents = self.get_content(result)
|
||||
self.assertEqual(len(contents), 1)
|
||||
self.assertEquals(contents[0].get('node').get('text'), self.submission1.text)
|
||||
|
||||
Loading…
Reference in New Issue