def test_serialization(self, weight, max_score, block_key): """ Tests serialization of a BlockRecord using the to_dict() method. """ record = BlockRecord(block_key, weight, max_score) expected = OrderedDict([ ("locator", block_key), ("weight", weight), ("max_score", max_score), ]) self.assertEqual(expected, record._asdict())
def test_serialization(self, weight, raw_possible, block_key, graded): """ Tests serialization of a BlockRecord using the _asdict() method. """ record = BlockRecord(block_key, weight, raw_possible, graded) expected = OrderedDict([ ("locator", block_key), ("weight", weight), ("raw_possible", raw_possible), ("graded", graded), ]) self.assertEqual(expected, record._asdict())
def _create_persisted_block(self, persisted_block_value): """ Creates and returns a minimal BlockRecord object with the give values. """ if persisted_block_value.exists: return BlockRecord( self.location, persisted_block_value.weight, persisted_block_value.raw_possible, persisted_block_value.graded, ) else: return None
def test_creation(self): """ Tests creation of a BlockRecord. """ weight = 1 raw_possible = 10 record = BlockRecord( self.locator_a, weight, raw_possible, graded=False, ) self.assertEqual(record.locator, self.locator_a)
def save(self, student, subsection, course): """ Persist the SubsectionGrade. """ visible_blocks = [ BlockRecord(location, weight, score.possible) for location, (score, weight) in self.locations_to_weighted_scores.iteritems() ] PersistentSubsectionGrade.save_grade( user_id=student.id, usage_key=self.location, course_version=getattr(course, 'course_version', None), subtree_edited_timestamp=subsection.subtree_edited_on, earned_all=self.all_total.earned, possible_all=self.all_total.possible, earned_graded=self.graded_total.earned, possible_graded=self.graded_total.possible, visible_blocks=visible_blocks, )
def test_with_persisted_block(self, persisted_block_value, block_value): block = self._create_block(block_value) block_record = BlockRecord(block.location, 0, 0, persisted_block_value) assert scores._get_graded_from_block(block_record, block) == block_record.graded
def test_with_persisted_block(self, persisted_block_r_possible, block_r_possible, weight): block = self._create_block(block_r_possible) block_record = BlockRecord(block.location, 0, persisted_block_r_possible, False) self._verify_score_result(block_record, block, weight, persisted_block_r_possible)