function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
sequence
def test_base_class_convert_html_in_suggestion_change(self): def conversion_fn(): """Temporary function.""" pass with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseSuggestion should implement' ' convert_html_in_suggestion_change.'): self.base_suggestion.convert_html_in_suggestion_change( conversion_fn)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def setUp(self): super(SuggestionEditStateContentUnitTests, self).setUp() self.signup(self.AUTHOR_EMAIL, 'author') self.author_id = self.get_user_id_from_email(self.AUTHOR_EMAIL) self.signup(self.REVIEWER_EMAIL, 'reviewer') self.reviewer_id = self.get_user_id_from_email(self.REVIEWER_EMAIL) self.suggestion_dict = { 'suggestion_id': 'exploration.exp1.thread1', 'suggestion_type': ( feconf.SUGGESTION_TYPE_EDIT_STATE_CONTENT), 'target_type': feconf.ENTITY_TYPE_EXPLORATION, 'target_id': 'exp1', 'target_version_at_submission': 1, 'status': suggestion_models.STATUS_ACCEPTED, 'author_name': 'author', 'final_reviewer_id': self.reviewer_id, 'change': { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'state_1', 'new_value': 'new suggestion content', 'old_value': None }, 'score_category': 'content.Algebra', 'language_code': None, 'last_updated': utils.get_time_in_millisecs(self.fake_date), 'edited_by_reviewer': False }
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_suggestion_edit_state_content(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_suggestion_type(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.suggestion_type = 'invalid_suggestion_type' with self.assertRaisesRegex( utils.ValidationError, 'Expected suggestion_type to be among allowed choices' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_target_id(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.target_id = 0 with self.assertRaisesRegex( utils.ValidationError, 'Expected target_id to be a string' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_status(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.status = 'invalid_status' with self.assertRaisesRegex( utils.ValidationError, 'Expected status to be among allowed choices' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_author_id_format(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.author_id = self.PSEUDONYMOUS_ID suggestion.validate() suggestion.author_id = '' with self.assertRaisesRegex( utils.ValidationError, 'Expected author_id to be in a valid user ID format' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_final_reviewer_id_format(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.final_reviewer_id = self.PSEUDONYMOUS_ID suggestion.validate() suggestion.final_reviewer_id = '' with self.assertRaisesRegex( utils.ValidationError, 'Expected final_reviewer_id to be in a valid user ID format' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_score_category_format(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.score_category = 'score.score_type.score_sub_type' with self.assertRaisesRegex( utils.ValidationError, 'Expected score_category to be of the form' ' score_type.score_sub_type' ): suggestion.validate() suggestion.score_category = 'invalid_score_category' with self.assertRaisesRegex( utils.ValidationError, 'Expected score_category to be of the form' ' score_type.score_sub_type' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_change(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.change = {} with self.assertRaisesRegex( utils.ValidationError, 'Expected change to be an ExplorationChange' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_change_cmd(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.change.cmd = 'invalid_cmd' with self.assertRaisesRegex( utils.ValidationError, 'Expected cmd to be edit_state_property' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_language_code_fails_when_language_codes_do_not_match( self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.language_code = 'wrong_language_code' with self.assertRaisesRegex( utils.ValidationError, 'Expected language_code to be None, received wrong_language_code' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_populate_old_value_of_change_with_invalid_state(self): self.save_new_default_exploration('exp1', self.author_id) expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.change.state_name = 'invalid_state_name' self.assertIsNone(suggestion.change.old_value) suggestion.populate_old_value_of_change() self.assertIsNone(suggestion.change.old_value)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_pre_update_validate_change_property_name(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) change = { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_PARAM_CHANGES, 'state_name': suggestion.change.state_name, 'new_value': 'new suggestion content', 'old_value': None } with self.assertRaisesRegex( utils.ValidationError, 'The new change property_name must be equal to content' ): suggestion.pre_update_validate(exp_domain.ExplorationChange(change))
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_pre_update_validate_change_new_value(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionEditStateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) new_content = state_domain.SubtitledHtml( 'content', '<p>new suggestion html</p>').to_dict() suggestion.change.new_value = new_content change = { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': suggestion.change.state_name, 'new_value': new_content, 'old_value': None } with self.assertRaisesRegex( utils.ValidationError, 'The new html must not match the old html' ): suggestion.pre_update_validate(exp_domain.ExplorationChange(change))
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_get_all_html_content_strings(self): change_dict = { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'state_1', 'new_value': { 'content_id': 'content', 'html': 'new suggestion content' }, 'old_value': None } suggestion = suggestion_registry.SuggestionEditStateContent( self.suggestion_dict['suggestion_id'], self.suggestion_dict['target_id'], self.suggestion_dict['target_version_at_submission'], self.suggestion_dict['status'], self.author_id, self.reviewer_id, change_dict, self.suggestion_dict['score_category'], self.suggestion_dict['language_code'], False, self.fake_date) actual_outcome_list = suggestion.get_all_html_content_strings() expected_outcome_list = [u'new suggestion content'] self.assertEqual(expected_outcome_list, actual_outcome_list)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_get_target_entity_html_strings_returns_expected_strings(self): change_dict = { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'state_1', 'new_value': { 'content_id': 'content', 'html': 'new suggestion content' }, 'old_value': { 'content_id': 'content', 'html': 'Old content.' } } suggestion = suggestion_registry.SuggestionEditStateContent( self.suggestion_dict['suggestion_id'], self.suggestion_dict['target_id'], self.suggestion_dict['target_version_at_submission'], self.suggestion_dict['status'], self.author_id, self.reviewer_id, change_dict, self.suggestion_dict['score_category'], self.suggestion_dict['language_code'], False, self.fake_date) actual_outcome_list = suggestion.get_target_entity_html_strings() expected_outcome_list = [u'Old content.'] self.assertEqual(expected_outcome_list, actual_outcome_list)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def setUp(self): super(SuggestionTranslateContentUnitTests, self).setUp() self.signup(self.AUTHOR_EMAIL, 'author') self.author_id = self.get_user_id_from_email(self.AUTHOR_EMAIL) self.signup(self.REVIEWER_EMAIL, 'reviewer') self.reviewer_id = self.get_user_id_from_email(self.REVIEWER_EMAIL) self.suggestion_dict = { 'suggestion_id': 'exploration.exp1.thread1', 'suggestion_type': ( feconf.SUGGESTION_TYPE_TRANSLATE_CONTENT), 'target_type': feconf.ENTITY_TYPE_EXPLORATION, 'target_id': 'exp1', 'target_version_at_submission': 1, 'status': suggestion_models.STATUS_ACCEPTED, 'author_name': 'author', 'final_reviewer_id': self.reviewer_id, 'change': { 'cmd': exp_domain.CMD_ADD_WRITTEN_TRANSLATION, 'state_name': 'Introduction', 'content_id': 'content', 'language_code': 'hi', 'content_html': '<p>This is a content.</p>', 'translation_html': '<p>This is translated html.</p>', 'data_format': 'html' }, 'score_category': 'translation.Algebra', 'language_code': 'hi', 'last_updated': utils.get_time_in_millisecs(self.fake_date), 'edited_by_reviewer': False }
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_pre_update_validate_change_state_name(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], self.fake_date) change = { 'cmd': exp_domain.CMD_ADD_WRITTEN_TRANSLATION, 'state_name': 'State 1', 'content_id': 'content', 'language_code': 'hi', 'content_html': '<p>This is a content.</p>', 'translation_html': '<p>This is the updated translated html.</p>', 'data_format': 'html' } with self.assertRaisesRegex( utils.ValidationError, 'The new change state_name must be equal to Introduction' ): suggestion.pre_update_validate(exp_domain.ExplorationChange(change))
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_pre_update_validate_change_content_html(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], self.fake_date) change = { 'cmd': exp_domain.CMD_ADD_WRITTEN_TRANSLATION, 'state_name': 'Introduction', 'content_id': 'content', 'language_code': 'en', 'content_html': '<p>This is the changed content.</p>', 'translation_html': '<p>This is the updated translated html.</p>', 'data_format': 'html' } with self.assertRaisesRegex( utils.ValidationError, 'The new change content_html must be equal to <p>This is a ' + 'content.</p>' ): suggestion.pre_update_validate( exp_domain.ExplorationChange(change))
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_suggestion_add_translation(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_suggestion_type(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.suggestion_type = 'invalid_suggestion_type' with self.assertRaisesRegex( utils.ValidationError, 'Expected suggestion_type to be among allowed choices' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_target_id(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.target_id = 0 with self.assertRaisesRegex( utils.ValidationError, 'Expected target_id to be a string' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_status(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.status = 'invalid_status' with self.assertRaisesRegex( utils.ValidationError, 'Expected status to be among allowed choices' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_author_id_format(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.author_id = '' with self.assertRaisesRegex( utils.ValidationError, 'Expected author_id to be in a valid user ID format.' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_final_reviewer_id_format(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.final_reviewer_id = '' with self.assertRaisesRegex( utils.ValidationError, 'Expected final_reviewer_id to be in a valid user ID format' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_score_category_format(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.score_category = 'score.score_type.score_sub_type' with self.assertRaisesRegex( utils.ValidationError, 'Expected score_category to be of the form' ' score_type.score_sub_type' ): suggestion.validate() suggestion.score_category = 'invalid_score_category' with self.assertRaisesRegex( utils.ValidationError, 'Expected score_category to be of the form' ' score_type.score_sub_type' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_change(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.change = {} with self.assertRaisesRegex( utils.ValidationError, 'Expected change to be an ExplorationChange' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_change_cmd(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.change.cmd = 'invalid_cmd' with self.assertRaisesRegex( utils.ValidationError, 'Expected cmd to be add_written_translation' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_language_code_fails_when_language_code_is_set_to_none( self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.language_code = None with self.assertRaisesRegex( utils.ValidationError, 'language_code cannot be None' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_pre_accept_validate_state_name(self): self.save_new_default_exploration('exp1', self.author_id) expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionTranslateContent( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) exp_services.update_exploration( self.author_id, 'exp1', [ exp_domain.ExplorationChange({ 'cmd': exp_domain.CMD_ADD_STATE, 'state_name': 'State A', }), exp_domain.ExplorationChange({ 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'new_value': { 'content_id': 'content', 'html': '<p>This is a content.</p>' }, 'state_name': 'State A', }) ], 'Added state') suggestion.change.state_name = 'State A' suggestion.pre_accept_validate() suggestion.change.state_name = 'invalid_state_name' with self.assertRaisesRegex( utils.ValidationError, 'Expected invalid_state_name to be a valid state name' ): suggestion.pre_accept_validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_accept_suggestion_with_set_of_string_adds_translation(self): self.save_new_default_exploration('exp1', self.author_id) exploration = exp_fetchers.get_exploration_by_id('exp1') self.assertEqual(exploration.get_translation_counts(), {}) suggestion = suggestion_registry.SuggestionTranslateContent( self.suggestion_dict['suggestion_id'], self.suggestion_dict['target_id'], self.suggestion_dict['target_version_at_submission'], self.suggestion_dict['status'], self.author_id, self.reviewer_id, { 'cmd': exp_domain.CMD_ADD_WRITTEN_TRANSLATION, 'state_name': 'Introduction', 'content_id': 'content', 'language_code': 'hi', 'content_html': ['text1', 'text2'], 'translation_html': ['translated text1', 'translated text2'], 'data_format': 'set_of_normalized_string' }, self.suggestion_dict['score_category'], self.suggestion_dict['language_code'], False, self.fake_date) suggestion.accept( 'Accepted suggestion by translator: Add translation change.') exploration = exp_fetchers.get_exploration_by_id('exp1') self.assertEqual(exploration.get_translation_counts(), { 'hi': 1 })
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_get_all_html_content_strings(self): suggestion = suggestion_registry.SuggestionTranslateContent( self.suggestion_dict['suggestion_id'], self.suggestion_dict['target_id'], self.suggestion_dict['target_version_at_submission'], self.suggestion_dict['status'], self.author_id, self.reviewer_id, self.suggestion_dict['change'], self.suggestion_dict['score_category'], self.suggestion_dict['language_code'], False, self.fake_date) actual_outcome_list = suggestion.get_all_html_content_strings() expected_outcome_list = [ u'<p>This is translated html.</p>', u'<p>This is a content.</p>'] self.assertEqual(expected_outcome_list, actual_outcome_list)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_get_target_entity_html_strings_returns_expected_strings(self): suggestion = suggestion_registry.SuggestionTranslateContent( self.suggestion_dict['suggestion_id'], self.suggestion_dict['target_id'], self.suggestion_dict['target_version_at_submission'], self.suggestion_dict['status'], self.author_id, self.reviewer_id, self.suggestion_dict['change'], self.suggestion_dict['score_category'], self.suggestion_dict['language_code'], False, self.fake_date) actual_outcome_list = suggestion.get_target_entity_html_strings() expected_outcome_list = [self.suggestion_dict['change']['content_html']] self.assertEqual(expected_outcome_list, actual_outcome_list)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def setUp(self): super(SuggestionAddQuestionTest, self).setUp() self.signup(self.AUTHOR_EMAIL, 'author') self.author_id = self.get_user_id_from_email(self.AUTHOR_EMAIL) self.signup(self.REVIEWER_EMAIL, 'reviewer') self.reviewer_id = self.get_user_id_from_email(self.REVIEWER_EMAIL) self.suggestion_dict = { 'suggestion_id': 'skill1.thread1', 'suggestion_type': feconf.SUGGESTION_TYPE_ADD_QUESTION, 'target_type': feconf.ENTITY_TYPE_SKILL, 'target_id': 'skill1', 'target_version_at_submission': 1, 'status': suggestion_models.STATUS_ACCEPTED, 'author_name': 'author', 'final_reviewer_id': self.reviewer_id, 'change': { 'cmd': question_domain.CMD_CREATE_NEW_FULLY_SPECIFIED_QUESTION, 'question_dict': { 'question_state_data': self._create_valid_question_data( 'default_state').to_dict(), 'language_code': 'en', 'question_state_data_schema_version': ( feconf.CURRENT_STATE_SCHEMA_VERSION), 'linked_skill_ids': ['skill_1'], 'inapplicable_skill_misconception_ids': ['skillid12345-1'] }, 'skill_id': 'skill_1', 'skill_difficulty': 0.3, }, 'score_category': 'question.topic_1', 'language_code': 'en', 'last_updated': utils.get_time_in_millisecs(self.fake_date), 'edited_by_reviewer': False }
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_suggestion_edit_state_content(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_score_type(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.score_category = 'content.score_sub_type' with self.assertRaisesRegex( utils.ValidationError, 'Expected the first part of score_category to be "question"' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_change_cmd(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.change.cmd = None with self.assertRaisesRegex( utils.ValidationError, 'Expected change to contain cmd' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_change_question_dict(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.change.question_dict = None with self.assertRaisesRegex( utils.ValidationError, 'Expected change to contain question_dict' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_change_skill_difficulty_none(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.change.skill_difficulty = None with self.assertRaisesRegex( utils.ValidationError, 'Expected change to contain skill_difficulty' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_pre_accept_validate_change_skill_id(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) skill_id = skill_services.get_new_skill_id() self.save_new_skill(skill_id, self.author_id, description='description') suggestion.change.skill_id = skill_id suggestion.pre_accept_validate() suggestion.change.skill_id = None with self.assertRaisesRegex( utils.ValidationError, 'Expected change to contain skill_id' ): suggestion.pre_accept_validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_get_change_list_for_accepting_suggestion(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) self.assertIsNone(suggestion.get_change_list_for_accepting_suggestion())
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_cannot_accept_suggestion_with_invalid_skill_id(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.change.skill_id = skill_services.get_new_skill_id() with self.assertRaisesRegex( utils.ValidationError, 'The skill with the given id doesn\'t exist.' ): suggestion.accept('commit message')
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_pre_update_validate_change_skill_id(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) change = { 'cmd': question_domain.CMD_CREATE_NEW_FULLY_SPECIFIED_QUESTION, 'question_dict': { 'question_state_data': self._create_valid_question_data( 'default_state').to_dict(), 'language_code': 'en', 'question_state_data_schema_version': ( feconf.CURRENT_STATE_SCHEMA_VERSION) }, 'skill_id': 'skill_2' } with self.assertRaisesRegex( utils.ValidationError, 'The new change skill_id must be equal to skill_1' ): suggestion.pre_update_validate( question_domain.QuestionChange(change))
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_pre_update_validate_accepts_a_change_in_skill_difficulty_only( self): change = { 'cmd': question_domain.CMD_CREATE_NEW_FULLY_SPECIFIED_QUESTION, 'question_dict': { 'question_state_data': self._create_valid_question_data( 'default_state').to_dict(), 'language_code': 'en', 'question_state_data_schema_version': ( feconf.CURRENT_STATE_SCHEMA_VERSION) }, 'skill_id': 'skill_1', 'skill_difficulty': 0.3 } suggestion = suggestion_registry.SuggestionAddQuestion( 'exploration.exp1.thread1', 'exp1', 1, suggestion_models.STATUS_ACCEPTED, self.author_id, self.reviewer_id, change, 'question.topic_1', 'en', self.fake_date) new_change = { 'cmd': question_domain.CMD_CREATE_NEW_FULLY_SPECIFIED_QUESTION, 'question_dict': { 'question_state_data': self._create_valid_question_data( 'default_state').to_dict(), 'language_code': 'en', 'question_state_data_schema_version': ( feconf.CURRENT_STATE_SCHEMA_VERSION) }, 'skill_id': 'skill_1', 'skill_difficulty': 0.6 } self.assertEqual( suggestion.pre_update_validate( question_domain.QuestionSuggestionChange(new_change)), None)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_author_id(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.author_id = 0 with self.assertRaisesRegex( utils.ValidationError, 'Expected author_id to be a string'): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_final_reviewer_id(self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) suggestion.validate() suggestion.final_reviewer_id = 1 with self.assertRaisesRegex( utils.ValidationError, 'Expected final_reviewer_id to be a string'): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_language_code_fails_when_language_codes_do_not_match( self): expected_suggestion_dict = self.suggestion_dict suggestion = suggestion_registry.SuggestionAddQuestion( expected_suggestion_dict['suggestion_id'], expected_suggestion_dict['target_id'], expected_suggestion_dict['target_version_at_submission'], expected_suggestion_dict['status'], self.author_id, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_suggestion_dict['language_code'], False, self.fake_date) expected_question_dict = ( expected_suggestion_dict['change']['question_dict'] ) suggestion.validate() expected_question_dict['language_code'] = 'wrong_language_code' with self.assertRaisesRegex( utils.ValidationError, 'Expected question language_code.wrong_language_code. to be same ' 'as suggestion language_code.en.' ): suggestion.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_get_all_html_conztent_strings(self): suggestion = suggestion_registry.SuggestionAddQuestion( self.suggestion_dict['suggestion_id'], self.suggestion_dict['target_id'], self.suggestion_dict['target_version_at_submission'], self.suggestion_dict['status'], self.author_id, self.reviewer_id, self.suggestion_dict['change'], self.suggestion_dict['score_category'], self.suggestion_dict['language_code'], self.fake_date) actual_outcome_list = suggestion.get_all_html_content_strings() expected_outcome_list = [ u'', u'<p>This is a hint.</p>', u'<p>This is a solution.</p>', u''] self.assertEqual(expected_outcome_list, actual_outcome_list)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_accept_suggestion_with_images(self): html_content = ( '<p>Value</p><oppia-noninteractive-math math_content-with-value=' '"{&amp;quot;raw_latex&amp;quot;: &amp;quot;+,-,-,+&amp;quot;, &' 'amp;quot;svg_filename&amp;quot;: &amp;quot;img.svg&amp;quot;}">' '</oppia-noninteractive-math>') question_state_dict = self._create_valid_question_data( 'default_state').to_dict() question_state_dict['content']['html'] = html_content with utils.open_file( os.path.join(feconf.TESTS_DATA_DIR, 'test_svg.svg'), 'rb', encoding=None) as f: raw_image = f.read() image_context = feconf.IMAGE_CONTEXT_QUESTION_SUGGESTIONS fs_services.save_original_and_compressed_versions_of_image( 'img.svg', image_context, 'skill1', raw_image, 'image', False) self.save_new_skill('skill1', self.author_id, description='description') suggestion_dict = { 'suggestion_id': 'skill1.thread1', 'suggestion_type': feconf.SUGGESTION_TYPE_ADD_QUESTION, 'target_type': feconf.ENTITY_TYPE_SKILL, 'target_id': 'skill1', 'target_version_at_submission': 1, 'status': suggestion_models.STATUS_ACCEPTED, 'author_name': 'author', 'final_reviewer_id': self.reviewer_id, 'change': { 'cmd': question_domain.CMD_CREATE_NEW_FULLY_SPECIFIED_QUESTION, 'question_dict': { 'question_state_data': question_state_dict, 'language_code': 'en', 'question_state_data_schema_version': ( feconf.CURRENT_STATE_SCHEMA_VERSION), 'linked_skill_ids': ['skill_1'], 'inapplicable_skill_misconception_ids': [] }, 'skill_id': 'skill1', 'skill_difficulty': 0.3, }, 'score_category': 'question.skill1', 'language_code': 'en', 'last_updated': utils.get_time_in_millisecs(self.fake_date) } suggestion = suggestion_registry.SuggestionAddQuestion( suggestion_dict['suggestion_id'], suggestion_dict['target_id'], suggestion_dict['target_version_at_submission'], suggestion_dict['status'], self.author_id, self.reviewer_id, suggestion_dict['change'], suggestion_dict['score_category'], suggestion_dict['language_code'], False, self.fake_date) suggestion.accept('commit_message')
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_contructor_updates_state_shema_in_change_cmd(self): score_category = ( suggestion_models.SCORE_TYPE_QUESTION + suggestion_models.SCORE_CATEGORY_DELIMITER + 'skill_id') change = { 'cmd': ( question_domain .CMD_CREATE_NEW_FULLY_SPECIFIED_QUESTION), 'question_dict': { 'question_state_data': self.VERSION_27_STATE_DICT, 'question_state_data_schema_version': 27, 'language_code': 'en', 'linked_skill_ids': ['skill_id'], 'inapplicable_skill_misconception_ids': [] }, 'skill_id': 'skill_id', 'skill_difficulty': 0.3 } self.assertEqual( change['question_dict']['question_state_data_schema_version'], 27) suggestion = suggestion_registry.SuggestionAddQuestion( 'suggestionId', 'target_id', 1, suggestion_models.STATUS_IN_REVIEW, self.author_id, None, change, score_category, 'en', False, self.fake_date) self.assertEqual( suggestion.change.question_dict[ 'question_state_data_schema_version'], feconf.CURRENT_STATE_SCHEMA_VERSION)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def __init__(self): # pylint: disable=super-init-not-called pass
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def setUp(self): super(BaseVoiceoverApplicationUnitTests, self).setUp() self.base_voiceover_application = MockInvalidVoiceoverApplication()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_base_class_accept_raises_error(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseVoiceoverApplication should implement accept.'): self.base_voiceover_application.accept()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def setUp(self): super(ExplorationVoiceoverApplicationUnitTest, self).setUp() self.signup('author@example.com', 'author') self.author_id = self.get_user_id_from_email('author@example.com') self.signup('reviewer@example.com', 'reviewer') self.reviewer_id = self.get_user_id_from_email('reviewer@example.com') self.voiceover_application = ( suggestion_registry.ExplorationVoiceoverApplication( 'application_id', 'exp_id', suggestion_models.STATUS_IN_REVIEW, self.author_id, None, 'en', 'audio_file.mp3', '<p>Content</p>', None))
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validation_with_invalid_target_id_raise_exception(self): self.voiceover_application.validate() self.voiceover_application.target_id = 123 with self.assertRaisesRegex( utils.ValidationError, 'Expected target_id to be a string' ): self.voiceover_application.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validation_with_invalid_author_id_raise_exception(self): self.voiceover_application.validate() self.voiceover_application.author_id = 123 with self.assertRaisesRegex( utils.ValidationError, 'Expected author_id to be a string' ): self.voiceover_application.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validation_for_handled_application_with_invalid_final_review(self): self.assertEqual( self.voiceover_application.status, suggestion_models.STATUS_IN_REVIEW) self.assertEqual(self.voiceover_application.final_reviewer_id, None) self.voiceover_application.validate() self.voiceover_application.status = suggestion_models.STATUS_ACCEPTED with self.assertRaisesRegex( utils.ValidationError, 'Expected final_reviewer_id to be a string' ): self.voiceover_application.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validation_for_accepted_application_with_message(self): self.assertEqual( self.voiceover_application.status, suggestion_models.STATUS_IN_REVIEW) self.assertEqual(self.voiceover_application.rejection_message, None) self.voiceover_application.validate() self.voiceover_application.final_reviewer_id = 'reviewer_id' self.voiceover_application.status = suggestion_models.STATUS_ACCEPTED self.voiceover_application.rejection_message = 'Invalid message' with self.assertRaisesRegex( utils.ValidationError, 'Expected rejection_message to be None for the accepted ' 'voiceover application, received Invalid message' ): self.voiceover_application.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validation_with_invalid_language_code_raise_exception(self): self.assertEqual(self.voiceover_application.language_code, 'en') self.voiceover_application.validate() self.voiceover_application.language_code = 'invalid language' with self.assertRaisesRegex( utils.ValidationError, 'Invalid language_code: invalid language' ): self.voiceover_application.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validation_with_invalid_content_type_raise_exception(self): self.assertEqual(self.voiceover_application.content, '<p>Content</p>') self.voiceover_application.validate() self.voiceover_application.content = 1 with self.assertRaisesRegex( utils.ValidationError, 'Expected content to be a string' ): self.voiceover_application.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_is_handled_property_returns_correct_value(self): self.assertFalse(self.voiceover_application.is_handled) self.voiceover_application.accept(self.reviewer_id) self.assertTrue(self.voiceover_application.is_handled)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_reject_voiceover_application(self): self.assertEqual(self.voiceover_application.final_reviewer_id, None) self.assertEqual(self.voiceover_application.status, 'review') self.voiceover_application.reject(self.reviewer_id, 'rejection message') self.assertEqual( self.voiceover_application.final_reviewer_id, self.reviewer_id) self.assertEqual(self.voiceover_application.status, 'rejected') self.assertEqual( self.voiceover_application.rejection_message, 'rejection message')
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def _assert_community_contribution_stats_is_in_default_state(self): """Checks if the community contribution stats is in its default state. """ community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) self.assertEqual( ( community_contribution_stats .translation_reviewer_counts_by_lang_code ), {}) self.assertEqual( ( community_contribution_stats .translation_suggestion_counts_by_lang_code ), {}) self.assertEqual( community_contribution_stats.question_reviewer_count, 0) self.assertEqual( community_contribution_stats.question_suggestion_count, 0)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_set_translation_reviewer_count_for_lang_code_updates_empty_dict( self): community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) self._assert_community_contribution_stats_is_in_default_state() ( community_contribution_stats .set_translation_reviewer_count_for_language_code( self.sample_language_code, 2) ) self.assertDictEqual( ( community_contribution_stats .translation_reviewer_counts_by_lang_code ), {self.sample_language_code: 2} )
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_set_translation_reviewer_count_for_lang_code_adds_new_lang_key( self): community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) self._assert_community_contribution_stats_is_in_default_state() ( community_contribution_stats .translation_reviewer_counts_by_lang_code ) = {'en': 1} ( community_contribution_stats .set_translation_reviewer_count_for_language_code('hi', 2) ) self.assertDictEqual( ( community_contribution_stats .translation_reviewer_counts_by_lang_code ), {'en': 1, 'hi': 2} )
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_set_translation_suggestion_count_for_lang_code_updates_count_value( self): community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) self._assert_community_contribution_stats_is_in_default_state() ( community_contribution_stats .translation_suggestion_counts_by_lang_code ) = {self.sample_language_code: 1} ( community_contribution_stats .set_translation_suggestion_count_for_language_code( self.sample_language_code, 2) ) self.assertDictEqual( ( community_contribution_stats .translation_suggestion_counts_by_lang_code ), {self.sample_language_code: 2} )
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_get_translation_language_codes_that_need_reviewers_for_one_lang( self): stats = suggestion_services.get_community_contribution_stats() stats.set_translation_suggestion_count_for_language_code( self.sample_language_code, 1) language_codes_that_need_reviewers = ( stats.get_translation_language_codes_that_need_reviewers() ) self.assertEqual( language_codes_that_need_reviewers, {self.sample_language_code})
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_get_translation_language_codes_that_need_reviewers_for_no_lang( self): stats = suggestion_services.get_community_contribution_stats() language_codes_that_need_reviewers = ( stats.get_translation_language_codes_that_need_reviewers() ) self.assertEqual( language_codes_that_need_reviewers, set())
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_translation_reviewers_are_needed_if_num_suggestions_past_max(self): stats = suggestion_services.get_community_contribution_stats() stats.set_translation_suggestion_count_for_language_code( self.sample_language_code, 2) stats.set_translation_reviewer_count_for_language_code( self.sample_language_code, 1) config_services.set_property( 'committer_id', 'max_number_of_suggestions_per_reviewer', 1) reviewers_are_needed = ( stats.are_translation_reviewers_needed_for_lang_code( self.sample_language_code)) self.assertTrue(reviewers_are_needed)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_translation_reviewers_not_needed_if_num_suggestions_less_max(self): stats = suggestion_services.get_community_contribution_stats() stats.set_translation_suggestion_count_for_language_code( self.sample_language_code, 1) stats.set_translation_reviewer_count_for_language_code( self.sample_language_code, 2) config_services.set_property( 'committer_id', 'max_number_of_suggestions_per_reviewer', 1) reviewers_are_needed = ( stats.are_translation_reviewers_needed_for_lang_code( self.sample_language_code)) self.assertFalse(reviewers_are_needed)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_translation_reviewers_not_needed_if_no_reviewers_no_sugestions( self): stats = suggestion_services.get_community_contribution_stats() self._assert_community_contribution_stats_is_in_default_state() self.assertFalse( stats.are_translation_reviewers_needed_for_lang_code( self.sample_language_code))
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_question_reviewers_are_needed_if_num_suggestions_past_max(self): stats = suggestion_services.get_community_contribution_stats() stats.question_suggestion_count = 2 stats.question_reviewer_count = 1 config_services.set_property( 'committer_id', 'max_number_of_suggestions_per_reviewer', 1) reviewers_are_needed = stats.are_question_reviewers_needed() self.assertTrue(reviewers_are_needed)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_question_reviewers_not_needed_if_num_suggestions_less_max(self): stats = suggestion_services.get_community_contribution_stats() stats.question_suggestion_count = 1 stats.question_reviewer_count = 2 config_services.set_property( 'committer_id', 'max_number_of_suggestions_per_reviewer', 1) reviewers_are_needed = stats.are_question_reviewers_needed() self.assertFalse(reviewers_are_needed)
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_translation_reviewer_counts_fails_for_negative_counts( self): community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) ( community_contribution_stats .set_translation_reviewer_count_for_language_code( self.sample_language_code, self.negative_count) ) with self.assertRaisesRegex( utils.ValidationError, 'Expected the translation reviewer count to be non-negative for ' '%s language code, received: %s.' % ( self.sample_language_code, self.negative_count) ): community_contribution_stats.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_question_reviewer_count_fails_for_negative_count(self): community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) community_contribution_stats.question_reviewer_count = ( self.negative_count ) with self.assertRaisesRegex( utils.ValidationError, 'Expected the question reviewer count to be non-negative, ' 'received: %s.' % ( community_contribution_stats.question_reviewer_count) ): community_contribution_stats.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_translation_reviewer_counts_fails_for_non_integer_counts( self): community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) ( community_contribution_stats .set_translation_reviewer_count_for_language_code( self.sample_language_code, self.non_integer_count) ) with self.assertRaisesRegex( utils.ValidationError, 'Expected the translation reviewer count to be an integer for ' '%s language code, received: %s.' % ( self.sample_language_code, self.non_integer_count) ): community_contribution_stats.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_question_reviewer_count_fails_for_non_integer_count( self): community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) community_contribution_stats.question_reviewer_count = ( self.non_integer_count ) with self.assertRaisesRegex( utils.ValidationError, 'Expected the question reviewer count to be an integer, ' 'received: %s.' % ( community_contribution_stats.question_reviewer_count) ): community_contribution_stats.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_validate_translation_reviewer_counts_fails_for_invalid_lang_code( self): community_contribution_stats = ( suggestion_services.get_community_contribution_stats() ) ( community_contribution_stats .set_translation_reviewer_count_for_language_code( self.invalid_language_code, 1) ) with self.assertRaisesRegex( utils.ValidationError, 'Invalid language code for the translation reviewer counts: ' '%s.' % self.invalid_language_code ): community_contribution_stats.validate()
oppia/oppia
[ 4927, 2897, 4927, 1181, 1439511374 ]
def test_parse_sections(): simple_mariofile_sections = dict(mariofile.parse_sections(SIMPLE_MARIOFILE.splitlines(True))) assert len(simple_mariofile_sections) == 3 complex_mariofile_sections = dict(mariofile.parse_sections(COMPLEX_MARIOFILE.splitlines(True))) assert len(complex_mariofile_sections) == 2 assert sorted(complex_mariofile_sections.keys()) == ['DEFAULT', 'section'] assert complex_mariofile_sections['DEFAULT'] == ['default text\n', '\n'] with pytest.raises(mariofile.ConfigurationFileError): dict(mariofile.parse_sections(GARBAGE_MARIOFILE.splitlines(True))) with pytest.raises(mariofile.ConfigurationFileError): dict(mariofile.parse_sections(INVALID_SECTION_MARIOFILE.splitlines(True))) more_complex_mariofile_sections = dict( mariofile.parse_sections(MORE_COMPLEX_MARIOFILE.splitlines(True)) ) more_complex_mariofile_sections_keys = ['DEFAULT', 'section_one', 'section_two', 'three'] assert sorted(more_complex_mariofile_sections.keys()) == more_complex_mariofile_sections_keys assert more_complex_mariofile_sections['three'] == []
bopen/mariobros
[ 15, 4, 15, 1, 1430924766 ]
def test_statements(): with pytest.raises(mariofile.ConfigurationFileError): mariofile.parse_section_body(CRASH_MARIOFILE_1.splitlines()) with pytest.raises(mariofile.ConfigurationFileError): mariofile.parse_section_body(CRASH_MARIOFILE_2.splitlines())
bopen/mariobros
[ 15, 4, 15, 1, 1430924766 ]
def test_parse_statements(): parsed_statement = mariofile.parse_statements(STRING_PARSE_STATEMENTS.splitlines()) assert '\n'.join(parsed_statement) == "statement\nstatement con commento"
bopen/mariobros
[ 15, 4, 15, 1, 1430924766 ]
def test_parse_section_body(): output_section = { 'action_template': ' task', 'sources_repls': 'source', 'variable': '6', 'target_pattern': 'target', } assert mariofile.parse_section_body(SECTION.splitlines(True)) == output_section with pytest.raises(mariofile.ConfigurationFileError): mariofile.parse_section_body(SECTION_MULTIPLE_RULE.splitlines(True)) with pytest.raises(mariofile.ConfigurationFileError): mariofile.parse_section_body(INVALID_CONFIG.splitlines(True))
bopen/mariobros
[ 15, 4, 15, 1, 1430924766 ]
def test_parse_include(): filepaths, current_line = mariofile.parse_include(INCLUDE_FILE.splitlines(True)) assert filepaths == ['prova.ini', 'altrofile.ini'] assert current_line == 4 filepaths, current_line = mariofile.parse_include(INCLUDE_UNIQUE_FILE.splitlines(True)) assert filepaths == ['prova.ini'] assert current_line == 1
bopen/mariobros
[ 15, 4, 15, 1, 1430924766 ]
def check_permissions(self, perm_db, perm_set, path): invalid = [] for p in perm_set: if ':' not in p: invalid.append(p) continue s, a = p.split(':', 1) if s not in perm_db: invalid.append(p) continue if '*' in a: if not fnmatch.filter(perm_db[s], a): invalid.append(p) continue elif a not in perm_db[s]: invalid.append(p) if not invalid: return [] return [(path, invalid)]
kapilt/cloud-custodian
[ 2, 2, 2, 8, 1461493242 ]
def setUpTestData(cls): cls.setup_users() cls.setup_categories() cls.setup_authors() cls.setup_languages() cls.setup_books() cls.setup_added_books() cls.setup_book_rating() cls.setup_book_comment() cls.setup_post_messages() cls.setup_support_messages()
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_users(cls): client = Client() cls.anonymous_user = auth.get_user(client) cls.user1 = User.objects.create_user('user1', 'user1@user1.com', 'testpassword1') cls.user2 = User.objects.create_user('user2', 'user2@user2.com', 'testpassword2') cls.user3 = User.objects.create_user('user3', 'user3@user3.com', 'testpassword3') cls.user4 = User.objects.create_user('user4', 'user4@user4.com', 'testpassword4') cls.user5 = User.objects.create_user('user5', 'user5@user5.com', 'testpassword5') cls.user6 = User.objects.create_user('user6', 'user6@user6.com', 'testpassword6') cls.the_user1 = TheUser.objects.get(id_user=cls.user1) cls.the_user2 = TheUser.objects.get(id_user=cls.user2) cls.the_user5 = TheUser.objects.get(id_user=cls.user5) cls.the_user6 = TheUser.objects.get(id_user=cls.user6)
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_categories(cls): cls.category1 = Category.objects.create(category_name='category1') cls.category2 = Category.objects.create(category_name='category2')
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_authors(cls): cls.author1 = Author.objects.create(author_name='Best Author 1') cls.author2 = Author.objects.create(author_name='trueAuthorNew') cls.author3 = Author.objects.create(author_name='zlast author') cls.author4 = Author.objects.create(author_name='<AuthorSpecialSymbols>&"') cls.author5 = Author.objects.create(author_name="O'Connor")
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_languages(cls): cls.language_en = Language.objects.create(language='English') cls.language_ru = Language.objects.create(language='Russian')
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_books(cls): test_book_path = os.path.join(TEST_DATA_DIR, 'test_book.pdf') test_book_image_path = os.path.join(TEST_DATA_DIR, 'test_book_image.png') books_setup = [ { 'name': 'First Book', 'author': cls.author1, 'category': cls.category1, 'language': cls.language_en, 'file': SimpleUploadedFile('test_book.pdf', open(test_book_path, 'rb').read()), 'photo': SimpleUploadedFile('test_book_image.png', open(test_book_image_path, 'rb').read()), 'who_added': cls.the_user1, 'private': True }, { 'name': 'Second Book', 'author': cls.author2, 'category': cls.category1, 'language': cls.language_en, 'file': SimpleUploadedFile('test_book.pdf', open(test_book_path, 'rb').read()), 'who_added': cls.the_user2, 'blocked_book': True }, { 'name': 'Third Book', 'author': cls.author2, 'category': cls.category1, 'language': cls.language_ru, 'file': SimpleUploadedFile('test_book.pdf', open(test_book_path, 'rb').read()), 'photo': SimpleUploadedFile('test_book_image.png', open(test_book_image_path, 'rb').read()), 'who_added': cls.the_user1, 'blocked_book': True }, { 'name': 'Fourth Book', 'author': cls.author1, 'category': cls.category1, 'language': cls.language_ru, 'file': SimpleUploadedFile('test_book.pdf', open(test_book_path, 'rb').read()), 'photo': SimpleUploadedFile('test_book_image.png', open(test_book_image_path, 'rb').read()), 'who_added': cls.the_user2, 'blocked_book': True }, { 'name': 'Fifth Book', 'author': cls.author1, 'category': cls.category2, 'language': cls.language_ru, 'file': SimpleUploadedFile('test_book.pdf', open(test_book_path, 'rb').read()), 'who_added': cls.the_user1, 'private': True }, { 'name': 'Sixth Book', 'author': cls.author2, 'category': cls.category2, 'language': cls.language_en, 'file': SimpleUploadedFile('test_book.pdf', open(test_book_path, 'rb').read()), 'photo': SimpleUploadedFile('test_book_image.png', open(test_book_image_path, 'rb').read()), 'who_added': cls.the_user2 }, { 'name': 'Seventh Book<>&"', 'author': cls.author4, 'category': cls.category2, 'language': cls.language_en, 'file': SimpleUploadedFile('test_book.pdf', open(test_book_path, 'rb').read()), 'photo': SimpleUploadedFile('test_book_image.png', open(test_book_image_path, 'rb').read()), 'who_added': cls.the_user2 } ] for book in books_setup: Book.objects.create( book_name=book['name'], id_author=book['author'], id_category=book['category'], description='TEST description', language=book['language'], book_file=book['file'], photo=book.get('photo', False), who_added=book['who_added'], private_book=book.get('private', False), blocked_book=book.get('blocked_book', False) )
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_added_books(cls): AddedBook.objects.create(id_user=cls.the_user1, id_book=Book.objects.get(book_name='Third Book')) AddedBook.objects.create(id_user=cls.the_user1, id_book=Book.objects.get(book_name='Sixth Book')) AddedBook.objects.create(id_user=cls.the_user1, id_book=Book.objects.get(book_name='Fourth Book')) AddedBook.objects.create(id_user=cls.the_user2, id_book=Book.objects.get(book_name='Third Book')) AddedBook.objects.create(id_user=cls.the_user2, id_book=Book.objects.get(book_name='Sixth Book')) AddedBook.objects.create(id_user=cls.the_user2, id_book=Book.objects.get(book_name='Second Book')) AddedBook.objects.create(id_user=cls.the_user5, id_book=Book.objects.get(book_name='Sixth Book')) AddedBook.objects.create(id_user=cls.the_user6, id_book=Book.objects.get(book_name='Sixth Book'))
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_book_rating(cls): BookRating.objects.create(id_book=Book.objects.get(book_name='Third Book'), id_user=cls.the_user1, rating=10) BookRating.objects.create(id_book=Book.objects.get(book_name='Third Book'), id_user=cls.the_user2, rating=5) BookRating.objects.create(id_book=Book.objects.get(book_name='Third Book'), id_user=cls.the_user5, rating=3) BookRating.objects.create(id_book=Book.objects.get(book_name='Fourth Book'), id_user=cls.the_user1, rating=7) BookRating.objects.create(id_book=Book.objects.get(book_name='Sixth Book'), id_user=cls.the_user1, rating=4) BookRating.objects.create(id_book=Book.objects.get(book_name='Second Book'), id_user=cls.the_user2, rating=7)
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_book_comment(cls): second_book = Book.objects.get(book_name='Second Book') third_book = Book.objects.get(book_name='Third Book') fourth_book = Book.objects.get(book_name='Fourth Book') BookComment.objects.create(id_book=second_book, id_user=cls.the_user1, text='Test book 2 user 1') BookComment.objects.create(id_book=second_book, id_user=cls.the_user2, text='Test book 2 user 2') BookComment.objects.create(id_book=third_book, id_user=cls.the_user1, text='Test book 3 user 1') BookComment.objects.create(id_book=fourth_book, id_user=cls.the_user1, text='Test book 4 user 1') BookComment.objects.create(id_book=fourth_book, id_user=cls.the_user5, text='Test book 4 user 5')
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_post_messages(cls): Post.objects.create(user=cls.the_user1, heading='post 1', text='Posted test text 1') Post.objects.create(user=cls.the_user1, heading='post 2', text='Posted test text 2') Post.objects.create(user=cls.the_user2, heading='post 3', text='Posted test text 3')
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def setup_support_messages(cls): SupportMessage.objects.create(email='testemail1@mail.co', text='Test text1') SupportMessage.objects.create(email='testemail1@mail.co', text='Test text2') SupportMessage.objects.create(email='test_email22@mail.co', text='Test text3') SupportMessage.objects.create(email='test_email23@mail.co', text='Test text4')
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def test_the_user_str(self): self.assertEqual(str(self.the_user1), 'user1') self.assertEqual(str(self.the_user2), 'user2')
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def test_creating_the_user_objects(self): """ Must create 'app.models.TheUser' instance after django User instance was created. """ self.assertEqual(User.objects.all().count(), 6) self.assertEqual(User.objects.all().count(), TheUser.objects.all().count()) self.assertNotEqual(self.the_user1.auth_token, '') self.assertNotEqual(self.the_user1.auth_token, self.the_user2.auth_token)
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def test_the_user_get_api_reminders(self): reminders = self.the_user1.get_api_reminders() reminders_keys_correct = ['vk', 'fb_group', 'fb_page', 'twitter', 'disabled_all', 'app_rate'] self.assertTrue(isinstance(reminders, dict)) self.assertEqual(sorted(list(reminders.keys())), sorted(reminders_keys_correct))
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]
def test_the_user_get_web_reminders(self): reminders = self.the_user1.get_web_reminders() reminders_keys_correct = ['vk', 'fb_group', 'fb_page', 'twitter', 'disabled_all', 'app_download'] self.assertTrue(isinstance(reminders, dict)) self.assertEqual(sorted(list(reminders.keys())), sorted(reminders_keys_correct))
OlegKlimenko/Plamber
[ 9, 1, 9, 28, 1487368387 ]