コード例 #1
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
 def test_put_insufficient_key(self, missing_key, scheduled_jobs, get_json_happy_dict):
     # post a new job
     input_string = simplejson.dumps(get_json_happy_dict)
     et_scanner_queue = FakeSQS()
     self.post_job(scheduled_jobs, et_scanner_queue, input_string)
     # put job with missing args
     test_dict = dict(get_json_happy_dict)
     test_dict.pop(missing_key)
     input_string = simplejson.dumps(test_dict)
     with pytest.raises(PrimaryKeyError):
         put_job(None, None, input_string)
コード例 #2
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
 def test_put_action_wrong_type(self, scheduled_jobs, get_json_happy_dict, action):
     # post a new job
     input_string = simplejson.dumps(get_json_happy_dict)
     et_scanner_queue = FakeSQS()
     self.post_job(scheduled_jobs, et_scanner_queue, input_string)
     # update the action of the job
     required_args = list(ACTION_TO_REQUIRED_ARGS['put'])
     new_happy_dict = dict(zip(required_args, [get_json_happy_dict[k] for k in required_args]))
     new_happy_dict[action] = '1'    # fill with wrong type. It should be boolean here.
     input_string = simplejson.dumps(new_happy_dict)
     with pytest.raises(ValueError):
         put_job(scheduled_jobs, et_scanner_queue, input_string)
コード例 #3
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
 def test_put_delete_job_fail(self, scheduled_jobs, get_json_happy_dict):
     # post a new job
     job = get_json_happy_dict
     input_string = simplejson.dumps(job)
     et_scanner_queue = FakeSQS()
     self.post_job(scheduled_jobs, et_scanner_queue, input_string)
     required_args = list(ACTION_TO_REQUIRED_ARGS['put'])
     new_happy_dict = dict(zip(required_args, [get_json_happy_dict[k] for k in required_args]))
     new_happy_dict['delete_requested'] = True
     input_string = simplejson.dumps(new_happy_dict)
     with pytest.raises(ValueError):
         put_job(scheduled_jobs, et_scanner_queue, input_string)
コード例 #4
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
 def test_put_acceptable_job(self, scheduled_jobs, get_json_happy_dict):
     # post a new job
     input_string = simplejson.dumps(get_json_happy_dict)
     et_scanner_queue = FakeSQS()
     result = self.post_job(scheduled_jobs, et_scanner_queue, input_string)
     # update the both cancel_requested and pause_requested of the job
     required_args = list(ACTION_TO_REQUIRED_ARGS['put'])
     new_happy_dict = dict(zip(required_args, [get_json_happy_dict[k] for k in required_args]))
     new_happy_dict['cancel_requested'] = True
     new_happy_dict['pause_requested'] = True
     input_string = simplejson.dumps(new_happy_dict)
     result = put_job(scheduled_jobs, et_scanner_queue, input_string)
     assert 'put_accepted' in result
     assert result['put_accepted'] is True
     assert et_scanner_queue._published_msg == {'message': 'job put request'}
コード例 #5
0
def jobs_update_job(request):
    """
    jobs_update_job_by_job_id handles requests from the jobs endpoint.

    **PUT /v1/jobs/job/**

    Example: ``v1/jobs/job/``

    **Query Parameters:**

    * **request.body** -- the json string of job details

    *Example request.body* ::

        "{ 'log_name': 'ad_click',
           'log_schema_version': 'initial',
           'start_date': '2014-04-01',
           'end_date': '',
           'redshift_id': 'rs1',
           'cancel_requested': True,
        }"

    ============ ===========
    Status Code  Description
    ============ ===========
    **200**      Success
    **400**      bad hash_key: redshift_id, log_name,
                 log_schema_version and start_date must all be present
    **404**      invalid job parameters
    **500**      unknown exception
    ============ ===========

    * **Encoding type:** *application/json*
    """
    try:
        return 200, put_job(TableConnection.get_connection('ScheduledJobs'),
                            get_scanner_queue('et'), request.body)
    except PrimaryKeyError as e:
        return 400, {'error': 'bad hash_key'}
    except JSONDecodeError as e:
        return 400, {'error': 'json decode error'}
    except ValueError as e:
        return 404, {'error': repr(e)}
    except Exception as unknown_exception:
        return 500, {'error': repr(unknown_exception)}
コード例 #6
0
ファイル: jobs.py プロジェクト: hyuni/mycroft
def jobs_update_job(request):
    """
    jobs_update_job_by_job_id handles requests from the jobs endpoint.

    **PUT /v1/jobs/job/**

    Example: ``v1/jobs/job/``

    **Query Parameters:**

    * **request.body** -- the json string of job details

    *Example request.body* ::

        "{ 'log_name': 'ad_click',
           'log_schema_version': 'initial',
           'start_date': '2014-04-01',
           'end_date': '',
           'redshift_id': 'rs1',
           'cancel_requested': True,
        }"

    ============ ===========
    Status Code  Description
    ============ ===========
    **200**      Success
    **400**      bad hash_key: redshift_id, log_name,
                 log_schema_version and start_date must all be present
    **404**      invalid job parameters
    **500**      unknown exception
    ============ ===========

    * **Encoding type:** *application/json*
    """
    try:
        return 200, put_job(TableConnection.get_connection("ScheduledJobs"), get_scanner_queue("et"), request.body)
    except PrimaryKeyError as e:
        return 400, {"error": "bad hash_key"}
    except JSONDecodeError as e:
        return 400, {"error": "json decode error"}
    except ValueError as e:
        return 404, {"error": repr(e)}
    except Exception as unknown_exception:
        return 500, {"error": repr(unknown_exception)}
コード例 #7
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
    def test_put_delete_job_ok(self, scheduled_jobs, get_json_happy_dict, job_status):
        # post a new job
        job = get_json_happy_dict
        input_string = simplejson.dumps(job)
        et_scanner_queue = FakeSQS()
        result = self.post_job(scheduled_jobs, et_scanner_queue, input_string)
        required_args = list(ACTION_TO_REQUIRED_ARGS['put'])
        new_happy_dict = dict(zip(required_args, [get_json_happy_dict[k] for k in required_args]))
        new_happy_dict['et_status'] = job_status
        new_happy_dict['delete_requested'] = True

        # update job status
        hash_key = _create_hash_key(new_happy_dict)
        job = scheduled_jobs.get(hash_key=hash_key)
        # make state machine happy
        job.update(et_status=JOBS_ETL_STATUS_SCHEDULED)
        job.update(et_status=JOBS_ETL_STATUS_RUNNING)
        job.update(et_status=job_status)

        input_string = simplejson.dumps(new_happy_dict)
        result = put_job(scheduled_jobs, et_scanner_queue, input_string)
        assert 'put_accepted' in result
        assert result['put_accepted'] is True
        assert et_scanner_queue._published_msg == {'message': 'job put request'}
コード例 #8
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
 def test_put_no_kwargs(self):
     with pytest.raises(JSONDecodeError):
         put_job(None, None, "")
コード例 #9
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
 def test_put_nonexisting_job(self, scheduled_jobs, get_json_happy_dict):
     input_string = simplejson.dumps(get_json_happy_dict)
     et_scanner_queue = FakeSQS()
     with pytest.raises(KeyError):
         put_job(scheduled_jobs, et_scanner_queue, input_string)