예제 #1
0
    def test_mark_training_jobs_failed(self):
        """Test the mark_training_job_failed method."""
        exp_id = u'1'
        state_name = 'Home'
        interaction_id = 'TextInput'

        job_id = classifier_services.create_classifier_training_job(
            feconf.INTERACTION_CLASSIFIER_MAPPING[interaction_id]
            ['algorithm_id'], interaction_id, exp_id, 1, state_name, [],
            feconf.TRAINING_JOB_STATUS_PENDING)

        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])
예제 #2
0
    def setUp(self):
        super(NextJobHandlerTest, self).setUp()

        self.exp_id = 'exp_id1'
        self.title = 'Testing Classifier storing'
        self.category = 'Test'
        interaction_id = 'TextInput'
        self.algorithm_id = feconf.INTERACTION_CLASSIFIER_MAPPING[
            interaction_id]['algorithm_id']
        self.training_data = [
            {
                u'answer_group_index': 1,
                u'answers': [u'a1', u'a2']
            },
            {
                u'answer_group_index': 2,
                u'answers': [u'a2', u'a3']
            }
        ]
        self.job_id = classifier_services.create_classifier_training_job(
            self.algorithm_id, interaction_id, self.exp_id,
            1, 'Home', self.training_data,
            feconf.TRAINING_JOB_STATUS_NEW)
        self.expected_response = {
            u'job_id' : unicode(self.job_id, 'utf-8'),
            u'training_data' : self.training_data,
            u'algorithm_id' : unicode(self.algorithm_id, 'utf-8')
        }

        self.payload = {}
        self.payload['vm_id'] = feconf.DEFAULT_VM_ID
        secret = feconf.DEFAULT_VM_SHARED_SECRET
        self.payload['message'] = json.dumps({})
        self.payload['signature'] = classifier.generate_signature(
            secret, self.payload['message'])
예제 #3
0
    def test_fetch_next_job(self):
        """Test the fetch_next_jobs method."""
        exp1_id = u'1'
        state_name = 'Home'
        interaction_id = 'TextInput'
        exp2_id = u'2'

        job1_id = classifier_services.create_classifier_training_job(
            feconf.INTERACTION_CLASSIFIER_MAPPING[interaction_id]
            ['algorithm_id'], interaction_id, exp1_id, 1, state_name, [],
            feconf.TRAINING_JOB_STATUS_NEW)
        classifier_services.create_classifier_training_job(
            feconf.INTERACTION_CLASSIFIER_MAPPING[interaction_id]
            ['algorithm_id'], interaction_id, exp2_id, 1, state_name, [],
            feconf.TRAINING_JOB_STATUS_PENDING)
        # This will get the job_id of the exploration created in setup.
        classifier_services.fetch_next_job()
        next_job = classifier_services.fetch_next_job()
        self.assertEqual(job1_id, next_job.job_id)