Merge branch 'feature/custom-assignments-to-user-created'
This commit is contained in:
commit
90dac6b7e5
|
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 2.0.6 on 2018-10-18 08:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assignments', '0002_auto_20181015_1237'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='customassignment',
|
||||
name='assignment_ptr',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='assignment',
|
||||
name='user_created',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='CustomAssignment',
|
||||
),
|
||||
]
|
||||
|
|
@ -12,15 +12,12 @@ class Assignment(TimeStampedModel):
|
|||
owner = models.ForeignKey(get_user_model(),
|
||||
on_delete=models.PROTECT) # probably don't want to delete all assignments if a user gets deleted
|
||||
module = models.ForeignKey(Module, related_name='assignments', on_delete=models.CASCADE)
|
||||
user_created = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class CustomAssignment(Assignment):
|
||||
pass
|
||||
|
||||
|
||||
class StudentSubmission(TimeStampedModel):
|
||||
text = models.TextField(blank=True)
|
||||
document = models.URLField(blank=True, default='', max_length=255)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
import json
|
||||
|
||||
from django.test import TestCase, RequestFactory
|
||||
from graphene.test import Client
|
||||
|
||||
from api import schema
|
||||
from api.schema import schema
|
||||
from assignments.factories import AssignmentFactory
|
||||
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 CustomAssignmentTestCase(TestCase):
|
||||
def setUp(self):
|
||||
create_users()
|
||||
|
||||
self.teacher = User.objects.get(username='teacher')
|
||||
self.student1 = User.objects.get(username='student1')
|
||||
self.assignment = AssignmentFactory(
|
||||
owner=self.teacher,
|
||||
user_created=True
|
||||
)
|
||||
self.module = ModuleFactory()
|
||||
chapter = Chapter(slug='some-slug', title='chapter')
|
||||
self.module.add_child(instance=chapter)
|
||||
|
||||
self.content_block = ContentBlock(
|
||||
slug='slug',
|
||||
title='title'
|
||||
)
|
||||
|
||||
self.admin = UserFactory(
|
||||
username='test',
|
||||
is_staff=True,
|
||||
is_superuser=True,
|
||||
first_name='Nicol',
|
||||
last_name='Bolas'
|
||||
)
|
||||
|
||||
chapter.specific.add_child(instance=self.content_block)
|
||||
|
||||
request = RequestFactory().get('/')
|
||||
request.user = self.student1
|
||||
self.client = Client(schema=schema, context_value=request)
|
||||
|
||||
def query_module(self):
|
||||
query = '''
|
||||
query Module($slug: String!){
|
||||
module(slug: $slug) {
|
||||
id
|
||||
chapters {
|
||||
edges {
|
||||
node {
|
||||
contentBlocks {
|
||||
edges {
|
||||
node {
|
||||
contents
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
result = self.client.execute(query, variables={
|
||||
'slug': self.module.slug
|
||||
})
|
||||
|
||||
self.assertIsNone(result.get('errors'))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def get_first_contents(result):
|
||||
return result.get('data').get('module').get('chapters').get('edges')[0].get('node').get('contentBlocks').get(
|
||||
'edges')[0].get('node').get('contents')
|
||||
|
||||
def test_module_query(self):
|
||||
result = self.query_module()
|
||||
contents = self.get_first_contents(result)
|
||||
self.assertIsNotNone(contents)
|
||||
|
||||
def test_global_assignment(self):
|
||||
title = 'Assignment'
|
||||
assignment = Assignment.objects.create(
|
||||
title=title,
|
||||
assignment='Assignment text',
|
||||
owner=self.admin,
|
||||
module=self.module
|
||||
)
|
||||
self.content_block.contents = json.dumps([
|
||||
{
|
||||
'type': 'assignment',
|
||||
'value': {
|
||||
'assignment_id': assignment.id
|
||||
}}
|
||||
])
|
||||
self.content_block.save()
|
||||
result = self.query_module()
|
||||
contents = self.get_first_contents(result)
|
||||
self.assertEqual(contents[0].get('value').get('title'), title)
|
||||
|
|
@ -50,6 +50,7 @@ def handle_content_block(content, context, module, allowed_blocks=ALLOWED_BLOCKS
|
|||
assignment=content['value']['assignment'],
|
||||
owner=context.user,
|
||||
module=module,
|
||||
user_created=True
|
||||
)
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ from graphql_relay import to_global_id
|
|||
|
||||
from api.schema import schema
|
||||
from api.utils import get_object
|
||||
from books.factories import ModuleFactory
|
||||
from books.models import ContentBlock, Chapter
|
||||
from books.factories import ModuleFactory
|
||||
from core.factories import UserFactory
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue