def test_mark_training_job_pending(self): """Test the mark_training_job_pending method.""" exp_id = u'1' state_name = 'Home' interaction_id = 'TextInput' job_id = self._create_classifier_training_job( feconf.INTERACTION_CLASSIFIER_MAPPING[interaction_id] ['algorithm_id'], interaction_id, exp_id, 1, datetime.datetime.utcnow(), [], state_name, feconf.TRAINING_JOB_STATUS_NEW, {}, 1) classifier_training_job = ( classifier_services.get_classifier_training_job_by_id(job_id)) self.assertEqual(classifier_training_job.status, feconf.TRAINING_JOB_STATUS_NEW) classifier_services.mark_training_job_pending(job_id) classifier_training_job = ( classifier_services.get_classifier_training_job_by_id(job_id)) self.assertEqual(classifier_training_job.status, feconf.TRAINING_JOB_STATUS_PENDING) # Test that invalid status changes cannot be made. with self.assertRaisesRegexp( Exception, ('The status change %s to %s is not valid.' % (feconf.TRAINING_JOB_STATUS_PENDING, feconf.TRAINING_JOB_STATUS_PENDING))): classifier_services.mark_training_job_pending(job_id)
def test_can_not_mark_training_jobs_pending_due_to_invalid_job_id( self) -> None: with self.assertRaisesRegex( # type: ignore[no-untyped-call] Exception, 'The ClassifierTrainingJobModel corresponding to the ' 'job_id of the ClassifierTrainingJob does not exist.'): classifier_services.mark_training_job_pending('invalid_job_id')
def post(self): """Handles POST requests.""" response = {} next_job = classifier_services.fetch_next_job() if next_job is not None: classifier_services.mark_training_job_pending(next_job.job_id) response['job_id'] = next_job.job_id response['algorithm_id'] = next_job.algorithm_id response['algorithm_version'] = next_job.algorithm_version response['training_data'] = next_job.training_data return self.render_json(response)
def post(self): """Handles POST requests.""" signature = self.payload.get('signature') vm_id = self.payload.get('vm_id') message = self.payload.get('message') if vm_id == feconf.DEFAULT_VM_ID and not feconf.DEV_MODE: raise self.UnauthorizedUserException if not verify_signature(message, vm_id, signature): raise self.UnauthorizedUserException response = {} next_job = classifier_services.fetch_next_job() if next_job is not None: classifier_services.mark_training_job_pending(next_job.job_id) response['job_id'] = next_job.job_id response['algorithm_id'] = next_job.algorithm_id response['training_data'] = next_job.training_data return self.render_json(response)