112 lines
5.5 KiB
Python
112 lines
5.5 KiB
Python
from django.test import RequestFactory
|
|
from graphene.test import Client
|
|
from graphql_relay import to_global_id, from_global_id
|
|
|
|
from api.schema import schema
|
|
from api.utils import get_object
|
|
from books.factories import ModuleFactory, ChapterFactory, ContentBlockFactory
|
|
from books.management.commands.migrate_objective_snapshots import migrate_snapshots
|
|
from books.management.commands.migrate_objectives_to_content import migrate_objectives_to_content
|
|
from books.models import Snapshot, ChapterSnapshot
|
|
from books.tests.queries import MODULE_QUERY, SNAPSHOT_MODULE_QUERY, CREATE_SNAPSHOT_MUTATION, APPLY_SNAPSHOT_MUTATION, \
|
|
MODULE_SNAPSHOTS_QUERY, SHARE_SNAPSHOT_MUTATION, UPDATE_SNAPSHOT_MUTATION, DELETE_SNAPSHOT_MUTATION
|
|
from core.tests.base_test import SkillboxTestCase
|
|
from objectives.factories import ObjectiveGroupFactory, ObjectiveFactory
|
|
from users.factories import SchoolClassFactory
|
|
from users.models import User, SchoolClass
|
|
|
|
|
|
class TestObjectivesMigration(SkillboxTestCase):
|
|
@property
|
|
def graphene_client(self):
|
|
return self.get_client()
|
|
|
|
def setUp(self):
|
|
self.createDefault()
|
|
self.client = self.get_client()
|
|
# teacher will create snapshot
|
|
self.slug = 'some-module'
|
|
|
|
self.module = ModuleFactory(slug=self.slug)
|
|
self.skillbox_class = SchoolClass.objects.get(name='skillbox')
|
|
self.teacher2 = User.objects.get(username='teacher2')
|
|
self.second_class_name = 'second_class'
|
|
self.second_class = SchoolClass.objects.get(name=self.second_class_name)
|
|
self.admin = User.objects.get(username='admin')
|
|
|
|
# we make a snapshot S of the module M
|
|
# snapshot S looks like module M for school class X
|
|
# module M has a chapter
|
|
self.chapter = ChapterFactory(parent=self.module, slug='some-chapter', owner=self.admin)
|
|
ChapterFactory(parent=self.module, slug='some-other-chapter', owner=self.admin)
|
|
|
|
objective_group = ObjectiveGroupFactory(module=self.module, title='Gesellschaft')
|
|
second_objective_group = ObjectiveGroupFactory(module=self.module, title='Sprache & Kommunikation')
|
|
|
|
self.visible_objective = ObjectiveFactory(text='visible-objective', group=objective_group)
|
|
self.hidden_objective = ObjectiveFactory(text='hidden-objective', group=objective_group)
|
|
self.custom_objective = ObjectiveFactory(text='custom-objective', group=objective_group, owner=self.teacher)
|
|
self.custom_hidden_objective = ObjectiveFactory(text='custom-hidden-objective', group=objective_group,
|
|
owner=self.teacher)
|
|
|
|
self.visible_objective = ObjectiveFactory(text='objective1', group=second_objective_group)
|
|
|
|
self.hidden_objective.hidden_for.add(self.skillbox_class)
|
|
self.hidden_objective.save()
|
|
|
|
self.custom_objective.visible_for.add(self.skillbox_class)
|
|
self.custom_objective.save()
|
|
|
|
second_objective_group.hidden_for.add(self.skillbox_class)
|
|
second_objective_group.save()
|
|
|
|
self.custom_hidden_objective.visible_for.remove(self.skillbox_class)
|
|
|
|
migrate_objectives_to_content()
|
|
|
|
def test_objectives_migration_hidden_default_content(self):
|
|
result = self.client.execute(MODULE_QUERY, variables={
|
|
'slug': self.module.slug
|
|
})
|
|
module = result.data['module']
|
|
chapter1 = module['chapters'][0]
|
|
default_content, _, _ = chapter1['contentBlocks']
|
|
|
|
# default content block (Verlagsinhalte) exists but is hidden (since one objective is hidden for this class)
|
|
self.assertEqual(default_content['title'], 'Gesellschaft')
|
|
self.assertEqual(default_content['originalCreator'], None)
|
|
self.assertEqual(default_content['contents'][0]['value']['text'],
|
|
'<ul><li>visible-objective</li><li>hidden-objective</li></ul>')
|
|
self.assertEqual(default_content['hiddenFor'], [{'name': 'skillbox'}])
|
|
|
|
def test_objectives_migration_hidden_default_content_creates_custom_content(self):
|
|
result = self.client.execute(MODULE_QUERY, variables={
|
|
'slug': self.module.slug
|
|
})
|
|
module = result.data['module']
|
|
chapter1 = module['chapters'][0]
|
|
_, custom, _ = chapter1['contentBlocks']
|
|
|
|
# default content block (Verlagsinhalte) exists but is hidden (since one objective is hidden for this class)
|
|
self.assertEqual(custom['title'], 'Gesellschaft')
|
|
self.assertTrue(custom['originalCreator'] is not None)
|
|
self.assertEqual(custom['hiddenFor'], [])
|
|
self.assertEqual(custom['visibleFor'], [{'name': 'skillbox'}])
|
|
self.assertEqual(custom['contents'][0]['value']['text'],
|
|
'<ul><li>visible-objective</li><li>custom-objective</li></ul>')
|
|
|
|
def test_objectives_migration_hidden_default_content_creates_hidden_content_block(self):
|
|
result = self.client.execute(MODULE_QUERY, variables={
|
|
'slug': self.module.slug
|
|
})
|
|
module = result.data['module']
|
|
chapter1 = module['chapters'][0]
|
|
_, _, hidden_custom = chapter1['contentBlocks']
|
|
|
|
# default content block (Verlagsinhalte) exists but is hidden (since one objective is hidden for this class)
|
|
self.assertEqual(hidden_custom['title'], 'Sprache & Kommunikation')
|
|
self.assertTrue(hidden_custom['originalCreator'] is None)
|
|
self.assertEqual(hidden_custom['hiddenFor'], [])
|
|
self.assertEqual(hidden_custom['visibleFor'], [])
|
|
self.assertEqual(hidden_custom['contents'][0]['value']['text'], '<ul><li>objective1</li></ul>')
|