Exemplo n.º 1
0
 def test_on_get_return_correct_data(self):
     self.mock_db.get_job.return_value = common.get_fake_job_0()
     self.resource.on_get(self.mock_req, self.mock_req,
                          common.fake_job_0_job_id)
     result = self.mock_req.body
     self.assertEqual(result, common.get_fake_job_0())
     self.assertEqual(self.mock_req.status, falcon.HTTP_200)
Exemplo n.º 2
0
 def test_on_get_return_correct_data(self):
     self.mock_db.get_job.return_value = common.get_fake_job_0()
     self.resource.on_get(self.mock_req, self.mock_req,
                          common.fake_job_0_job_id)
     result = self.mock_req.body
     self.assertEqual(common.get_fake_job_0(), result)
     self.assertEqual(falcon.HTTP_200, self.mock_req.status)
Exemplo n.º 3
0
 def test_on_get_return_correct_list(self):
     self.mock_db.search_job.return_value = [common.get_fake_job_0(),
                                             common.get_fake_job_1()]
     expected_result = {
         'jobs': [common.get_fake_job_0(), common.get_fake_job_1()]}
     self.resource.on_get(self.mock_req, self.mock_req)
     result = self.mock_req.body
     self.assertEqual(result, expected_result)
     self.assertEqual(self.mock_req.status, falcon.HTTP_200)
Exemplo n.º 4
0
 def test_on_post_inserts_correct_data(self):
     job = common.get_fake_job_0()
     self.mock_json_body.return_value = job
     self.mock_db.add_job.return_value = 'pjiofrdslaikfunr'
     expected_result = {'job_id': 'pjiofrdslaikfunr'}
     self.resource.on_post(self.mock_req, self.mock_req)
     self.assertEqual(falcon.HTTP_201, self.mock_req.status)
     self.assertEqual(expected_result, self.mock_req.body)
Exemplo n.º 5
0
 def test_on_post_raises_when_db_replace_job_raises(self):
     self.mock_db.replace_job.side_effect = exceptions.AccessForbidden(
         'regular test failure')
     job = common.get_fake_job_0()
     self.mock_req.stream.read.return_value = json.dumps(job)
     self.assertRaises(exceptions.AccessForbidden, self.resource.on_post,
                       self.mock_req, self.mock_req,
                       common.fake_job_0_job_id)
Exemplo n.º 6
0
 def test_on_post_inserts_correct_data(self):
     job = common.get_fake_job_0()
     self.mock_json_body.return_value = job
     self.mock_db.add_job.return_value = 'pjiofrdslaikfunr'
     expected_result = {'job_id': 'pjiofrdslaikfunr'}
     self.resource.on_post(self.mock_req, self.mock_req)
     self.assertEqual(self.mock_req.status, falcon.HTTP_201)
     self.assertEqual(self.mock_req.body, expected_result)
Exemplo n.º 7
0
 def test_on_post_raises_when_db_replace_job_raises(self):
     self.mock_db.replace_job.side_effect = exceptions.AccessForbidden(
         'regular test failure')
     job = common.get_fake_job_0()
     self.mock_req.stream.read.return_value = json.dumps(job)
     self.assertRaises(exceptions.AccessForbidden, self.resource.on_post,
                       self.mock_req,
                       self.mock_req,
                       common.fake_job_0_job_id)
Exemplo n.º 8
0
 def test_create_raises_BadDataFormat_when_isvalid_fails(self, mock_time,
                                                         mock_uuid):
     mock_time.time.return_value = 1433611337
     mock_uuid.uuid4.return_value = mock_uuid
     mock_uuid.hex = 'hotforteacher'
     job_doc = common.get_fake_job_0()
     job_doc['job_schedule']['event'] = 'not_valid'
     self.assertRaises(exceptions.BadDataFormat, utils.JobDoc.create,
                       job_doc, 'dude')
Exemplo n.º 9
0
 def setUp(self):
     super(ApiTestCase, self).setUp()
     self.fake_job_0 = common.get_fake_job_0()
     self.fake_client_0 = common.get_fake_client_0()
     self.fake_user_id = self.fake_job_0.get('user_id')
     self.fake_job_id = common.get_fake_job_id()
     self.fake_action_0 = common.get_fake_action_0()
     self.fake_backup_0 = common.get_fake_backup_metadata()
     self.fake_session_0 = common.get_fake_session_0()
     self.fake_session_id = common.get_fake_session_id()
     CONF.enable_v1_api = True
Exemplo n.º 10
0
 def setUp(self):
     super(DbJobTestCase, self).setUp()
     self.fake_job_0 = common.get_fake_job_0()
     self.fake_job_0.pop('job_id')
     self.fake_job_2 = common.get_fake_job_2()
     self.fake_job_2.pop('job_id')
     self.fake_job_3 = common.get_fake_job_3()
     self.fake_job_3.pop('job_id')
     self.fake_project_id = self.fake_job_0.get('project_id')
     self.fake_user_id = self.fake_job_0.get('user_id')
     self.fake_job_id = common.get_fake_job_id()
