Add objective change count

This commit is contained in:
Ramon Wenger 2021-05-25 13:46:23 +02:00
parent 1f85defb2a
commit c257447748
2 changed files with 19 additions and 6 deletions

View File

@ -156,10 +156,10 @@ class SnapshotNode(DjangoObjectType):
@staticmethod
def resolve_changes(parent, info, **kwargs):
return {
'hidden_objectives': 0,
'new_objectives': 0,
'hidden_objectives': parent.hidden_objectives.count(),
'new_objectives': parent.custom_objectives.filter(hidden=False).count(),
'hidden_content_blocks': parent.hidden_content_blocks.count(),
'new_content_blocks': parent.custom_content_blocks.count()
'new_content_blocks': parent.custom_content_blocks.filter(hidden=False).count()
}
@staticmethod

View File

@ -87,6 +87,12 @@ SNAPSHOT_MODULE_QUERY = """
query SnapshotDetail($id: ID!) {
snapshot(id: $id) {
id
changes {
newContentBlocks
newObjectives
hiddenContentBlocks
hiddenObjectives
}
objectiveGroups {
title
id
@ -174,9 +180,10 @@ class CreateSnapshotTestCase(SkillboxTestCase):
module=self.module, title=self.title_custom,
slug='cb-c')
# content block d is user created, but hidden
self.custom_hidden_content_block = ContentBlockFactory(parent=self.chapter, owner=self.teacher, user_created=True,
module=self.module, title=self.title_custom_hidden,
slug='cb-d')
self.custom_hidden_content_block = ContentBlockFactory(parent=self.chapter, owner=self.teacher,
user_created=True,
module=self.module, title=self.title_custom_hidden,
slug='cb-d')
# content block a and c are visible to school class X
self.hidden_content_block.hidden_for.add(self.skillbox_class)
self.custom_content_block.visible_for.add(self.skillbox_class)
@ -339,6 +346,12 @@ class CreateSnapshotTestCase(SkillboxTestCase):
self.assertEqual(objective_group2['hidden'], True)
changes = snapshot['changes']
self.assertEqual(changes['newContentBlocks'], 1)
self.assertEqual(changes['hiddenContentBlocks'], 1)
self.assertEqual(changes['newObjectives'], 1)
self.assertEqual(changes['hiddenObjectives'], 1)
def test_apply_initial_snapshot(self):
teacher2 = User.objects.get(username='teacher2')
teacher2_client = self.get_client(user=teacher2)