示例#1
0
 def __init__(  # pylint: disable=super-init-not-called
         self,
         suggestion_id,
         target_id,
         target_version_at_submission,
         status,
         author_id,
         final_reviewer_id,
         change,
         score_category,
         last_updated=None):
     """Initializes an object of type SuggestionAddQuestion
     corresponding to the SUGGESTION_TYPE_ADD_QUESTION choice.
     """
     self.suggestion_id = suggestion_id
     self.suggestion_type = suggestion_models.SUGGESTION_TYPE_ADD_QUESTION
     self.target_type = suggestion_models.TARGET_TYPE_SKILL
     self.target_id = target_id
     self.target_version_at_submission = target_version_at_submission
     self.status = status
     self.author_id = author_id
     self.final_reviewer_id = final_reviewer_id
     self.change = question_domain.QuestionSuggestionChange(change)
     # Update question_state_data_schema_version here instead of surfacing
     # the version in the frontend.
     self.change.question_dict['question_state_data_schema_version'] = (
         feconf.CURRENT_STATE_SCHEMA_VERSION)
     self.score_category = score_category
     self.last_updated = last_updated
示例#2
0
def validate_suggestion_change(obj):
    """Validates Exploration or Question change.

    Args:
        obj: dict. Data that needs to be validated.

    Returns:
        dict. Returns suggestion change dict after validation.
    """
    # No explicit call to validate_dict is required, because
    # ExplorationChange or QuestionSuggestionChange calls
    # validate method while initialization.
    if obj.get('cmd') is None:
        raise base.BaseHandler.InvalidInputException(
            'Missing cmd key in change dict')

    exp_change_commands = [
        command['name'] for command in
        exp_domain.ExplorationChange.ALLOWED_COMMANDS
    ]
    question_change_commands = [
        command['name'] for command in
        question_domain.QuestionChange.ALLOWED_COMMANDS
    ]

    if obj['cmd'] in exp_change_commands:
        exp_domain.ExplorationChange(obj)
    elif obj['cmd'] in question_change_commands:
        question_domain.QuestionSuggestionChange(obj)
    else:
        raise base.BaseHandler.InvalidInputException(
            '%s cmd is not allowed.' % obj['cmd'])
    return obj
示例#3
0
    def test_create_new_fully_specified_question(self):
        """Test to verify __init__ method of the QuestionSuggestionChange object
        when cmd is create_new_fully_specified_question.
        """
        change_dict = {
            'cmd': 'create_new_fully_specified_question',
            'question_dict': {},
            'skill_id': '10',
            'skill_difficulty': '0.3',
        }
        observed_object = question_domain.QuestionSuggestionChange(
            change_dict=change_dict, )

        self.assertEqual('create_new_fully_specified_question',
                         observed_object.cmd)
        self.assertEqual('10', observed_object.skill_id)
        self.assertEqual({}, observed_object.question_dict)
示例#4
0
    def test_to_dict(self):
        """Test to verify to_dict method of the Question Change object."""
        expected_object_dict = {
            'cmd': 'create_new_fully_specified_question',
            'question_dict': 'question_dict',
            'skill_id': 'skill_1',
            'skill_difficulty': '0.3'
        }

        change_dict = {
            'cmd': 'create_new_fully_specified_question',
            'question_dict': 'question_dict',
            'skill_id': 'skill_1',
            'skill_difficulty': '0.3'
        }
        observed_object = question_domain.QuestionSuggestionChange(
            change_dict=change_dict, )

        self.assertEqual(expected_object_dict, observed_object.to_dict())