Exemplo n.º 11
0
 def setUp(self):
     super(DbJobTestCase, self).setUp()
     self.fake_job_0 = common.get_fake_job_0()
     self.fake_job_0.pop('job_id')
     self.fake_job_2 = common.get_fake_job_2()
     self.fake_job_2.pop('job_id')
     self.fake_job_3 = common.get_fake_job_3()
     self.fake_job_3.pop('job_id')
     self.fake_job_id = common.get_fake_job_id()
     self.fake_user_id = self.fake_job_0.get('user_id')
     CONF.enable_v1_api = True
Exemplo n.º 12
0
 def setUp(self):
     super(ApiTestCase, self).setUp()
     self.fake_job_0 = common.get_fake_job_0()
     self.fake_client_0 = common.get_fake_client_0()
     self.fake_project_id = self.fake_job_0.get('project_id')
     self.fake_user_id = self.fake_job_0.get('user_id')
     self.fake_job_id = common.get_fake_job_id()
     self.fake_action_0 = common.get_fake_action_0()
     self.fake_backup_0 = common.get_fake_backup_metadata()
     self.fake_session_0 = common.get_fake_session_0()
     self.fake_session_id = common.get_fake_session_id()
Exemplo n.º 13
0
    def test_on_post_ok(self):
        new_version = random.randint(0, 99)
        self.mock_db.replace_job.return_value = new_version
        job = common.get_fake_job_0()
        self.mock_req.stream.read.return_value = json.dumps(job)
        expected_result = {'job_id': common.fake_job_0_job_id,
                           'version': new_version}

        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_job_0_job_id)
        self.assertEqual(self.mock_req.status, falcon.HTTP_201)
        self.assertEqual(self.mock_req.body, expected_result)
Exemplo n.º 14
0
 def test_create_inserts_correct_uuid_timecreated_status(self, mock_time,
                                                         mock_uuid):
     mock_time.time.return_value = 1433611337
     mock_uuid.uuid4.return_value = mock_uuid
     mock_uuid.hex = 'hotforteacher'
     job_doc = common.get_fake_job_0()
     job_doc['job_schedule']['status'] = 'stop'
     res_doc = utils.JobDoc.create(job_doc, 'dude')
     self.assertEqual(res_doc['job_schedule']['time_created'], 1433611337)
     self.assertEqual(res_doc['job_schedule']['time_started'], -1)
     self.assertEqual(res_doc['job_schedule']['time_ended'], -1)
     self.assertEqual(res_doc['job_schedule']['status'], 'stop')
     self.assertEqual(res_doc['user_id'], 'dude')
     self.assertEqual(res_doc['job_id'], 'hotforteacher')
Exemplo n.º 15
0
    def test_on_delete_removes_job_from_session_jobs(self):
        session = common.get_fake_session_0()
        updated_session = common.get_fake_session_1()
        job = common.get_fake_job_0()

        self.mock_db.get_session.return_value = session
        self.mock_db.get_job.return_value = job

        self.resource.on_delete(self.mock_req, self.mock_req,
                                session['session_id'], 'job_id_2')

        self.mock_db.replace_session.assert_called_with(
            user_id=session['user_id'],
            session_id=session['session_id'],
            doc=updated_session)
Exemplo n.º 16
0
    def test_on_delete_removes_job_from_session_jobs(self):
        session = common.get_fake_session_0()
        updated_session = common.get_fake_session_1()
        job = common.get_fake_job_0()

        self.mock_db.get_session.return_value = session
        self.mock_db.get_job.return_value = job

        self.resource.on_delete(self.mock_req, self.mock_req,
                                session['session_id'],
                                'job_id_2')

        self.mock_db.replace_session.assert_called_with(
            user_id=session['user_id'],
            session_id=session['session_id'],
            doc=updated_session)
Exemplo n.º 17
0
    def test_on_put_updates_job_with_session_info(self):
        session = common.get_fake_session_0()
        job = common.get_fake_job_0()

        self.mock_db.get_session.return_value = session
        self.mock_db.get_job.return_value = job

        job_update_doc = {
            'session_id': session['session_id'],
            'session_tag': session['session_tag'],
            'job_schedule': session['schedule']
        }

        self.resource.on_put(self.mock_req, self.mock_req,
                             session['session_id'], job['job_id'])
        self.mock_db.update_job.assert_called_with(user_id=session['user_id'],
                                                   job_id=job['job_id'],
                                                   patch_doc=job_update_doc)
Exemplo n.º 18
0
    def test_on_put_updates_job_with_session_info(self):
        session = common.get_fake_session_0()
        job = common.get_fake_job_0()

        self.mock_db.get_session.return_value = session
        self.mock_db.get_job.return_value = job

        job_update_doc = {
            'session_id': session['session_id'],
            'session_tag': session['session_tag'],
            'job_schedule': session['schedule']
        }

        self.resource.on_put(self.mock_req, self.mock_req,
                             session['session_id'],
                             job['job_id'])
        self.mock_db.update_job.assert_called_with(user_id=session['user_id'],
                                                   job_id=job['job_id'],
                                                   patch_doc=job_update_doc)
