def test_cannot_get_question_from_model_with_invalid_schema_version(self): # Delete all question models. all_question_models = question_models.QuestionModel.get_all() question_models.QuestionModel.delete_multi(all_question_models) all_question_models = question_models.QuestionModel.get_all() self.assertEqual(all_question_models.count(), 0) question_id = question_services.get_new_question_id() question_model = question_models.QuestionModel( id=question_id, question_state_data=( self._create_valid_question_data('ABC').to_dict()), language_code='en', version=0, question_state_data_schema_version=0) question_model.commit( self.editor_id, 'question model created', [{'cmd': question_domain.CMD_CREATE_NEW}]) all_question_models = question_models.QuestionModel.get_all() self.assertEqual(all_question_models.count(), 1) question_model = all_question_models.get() with self.assertRaisesRegexp( Exception, 'Sorry, we can only process v25-v%d state schemas at present.' % feconf.CURRENT_STATE_SCHEMA_VERSION): question_services.get_question_from_model(question_model)
def test_post(self): with self.swap(feconf, 'ENABLE_NEW_STRUCTURES', True): self.login(self.NEW_USER_EMAIL) response = self.testapp.post( '%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), expect_errors=True) self.assertEqual(response.status_int, 401) self.logout() self.login(self.ADMIN_EMAIL) response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None self.post_json( '%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), { 'question_dict': question_dict }, csrf_token=csrf_token, expect_errors=False, expected_status_int=200) all_models = question_models.QuestionModel.get_all() questions = [ question_services.get_question_from_model(model) for model in all_models ] self.assertEqual(len(questions), 2) self.logout() self.login(self.TOPIC_MANAGER_EMAIL) response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None self.post_json( '%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), { 'question_dict': question_dict }, csrf_token=csrf_token, expect_errors=False, expected_status_int=200) all_models = question_models.QuestionModel.get_all() questions = [ question_services.get_question_from_model(model) for model in all_models ] self.assertEqual(len(questions), 3) self.logout()
def test_post_with_topic_manager_email_allows_question_creation(self): self.login(self.TOPIC_MANAGER_EMAIL) csrf_token = self.get_new_csrf_token() question_dict = self.question.to_dict() question_dict['id'] = None self.post_json('%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), {'question_dict': question_dict}, csrf_token=csrf_token) all_models = question_models.QuestionModel.get_all() questions = [ question_services.get_question_from_model(model) for model in all_models ] self.assertEqual(len(questions), 2) self.logout()
def test_post_with_admin_email_allows_question_creation(self): self.login(self.ADMIN_EMAIL) csrf_token = self.get_new_csrf_token() question_dict = self.question.to_dict() question_dict['id'] = None self.post_json('%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), {'question_dict': question_dict}, csrf_token=csrf_token, expected_status_int=200) all_models = question_models.QuestionModel.get_all() questions = [ question_services.get_question_from_model(model) for model in all_models ] self.assertEqual(len(questions), 2) self.logout()
def test_post_with_topic_manager_email_allows_question_creation(self): with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True): self.login(self.TOPIC_MANAGER_EMAIL) response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL) csrf_token = self.get_csrf_token_from_response(response) question_dict = self.question.to_dict() question_dict['id'] = None self.post_json('%s/%s' % (feconf.NEW_QUESTION_URL, self.skill_id), {'question_dict': question_dict}, csrf_token=csrf_token) all_models = question_models.QuestionModel.get_all() questions = [ question_services.get_question_from_model(model) for model in all_models ] self.assertEqual(len(questions), 2) self.logout()
def test_migrate_question_state_from_v29_to_v30(self): answer_group = { 'outcome': { 'dest': 'abc', 'feedback': { 'content_id': 'feedback_1', 'html': '<p>Feedback</p>' }, 'labelled_as_correct': True, 'param_changes': [], 'refresher_exploration_id': None, 'missing_prerequisite_skill_id': None }, 'rule_specs': [{ 'inputs': { 'x': 'Test' }, 'rule_type': 'Contains' }], 'training_data': [], 'tagged_misconception_id': None } question_state_dict = { 'content': { 'content_id': 'content_1', 'html': 'Question 1' }, 'recorded_voiceovers': { 'voiceovers_mapping': {} }, 'written_translations': { 'translations_mapping': { 'explanation': {} } }, 'interaction': { 'answer_groups': [answer_group], 'confirmed_unclassified_answers': [], 'customization_args': {}, 'default_outcome': { 'dest': None, 'feedback': { 'content_id': 'feedback_1', 'html': 'Correct Answer' }, 'param_changes': [], 'refresher_exploration_id': None, 'labelled_as_correct': True, 'missing_prerequisite_skill_id': None }, 'hints': [{ 'hint_content': { 'content_id': 'hint_1', 'html': 'Hint 1' } }], 'solution': { 'correct_answer': 'This is the correct answer', 'answer_is_exclusive': False, 'explanation': { 'content_id': 'explanation_1', 'html': 'Solution explanation' } }, 'id': 'TextInput' }, 'param_changes': [], 'solicit_answer_details': False, 'classifier_model_id': None } question_model = question_models.QuestionModel( id='question_id', question_state_data=question_state_dict, language_code='en', version=0, linked_skill_ids=['skill_id'], question_state_data_schema_version=29) commit_cmd = question_domain.QuestionChange( {'cmd': question_domain.CMD_CREATE_NEW}) commit_cmd_dicts = [commit_cmd.to_dict()] question_model.commit('user_id_admin', 'question model created', commit_cmd_dicts) current_schema_version_swap = self.swap( feconf, 'CURRENT_STATE_SCHEMA_VERSION', 30) with current_schema_version_swap: question = question_services.get_question_from_model( question_model) self.assertEqual(question.question_state_data_schema_version, 30) answer_groups = question.question_state_data.interaction.answer_groups self.assertEqual(answer_groups[0].tagged_skill_misconception_id, None)