def mock_get_statistics(self, exp_id, unused_version): current_completions = { self.EXP_ID_1: stats_domain.ExplorationStats( self.EXP_ID_1, self.EXP_DEFAULT_VERSION, 5, 2, 0, 0, 0, 0, { 'state1': stats_domain.StateStats( 0, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0), 'state2': stats_domain.StateStats( 0, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0), } ), self.EXP_ID_2: stats_domain.ExplorationStats( self.EXP_ID_2, self.EXP_DEFAULT_VERSION, 5, 2, 0, 0, 0, 0, { 'state1': stats_domain.StateStats( 0, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0), 'state2': stats_domain.StateStats( 0, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0), } ), self.EXP_ID_3: stats_domain.ExplorationStats( self.EXP_ID_3, self.EXP_DEFAULT_VERSION, 0, 0, 0, 0, 0, 0, {}) } return current_completions[exp_id]
def test_to_dict(self): state_stats_dict = { 'total_answers_count_v1': 0, 'total_answers_count_v2': 10, 'useful_feedback_count_v1': 0, 'useful_feedback_count_v2': 4, 'total_hit_count_v1': 0, 'total_hit_count_v2': 18, 'first_hit_count_v1': 0, 'first_hit_count_v2': 7, 'num_times_solution_viewed_v2': 2, 'num_completions_v1': 0, 'num_completions_v2': 2 } state_stats = stats_domain.StateStats(0, 10, 0, 4, 0, 18, 0, 7, 2, 0, 2) self.assertEqual(state_stats_dict, state_stats.to_dict())
def test_validation(self): state_stats = stats_domain.StateStats(0, 10, 0, 4, 0, 18, 0, 7, 2, 0, 2) state_stats.validate() # Change total_answers_count to string. state_stats.total_answers_count_v2 = '10' with self.assertRaisesRegexp( utils.ValidationError, ('Expected total_answers_count_v2 to be an int')): state_stats.validate() # Make the total_answers_count negative. state_stats.total_answers_count_v2 = -5 with self.assertRaisesRegexp(utils.ValidationError, ('%s cannot have negative values' % ('total_answers_count_v2'))): state_stats.validate()