Example #1
0
 def test_can_not_mark_training_jobs_failed_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_jobs_failed(['invalid_job_id'])
    def test_mark_training_jobs_failed(self):
        """Test the mark_training_job_failed method."""
        exp_id = u'1'
        state_name = 'Home'
        interaction_id = 'TextInput'
        algorithm_id = feconf.INTERACTION_CLASSIFIER_MAPPING[interaction_id][
            'algorithm_id']
        algorithm_version = feconf.INTERACTION_CLASSIFIER_MAPPING[
            interaction_id]['algorithm_version']
        job_id = self._create_classifier_training_job(
            algorithm_id, interaction_id, exp_id, 1,
            datetime.datetime.utcnow(), [], state_name,
            feconf.TRAINING_JOB_STATUS_PENDING, {}, algorithm_version)

        classifier_training_job = (
            classifier_services.get_classifier_training_job_by_id(job_id))
        self.assertEqual(classifier_training_job.status,
                         feconf.TRAINING_JOB_STATUS_PENDING)

        classifier_services.mark_training_jobs_failed([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_FAILED)

        # 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_FAILED,
                             feconf.TRAINING_JOB_STATUS_FAILED))):
            classifier_services.mark_training_jobs_failed([job_id])
Example #3
0
 def test_next_job_handler(self):
     json_response = self.post_json(
         '/ml/nextjobhandler', self.payload, expected_status_int=200)
     self.assertEqual(json_response, self.expected_response)
     classifier_services.mark_training_jobs_failed([self.job_id])
     json_response = self.post_json(
         '/ml/nextjobhandler', self.payload, expected_status_int=200)
     self.assertEqual(json_response, {})