input
stringlengths
11
7.65k
target
stringlengths
22
8.26k
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def main(): import io import sys import argparse from .__init__ import __version__ from femagtools.bch import Reader argparser = argparse.ArgumentParser( description='Read BCH/BATCH/PLT file and create a plot') argparser.add_argument('filename', help='name of BCH/BATCH/PLT file') argparser.add_argument( "--version", "-v", action="version", version="%(prog)s {}, Python {}".format(__version__, sys.version), help="display version information", ) args = argparser.parse_args() if not matplotlibversion: sys.exit(0) if not args.filename: sys.exit(0) ext = args.filename.split('.')[-1].upper() if ext.startswith('MC'): import femagtools.mcv mcv = femagtools.mcv.read(sys.argv[1]) if mcv['mc1_type'] in (femagtools.mcv.MAGCRV, femagtools.mcv.ORIENT_CRV): ncols = 2 else: # Permanent Magnet ncols = 1 fig, ax = plt.subplots(nrows=1, ncols=ncols, figsize=(10, 6)) if ncols > 1: plt.subplot(1, 2, 1) mcv_hbj(mcv) plt.subplot(1, 2, 2) mcv_muer(mcv) else: mcv_hbj(mcv, log=False) fig.tight_layout() fig.subplots_adjust(top=0.94) plt.show() return if ext.startswith('PLT'): import femagtools.forcedens fdens = femagtools.forcedens.read(args.filename) cols = 1 rows = 2 fig, ax = plt.subplots(nrows=rows, ncols=cols, figsize=(10, 10*rows)) title = '{}, Rotor position {}'.format( fdens.title, fdens.positions[0]['position']) pos = fdens.positions[0]['X'] FT_FN = (fdens.positions[0]['FT'], fdens.positions[0]['FN']) plt.subplot(rows, cols, 1) forcedens(title, pos, FT_FN) title = 'Force Density Harmonics' plt.subplot(rows, cols, 2) forcedens_fft(title, fdens) # fig.tight_layout(h_pad=3.5) # if title: # fig.subplots_adjust(top=0.92) plt.show() return bchresults = Reader() with io.open(args.filename, encoding='latin1', errors='ignore') as f: bchresults.read(f.readlines()) if (bchresults.type.lower().find( 'pm-synchronous-motor simulation') >= 0 or bchresults.type.lower().find( 'permanet-magnet-synchronous-motor') >= 0 or bchresults.type.lower().find( 'simulation pm/universal-motor') >= 0): pmrelsim(bchresults, bchresults.filename) elif bchresults.type.lower().find( 'multiple calculation of forces and flux') >= 0: multcal(bchresults, bchresults.filename) elif bchresults.type.lower().find('cogging calculation') >= 0: cogging(bchresults, bchresults.filename) elif bchresults.type.lower().find('ld-lq-identification') >= 0: ldlq(bchresults) elif bchresults.type.lower().find('psid-psiq-identification') >= 0: psidq(bchresults) elif bchresults.type.lower().find('fast_torque calculation') >= 0: fasttorque(bchresults) elif bchresults.type.lower().find('transient sc') >= 0: transientsc(bchresults, bchresults.filename) else: raise ValueError("BCH type {} not yet supported".format( bchresults.type)) plt.show()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def characteristics(char, title=''): fig, axs = plt.subplots(2, 2, figsize=(10, 8), sharex=True) if title: fig.suptitle(title) n = np.array(char['n'])*60 pmech = np.array(char['pmech'])*1e-3 axs[0, 0].plot(n, np.array(char['T']), 'C0-', label='Torque') axs[0, 0].set_ylabel("Torque / Nm") axs[0, 0].grid() axs[0, 0].legend(loc='center left') ax1 = axs[0, 0].twinx() ax1.plot(n, pmech, 'C1-', label='P mech') ax1.set_ylabel("Power / kW") ax1.legend(loc='lower center') axs[0, 1].plot(n[1:], np.array(char['u1'][1:]), 'C0-', label='Voltage') axs[0, 1].set_ylabel("Voltage / V",) axs[0, 1].grid() axs[0, 1].legend(loc='center left') ax2 = axs[0, 1].twinx() ax2.plot(n[1:], char['cosphi'][1:], 'C1-', label='Cos Phi') ax2.set_ylabel("Cos Phi") ax2.legend(loc='lower right') if 'id' in char: axs[1, 0].plot(n, np.array(char['id']), label='Id') if 'iq' in char: axs[1, 0].plot(n, np.array(char['iq']), label='Iq') axs[1, 0].plot(n, np.array(char['i1']), label='I1') axs[1, 0].set_xlabel("Speed / rpm") axs[1, 0].set_ylabel("Current / A") axs[1, 0].legend(loc='center left') if 'beta' in char: ax3 = axs[1, 0].twinx() ax3.plot(n, char['beta'], 'C3-', label='Beta') ax3.set_ylabel("Beta / °") ax3.legend(loc='center right') axs[1, 0].grid() plfe = np.array(char['plfe'])*1e-3 plcu = np.array(char['plcu'])*1e-3 pl = np.array(char['losses'])*1e-3 axs[1, 1].plot(n, plcu, 'C0-', label='Cu Losses') axs[1, 1].plot(n, plfe, 'C1-', label='Fe Losses') axs[1, 1].set_ylabel("Losses / kW") axs[1, 1].legend(loc='center left') axs[1, 1].grid() axs[1, 1].set_xlabel("Speed / rpm") ax4 = axs[1, 1].twinx() ax4.plot(n[1:-1], char['eta'][1:-1], 'C3-', label="Eta") ax4.legend(loc='upper center') ax4.set_ylabel("Efficiency") fig.tight_layout()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def runcmd(cmd, **kw): # same code as in getlino.py """Run the cmd similar as os.system(), but stop when Ctrl-C.""" # kw.update(stdout=subprocess.PIPE) # kw.update(stderr=subprocess.STDOUT) kw.update(shell=True) kw.update(universal_newlines=True) kw.update(check=True) # subprocess.check_output(cmd, **kw) subprocess.run(cmd, **kw) # os.system(cmd)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=True, help='Do not prompt for input of any kind.') parser.add_argument('-l', '--list', action='store_true', dest='list', default=False, help="Just list the requirements, don't install them.")
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_watch_task(client): user = f.UserFactory.create() task = f.create_task(owner=user, milestone=None) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) url = reverse("tasks-watch", args=(task.id,)) client.login(user) response = client.post(url) assert response.status_code == 200
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_unwatch_task(client): user = f.UserFactory.create() task = f.create_task(owner=user, milestone=None) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) url = reverse("tasks-watch", args=(task.id,)) client.login(user) response = client.post(url) assert response.status_code == 200
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_list_task_watchers(client): user = f.UserFactory.create() task = f.TaskFactory(owner=user) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) f.WatchedFactory.create(content_object=task, user=user) url = reverse("task-watchers-list", args=(task.id,)) client.login(user) response = client.get(url) assert response.status_code == 200 assert response.data[0]['id'] == user.id
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_get_task_watcher(client): user = f.UserFactory.create() task = f.TaskFactory(owner=user) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) watch = f.WatchedFactory.create(content_object=task, user=user) url = reverse("task-watchers-detail", args=(task.id, watch.user.id)) client.login(user) response = client.get(url) assert response.status_code == 200 assert response.data['id'] == watch.user.id
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_get_task_watchers(client): user = f.UserFactory.create() task = f.TaskFactory(owner=user) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) url = reverse("tasks-detail", args=(task.id,)) f.WatchedFactory.create(content_object=task, user=user) client.login(user) response = client.get(url) assert response.status_code == 200 assert response.data['watchers'] == [user.id] assert response.data['total_watchers'] == 1
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_get_task_is_watcher(client): user = f.UserFactory.create() task = f.create_task(owner=user, milestone=None) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) url_detail = reverse("tasks-detail", args=(task.id,)) url_watch = reverse("tasks-watch", args=(task.id,)) url_unwatch = reverse("tasks-unwatch", args=(task.id,)) client.login(user) response = client.get(url_detail) assert response.status_code == 200 assert response.data['watchers'] == [] assert response.data['is_watcher'] == False response = client.post(url_watch) assert response.status_code == 200 response = client.get(url_detail) assert response.status_code == 200 assert response.data['watchers'] == [user.id] assert response.data['is_watcher'] == True response = client.post(url_unwatch) assert response.status_code == 200 response = client.get(url_detail) assert response.status_code == 200 assert response.data['watchers'] == [] assert response.data['is_watcher'] == False
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self): self.var = 0
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def connect (): ''' Create the connection to the MongoDB and create 3 collections needed ''' try: # Create the connection to the local host conn = pymongo.MongoClient() print 'MongoDB Connection Successful' except pymongo.errors.ConnectionFailure, err: print 'MongoDB Connection Unsuccessful' return False
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self): self.var = 0 # self.var will be overwritten
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def make_new_rsa_key_weak(bits): return RSA.generate(bits) # NOT OK
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def _build_gravatar_url(email, params): """Generate a Gravatar URL.
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def make_new_rsa_key_strong(bits): return RSA.generate(bits) # OK
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self, email, params): self.email = email self.params = params
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def render(self, context): try: if self.params: params = template.Variable(self.params).resolve(context) else: params = {} # try matching an address string literal email_literal = self.email.strip().lower() if EMAIL_RE.match(email_literal): email = email_literal # treat as a variable else: email = template.Variable(self.email).resolve(context) except template.VariableDoesNotExist: return '' # now, we generate the gravatar url return _build_gravatar_url(email, params)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self): # pylint: disable=super-init-not-called pass
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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'] == []
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def setUp(self): super(BaseSuggestionUnitTests, self).setUp() self.base_suggestion = MockInvalidSuggestion()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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())
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_accept_raises_error(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseSuggestion should implement accept.'): self.base_suggestion.accept()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_parse_statements(): parsed_statement = mariofile.parse_statements(STRING_PARSE_STATEMENTS.splitlines()) assert '\n'.join(parsed_statement) == "statement\nstatement con commento"
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_get_change_list_for_accepting_suggestion_raises_error( self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseSuggestion should implement ' 'get_change_list_for_accepting_suggestion.'): self.base_suggestion.get_change_list_for_accepting_suggestion()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_pre_accept_validate_raises_error(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseSuggestion should implement' ' pre_accept_validate.'): self.base_suggestion.pre_accept_validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_populate_old_value_of_change_raises_error(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseSuggestion should implement' ' populate_old_value_of_change.'): self.base_suggestion.populate_old_value_of_change()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_pre_update_validate_raises_error(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseSuggestion should implement' ' pre_update_validate.'): self.base_suggestion.pre_update_validate({})
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_get_all_html_content_strings(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseSuggestion should implement' ' get_all_html_content_strings.'): self.base_suggestion.get_all_html_content_strings()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_get_target_entity_html_strings(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseSuggestion should implement' ' get_target_entity_html_strings.'): self.base_suggestion.get_target_entity_html_strings()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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 }
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_create_suggestion_edit_state_content(self): expected_suggestion_dict = self.suggestion_dict observed_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) self.assertDictEqual( observed_suggestion.to_dict(), expected_suggestion_dict)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_get_score_part_helper_methods(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) self.assertEqual(suggestion.get_score_type(), 'content') self.assertEqual(suggestion.get_score_sub_type(), 'Algebra')
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_validate_target_version_at_submission(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_version_at_submission = 'invalid_version' with self.assertRaisesRegex( utils.ValidationError, 'Expected target_version_at_submission to be an int' ): suggestion.validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_convert_html_in_suggestion_change(self): html_content = ( '<p>Value</p><oppia-noninteractive-math raw_latex-with-value="&a' 'mp;quot;+,-,-,+&amp;quot;"></oppia-noninteractive-math>') expected_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;&amp;quot;}"></oppia' '-noninteractive-math>') change = { 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'state_name': 'Introduction', 'new_value': { 'content_id': 'content', 'html': '<p>suggestion</p>' }, 'old_value': { 'content_id': 'content', 'html': html_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, self.suggestion_dict['score_category'], self.suggestion_dict['language_code'], False, self.fake_date) suggestion.convert_html_in_suggestion_change( html_validation_service. add_math_content_to_math_rte_components) self.assertEqual( suggestion.change.old_value['html'], expected_html_content)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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 }
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_create_suggestion_add_translation(self): expected_suggestion_dict = self.suggestion_dict observed_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) self.assertDictEqual( observed_suggestion.to_dict(), expected_suggestion_dict)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_get_score_part_helper_methods(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) self.assertEqual(suggestion.get_score_type(), 'translation') self.assertEqual(suggestion.get_score_sub_type(), 'Algebra')
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_validate_author_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.author_id = 0 with self.assertRaisesRegex( utils.ValidationError, 'Expected author_id to be a string' ): suggestion.validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_accept_suggestion_adds_translation_in_exploration(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, self.suggestion_dict['change'], 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 })
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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 })
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_accept_suggestion_with_psedonymous_author_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(), {}) 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.PSEUDONYMOUS_ID, self.reviewer_id, expected_suggestion_dict['change'], expected_suggestion_dict['score_category'], expected_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 })
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_convert_html_in_suggestion_change(self): html_content = ( '<p>Value</p><oppia-noninteractive-math raw_latex-with-value="&a' 'mp;quot;+,-,-,+&amp;quot;"></oppia-noninteractive-math>') expected_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;&amp;quot;}"></oppia' '-noninteractive-math>') change_dict = { 'cmd': exp_domain.CMD_ADD_WRITTEN_TRANSLATION, 'state_name': 'Introduction', 'content_id': 'content', 'language_code': 'hi', 'content_html': html_content, 'translation_html': '<p>This is translated html.</p>', 'data_format': 'html' } 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, change_dict, self.suggestion_dict['score_category'], self.suggestion_dict['language_code'], False, self.fake_date) suggestion.convert_html_in_suggestion_change( html_validation_service.add_math_content_to_math_rte_components) self.assertEqual( suggestion.change.content_html, expected_html_content)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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 }
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_create_suggestion_add_question(self): expected_suggestion_dict = self.suggestion_dict observed_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.assertDictEqual( observed_suggestion.to_dict(), expected_suggestion_dict)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_get_score_part_helper_methods(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.assertEqual(suggestion.get_score_type(), 'question') self.assertEqual(suggestion.get_score_sub_type(), 'topic_1')
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_validate_change_question_state_data_schema_version(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() # We are not setting value in suggestion.change.question_dict # directly since pylint produces unsupported-assignment-operation # error. The detailed analysis for the same can be checked # in this issue: https://github.com/oppia/oppia/issues/7008. question_dict = suggestion.change.question_dict question_dict['question_state_data_schema_version'] = 0 suggestion.change.question_dict = question_dict with self.assertRaisesRegex( utils.ValidationError, 'Expected question state schema version to be %s, ' 'received 0' % feconf.CURRENT_STATE_SCHEMA_VERSION ): suggestion.validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_validate_change_skill_difficulty_invalid_value(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 = 0.4 with self.assertRaisesRegex( utils.ValidationError, 'Expected change skill_difficulty to be one of ' ): suggestion.validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_pre_accept_validate_change_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) 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 = skill_services.get_new_skill_id() with self.assertRaisesRegex( utils.ValidationError, 'The skill with the given id doesn\'t exist.' ): suggestion.pre_accept_validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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())
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_populate_old_value_of_change(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.populate_old_value_of_change())
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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')
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_pre_update_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) change = { 'cmd': question_domain.CMD_UPDATE_QUESTION_PROPERTY, 'property_name': question_domain.QUESTION_PROPERTY_LANGUAGE_CODE, 'new_value': 'bn', 'old_value': 'en' } with self.assertRaisesRegex( utils.ValidationError, 'The new change cmd must be equal to ' 'create_new_fully_specified_question' ): suggestion.pre_update_validate( question_domain.QuestionChange(change))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_pre_update_validate_complains_if_nothing_changed(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.3 } with self.assertRaisesRegex( utils.ValidationError, 'At least one of the new skill_difficulty or question_dict ' 'should be changed.'): suggestion.pre_update_validate( question_domain.QuestionSuggestionChange(new_change))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_pre_update_validate_accepts_a_change_in_state_data_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': 'hi', 'question_state_data_schema_version': ( feconf.CURRENT_STATE_SCHEMA_VERSION) }, 'skill_id': 'skill_1', 'skill_difficulty': 0.3 } self.assertEqual( suggestion.pre_update_validate( question_domain.QuestionSuggestionChange(new_change)), None)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_validate_author_id_format(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 = '' with self.assertRaisesRegex( utils.ValidationError, 'Expected author_id to be in a valid user ID format.'): suggestion.validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_convert_html_in_suggestion_change(self): html_content = ( '<p>Value</p><oppia-noninteractive-math raw_latex-with-value="&a' 'mp;quot;+,-,-,+&amp;quot;"></oppia-noninteractive-math>') expected_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;&amp;quot;}"></oppia' '-noninteractive-math>') answer_group = { 'outcome': { 'dest': None, 'feedback': { 'content_id': 'feedback_1', 'html': '' }, 'labelled_as_correct': True, 'param_changes': [], 'refresher_exploration_id': None, 'missing_prerequisite_skill_id': None }, 'rule_specs': [{ 'inputs': { 'x': 0 }, 'rule_type': 'Equals' }], 'training_data': [], 'tagged_skill_misconception_id': None } question_state_dict = { 'content': { 'content_id': 'content_1', 'html': html_content }, 'recorded_voiceovers': { 'voiceovers_mapping': { 'content_1': {}, 'feedback_1': {}, 'feedback_2': {}, 'hint_1': {}, 'solution': {} } }, 'written_translations': { 'translations_mapping': { 'content_1': {}, 'feedback_1': {}, 'feedback_2': {}, 'hint_1': {}, 'solution': {} } }, 'interaction': { 'answer_groups': [answer_group], 'confirmed_unclassified_answers': [], 'customization_args': { 'choices': { 'value': [{ 'html': 'option 1', 'content_id': 'ca_choices_0' }] }, 'showChoicesInShuffledOrder': { 'value': True } }, 'default_outcome': { 'dest': None, 'feedback': { 'content_id': 'feedback_2', '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': { 'answer_is_exclusive': False, 'correct_answer': 0, 'explanation': { 'content_id': 'solution', 'html': '<p>This is a solution.</p>' } }, 'id': 'MultipleChoiceInput' }, 'param_changes': [], 'solicit_answer_details': False, 'classifier_model_id': None } 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': ['skillid12345-1'] }, 'skill_id': 'skill_1', '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.convert_html_in_suggestion_change( html_validation_service.add_math_content_to_math_rte_components) self.assertEqual( suggestion.change.question_dict['question_state_data']['content'][ 'html'], expected_html_content)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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')
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_accept_suggestion_with_image_region_interactions(self): with utils.open_file( os.path.join(feconf.TESTS_DATA_DIR, 'img.png'), 'rb', encoding=None) as f: original_image_content = f.read() fs_services.save_original_and_compressed_versions_of_image( 'image.png', 'question_suggestions', 'skill1', original_image_content, 'image', True) question_state_dict = { 'content': { 'html': '<p>Text</p>', 'content_id': 'content' }, 'classifier_model_id': None, 'linked_skill_id': None, 'interaction': { 'answer_groups': [ { 'rule_specs': [ { 'rule_type': 'IsInRegion', 'inputs': {'x': 'Region1'} } ], 'outcome': { 'dest': None, 'feedback': { 'html': '<p>assas</p>', 'content_id': 'feedback_0' }, 'labelled_as_correct': True, 'param_changes': [], 'refresher_exploration_id': None, 'missing_prerequisite_skill_id': None }, 'training_data': [], 'tagged_skill_misconception_id': None } ], 'confirmed_unclassified_answers': [], 'customization_args': { 'imageAndRegions': { 'value': { 'imagePath': 'image.png', 'labeledRegions': [ { 'label': 'Region1', 'region': { 'regionType': 'Rectangle', 'area': [ [ 0.2644628099173554, 0.21807065217391305 ], [ 0.9201101928374655, 0.8847373188405797 ] ] } } ] } }, 'highlightRegionsOnHover': { 'value': False } }, 'default_outcome': { 'dest': None, 'feedback': { 'html': '<p>wer</p>', 'content_id': 'default_outcome' }, 'labelled_as_correct': False, 'param_changes': [], 'refresher_exploration_id': None, 'missing_prerequisite_skill_id': None }, 'hints': [ { 'hint_content': { 'html': '<p>assaas</p>', 'content_id': 'hint_1' } } ], 'id': 'ImageClickInput', 'solution': None }, 'param_changes': [], 'recorded_voiceovers': { 'voiceovers_mapping': { 'content': {}, 'default_outcome': {}, 'feedback_0': {}, 'hint_1': {} } }, 'solicit_answer_details': False, 'card_is_checkpoint': False, 'written_translations': { 'translations_mapping': { 'content': {}, 'default_outcome': {}, 'feedback_0': {}, 'hint_1': {} } }, 'next_content_id_index': 2 } 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': ['skill1'], '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) } self.save_new_skill( 'skill1', self.author_id, description='description') 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') question = question_services.get_questions_by_skill_ids( 1, ['skill1'], False)[0] destination_fs = fs_domain.AbstractFileSystem( fs_domain.GcsFileSystem( feconf.ENTITY_TYPE_QUESTION, question.id)) self.assertTrue(destination_fs.isfile('image/%s' % 'image.png')) self.assertEqual( suggestion.status, suggestion_models.STATUS_ACCEPTED)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_contructor_raise_exception_for_invalid_state_shema_version(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': 23, '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'], 23) with self.assertRaisesRegex( utils.ValidationError, 'Expected state schema version to be in between 25' ): suggestion_registry.SuggestionAddQuestion( 'suggestionId', 'target_id', 1, suggestion_models.STATUS_IN_REVIEW, self.author_id, None, change, score_category, 'en', False, self.fake_date)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def setUp(self): super(BaseVoiceoverApplicationUnitTests, self).setUp() self.base_voiceover_application = MockInvalidVoiceoverApplication()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_init_raises_error(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseVoiceoverApplication should implement ' '__init__.'): suggestion_registry.BaseVoiceoverApplication()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_accept_raises_error(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseVoiceoverApplication should implement accept.'): self.base_voiceover_application.accept()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_base_class_reject_raises_error(self): with self.assertRaisesRegex( NotImplementedError, 'Subclasses of BaseVoiceoverApplication should implement reject.'): self.base_voiceover_application.reject()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_validation_for_rejected_application_with_no_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_REJECTED with self.assertRaisesRegex( utils.ValidationError, 'Expected rejection_message to be a string for a ' 'rejected application' ): self.voiceover_application.validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_validation_with_invalid_language_code_type_raise_exception(self): self.assertEqual(self.voiceover_application.language_code, 'en') self.voiceover_application.validate() self.voiceover_application.language_code = 1 with self.assertRaisesRegex( utils.ValidationError, 'Expected language_code to be a string' ): self.voiceover_application.validate()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_to_dict_returns_correct_dict(self): self.voiceover_application.accept(self.reviewer_id) expected_dict = { 'voiceover_application_id': 'application_id', 'target_type': 'exploration', 'target_id': 'exp_id', 'status': 'accepted', 'author_name': 'author', 'final_reviewer_name': 'reviewer', 'language_code': 'en', 'content': '<p>Content</p>', 'filename': 'audio_file.mp3', 'rejection_message': None } self.assertEqual( self.voiceover_application.to_dict(), expected_dict)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_accept_voiceover_application(self): self.assertEqual(self.voiceover_application.final_reviewer_id, None) self.assertEqual(self.voiceover_application.status, 'review') self.voiceover_application.accept(self.reviewer_id) self.assertEqual( self.voiceover_application.final_reviewer_id, self.reviewer_id) self.assertEqual(self.voiceover_application.status, 'accepted')
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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')
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_initial_object_with_valid_arguments_has_correct_properties(self): community_contribution_stats = ( suggestion_registry.CommunityContributionStats( self.translation_reviewer_counts_by_lang_code, self.translation_suggestion_counts_by_lang_code, self.question_reviewer_count, self.question_suggestion_count ) ) community_contribution_stats.validate() self.assertEqual( ( community_contribution_stats .translation_reviewer_counts_by_lang_code ), self.translation_reviewer_counts_by_lang_code) self.assertEqual( ( community_contribution_stats .translation_suggestion_counts_by_lang_code ), self.translation_suggestion_counts_by_lang_code ) self.assertEqual( community_contribution_stats.question_reviewer_count, self.question_reviewer_count ) self.assertEqual( community_contribution_stats.question_suggestion_count, self.question_suggestion_count )
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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} )
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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})
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_get_translation_language_codes_that_need_reviewers_for_multi_lang( self): stats = suggestion_services.get_community_contribution_stats() stats.set_translation_suggestion_count_for_language_code('hi', 1) stats.set_translation_suggestion_count_for_language_code('fr', 1) language_codes_that_need_reviewers = ( stats.get_translation_language_codes_that_need_reviewers() ) self.assertEqual( language_codes_that_need_reviewers, {'hi', 'fr'})
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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())
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_question_reviewers_are_needed_if_suggestions_zero_reviewers( self): stats = suggestion_services.get_community_contribution_stats() stats.question_suggestion_count = 1 self.assertTrue(stats.are_question_reviewers_needed())
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_question_reviewers_not_needed_if_num_suggestions_eqs_max(self): stats = suggestion_services.get_community_contribution_stats() stats.question_suggestion_count = 2 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)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
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)