Exemplo n.º 19
0
    def test_on_delete_removes_session_info_from_job_and_stops_job(self):
        session = common.get_fake_session_0()
        job = common.get_fake_job_0()

        self.mock_db.get_session.return_value = session
        self.mock_db.get_job.return_value = job

        job_update_doc = {
            'session_id': '',
            'session_tag': 0,
            'job_schedule': {
                'event': 'stop'
            }
        }

        self.resource.on_delete(self.mock_req, self.mock_req,
                                session['session_id'], job['job_id'])

        self.mock_db.update_job.assert_called_with(user_id=session['user_id'],
                                                   job_id=job['job_id'],
                                                   patch_doc=job_update_doc)
Exemplo n.º 20
0
    def test_on_delete_removes_session_info_from_job_and_stops_job(self):
        session = common.get_fake_session_0()
        job = common.get_fake_job_0()

        self.mock_db.get_session.return_value = session
        self.mock_db.get_job.return_value = job

        job_update_doc = {
            'session_id': '',
            'session_tag': 0,
            'job_schedule': {
                'event': 'stop'
            }
        }

        self.resource.on_delete(self.mock_req, self.mock_req,
                                session['session_id'],
                                job['job_id'])

        self.mock_db.update_job.assert_called_with(user_id=session['user_id'],
                                                   job_id=job['job_id'],
                                                   patch_doc=job_update_doc)
Exemplo n.º 21
0
    def test_on_put_adds_job_to_session_jobs(self):
        session = common.get_fake_session_0()
        job = common.get_fake_job_0()
        job_info = {job['job_id']: {'client_id': job['client_id'],
                                    'status': job['job_schedule']['status'],
                                    'result': job['job_schedule']['result'],
                                    'time_started': job['job_schedule'][
                                        'time_started'],
                                    'time_ended': job['job_schedule'][
                                        'time_ended']}}
        session_update_doc = {'jobs': job_info}

        self.mock_db.get_session.return_value = session
        self.mock_db.get_job.return_value = job

        self.resource.on_put(self.mock_req, self.mock_req,
                             session['session_id'],
                             job['job_id'])
        self.mock_db.update_session.assert_called_with(
            user_id=session['user_id'],
            session_id=session['session_id'],
            patch_doc=session_update_doc)
Exemplo n.º 22
0
    def test_on_put_adds_job_to_session_jobs(self):
        session = common.get_fake_session_0()
        job = common.get_fake_job_0()
        job_info = {job['job_id']: {'client_id': job['client_id'],
                                    'status': job['job_schedule']['status'],
                                    'result': job['job_schedule']['result'],
                                    'time_started': job['job_schedule'][
                                        'time_started'],
                                    'time_ended': job['job_schedule'][
                                        'time_ended']}}
        session_update_doc = {'jobs': job_info}

        self.mock_db.get_session.return_value = session
        self.mock_db.get_job.return_value = job

        self.resource.on_put(self.mock_req, self.mock_req,
                             session['session_id'],
                             job['job_id'])
        self.mock_db.update_session.assert_called_with(
            user_id=session['user_id'],
            session_id=session['session_id'],
            patch_doc=session_update_doc)
Exemplo n.º 23
0
 def test_validate_raises_BadDataFormat_when_doc_has_no_userid(self):
     job_doc = common.get_fake_job_0()
     job_doc.pop('job_id')
     self.assertRaises(exceptions.BadDataFormat, utils.JobDoc.validate,
                       job_doc)
Exemplo n.º 24
0
 def test_validate_ok_when_data_ok(self):
     job_doc = common.get_fake_job_0()
     self.assertIsNone(utils.JobDoc.validate(job_doc))
Exemplo n.º 25
0
 def test_validate_patch_raises_when_doc_has_invalid_state(self):
     job_doc = common.get_fake_job_0()
     job_doc['job_schedule']['status'] = 'value_no_allowed'
     self.assertRaises(exceptions.BadDataFormat,
                       utils.JobDoc.validate_patch, job_doc)
Exemplo n.º 26
0
 def test_createpatch_pops_jobid_and_userid(self):
     job_doc = common.get_fake_job_0()
     res_doc = utils.JobDoc.create_patch(job_doc)
     self.assertFalse('job_id' in res_doc)
     self.assertFalse('user_id' in res_doc)
Exemplo n.º 27
0
 def test_createpatch_raises_BadDataFormat_when_patch_has_invalid_event(
         self):
     job_doc = common.get_fake_job_0()
     job_doc['job_schedule']['event'] = 'value_no_allowed'
     self.assertRaises(exceptions.BadDataFormat, utils.JobDoc.create_patch,
                       job_doc)