Example #1
0
    def test_empty_block_record_set(self):
        empty_json = u'{"blocks":[],"course_key":"%s","version":%s}' % (
            unicode(self.course_key),
            BLOCK_RECORD_LIST_VERSION,
        )

        brs = BlockRecordList((), self.course_key)
        self.assertFalse(brs)
        self.assertEqual(brs.json_value, empty_json)
        self.assertEqual(BlockRecordList.from_json(empty_json), brs)
Example #2
0
    def test_empty_block_record_set(self):
        empty_json = '{{"blocks":[],"course_key":"{}","version":{}}}'.format(
            str(self.course_key),
            BLOCK_RECORD_LIST_VERSION,
        )

        brs = BlockRecordList((), self.course_key)
        assert not brs
        assert brs.json_value == empty_json
        assert BlockRecordList.from_json(empty_json) == brs
 def test_empty_block_record_set(self):
     brs = BlockRecordList(())
     self.assertFalse(brs)
     self.assertEqual(
         brs.to_json(),
         self.empty_json
     )
     self.assertEqual(
         BlockRecordList.from_json(self.empty_json),
         brs
     )
Example #4
0
    def test_empty_block_record_set(self):
        empty_json = '{0}"blocks":[],"course_key":"{1}"{2}'.format('{', unicode(self.course_key), '}')

        brs = BlockRecordList((), self.course_key)
        self.assertFalse(brs)
        self.assertEqual(
            brs.json_value,
            empty_json
        )
        self.assertEqual(
            BlockRecordList.from_json(empty_json),
            brs
        )
Example #5
0
 def setUp(self):
     super(PersistentSubsectionGradeTest, self).setUp()
     self.usage_key = BlockUsageLocator(
         course_key=self.course_key,
         block_type='subsection',
         block_id='subsection_12345',
     )
     self.block_records = BlockRecordList([self.record_a, self.record_b],
                                          self.course_key)
     self.params = {
         "user_id": 12345,
         "usage_key": self.usage_key,
         "course_version": "deadbeef",
         "subtree_edited_timestamp": "2016-08-01 18:53:24.354741Z",
         "earned_all": 6.0,
         "possible_all": 12.0,
         "earned_graded": 6.0,
         "possible_graded": 8.0,
         "visible_blocks": self.block_records,
         "first_attempted": datetime(2000,
                                     1,
                                     1,
                                     12,
                                     30,
                                     45,
                                     tzinfo=pytz.UTC),
     }
     self.user = UserFactory(id=self.params['user_id'])
Example #6
0
 def _create_block_record_list(self, blocks, user_id=None):
     """
     Creates and returns a BlockRecordList for the given blocks.
     """
     block_record_list = BlockRecordList.from_list(blocks, self.course_key)
     return VisibleBlocks.cached_get_or_create(user_id or self.user_id,
                                               block_record_list)
Example #7
0
 def test_blocks_property(self):
     """
     Ensures that, given an array of BlockRecord, creating visible_blocks
     and accessing visible_blocks.blocks yields a copy of the initial array.
     Also, trying to set the blocks property should raise an exception.
     """
     expected_blocks = BlockRecordList.from_list([self.record_a, self.record_b], self.course_key)
     visible_blocks = self._create_block_record_list(expected_blocks)
     self.assertEqual(expected_blocks, visible_blocks.blocks)
     with self.assertRaises(AttributeError):
         visible_blocks.blocks = expected_blocks
Example #8
0
    def test_empty_block_record_set(self):
        empty_json = u'{"blocks":[],"course_key":"%s","version":%s}' % (
            unicode(self.course_key),
            BLOCK_RECORD_LIST_VERSION,
        )

        brs = BlockRecordList((), self.course_key)
        self.assertFalse(brs)
        self.assertEqual(
            brs.json_value,
            empty_json
        )
        self.assertEqual(
            BlockRecordList.from_json(empty_json),
            brs
        )
Example #9
0
 def setUp(self):
     super(PersistentSubsectionGradeTest, self).setUp()
     self.usage_key = BlockUsageLocator(
         course_key=self.course_key,
         block_type='subsection',
         block_id='subsection_12345',
     )
     self.block_records = BlockRecordList([self.record_a, self.record_b], self.course_key)
     self.params = {
         "user_id": 12345,
         "usage_key": self.usage_key,
         "course_version": "deadbeef",
         "subtree_edited_timestamp": "2016-08-01 18:53:24.354741",
         "earned_all": 6.0,
         "possible_all": 12.0,
         "earned_graded": 6.0,
         "possible_graded": 8.0,
         "visible_blocks": self.block_records,
     }
Example #10
0
 def _create_block_record_list(self, blocks):
     """
     Creates and returns a BlockRecordList for the given blocks.
     """
     return VisibleBlocks.objects.create_from_blockrecords(BlockRecordList.from_list(blocks, self.course_key))
Example #11
0
 def _create_block_record_list(self, blocks):
     """
     Creates and returns a BlockRecordList for the given blocks.
     """
     return VisibleBlocks.cached_get_or_create(
         BlockRecordList.from_list(blocks, self.course_key))
Example #12
0
 def _create_block_record_list(self, blocks, user_id=None):
     """
     Creates and returns a BlockRecordList for the given blocks.
     """
     block_record_list = BlockRecordList.from_list(blocks, self.course_key)
     return VisibleBlocks.cached_get_or_create(user_id or self.user_id, block_record_list)
Example #13
0
 def _create_block_record_list(self, blocks):
     """
     Creates and returns a BlockRecordList for the given blocks.
     """
     return VisibleBlocks.cached_get_or_create(BlockRecordList.from_list(blocks, self.course_key))