diff --git a/scheduler/snippets/create_job.py b/scheduler/snippets/create_job.py index 646a89780e73..aeea5750b277 100644 --- a/scheduler/snippets/create_job.py +++ b/scheduler/snippets/create_job.py @@ -31,27 +31,20 @@ def create_scheduler_job(project_id, location_id, service_id): # Construct the request body. job = { - 'app_engine_http_target': { - 'app_engine_routing': { - 'service': service_id - }, - 'relative_uri': '/log_payload', - 'http_method': 1, - 'body': 'Hello World'.encode() + "app_engine_http_target": { + "app_engine_routing": {"service": service_id}, + "relative_uri": "/log_payload", + "http_method": 1, + "body": "Hello World".encode(), }, - 'schedule': '* * * * *', - 'time_zone': 'America/Los_Angeles' + "schedule": "* * * * *", + "time_zone": "America/Los_Angeles", } # Use the client to send the job creation request. - response = client.create_job( - request={ - "parent": parent, - "job": job - } - ) + response = client.create_job(request={"parent": parent, "job": job}) - print('Created job: {}'.format(response.name)) + print("Created job: {}".format(response.name)) # [END cloud_scheduler_create_job] return response diff --git a/scheduler/snippets/create_job_test.py b/scheduler/snippets/create_job_test.py index e6b8a0eb719b..da61f0ef03ac 100644 --- a/scheduler/snippets/create_job_test.py +++ b/scheduler/snippets/create_job_test.py @@ -16,18 +16,19 @@ import create_job -TEST_PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT') -TEST_LOCATION = os.getenv('LOCATION_ID', 'us-central1') +TEST_PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") +TEST_LOCATION = os.getenv("LOCATION_ID", "us-central1") def test_create_job(capsys): create_result = create_job.create_scheduler_job( - TEST_PROJECT_ID, TEST_LOCATION, 'my-service') + TEST_PROJECT_ID, TEST_LOCATION, "my-service" + ) out, _ = capsys.readouterr() - assert 'Created job:' in out + assert "Created job:" in out - job_name = create_result.name.split('/')[-1] + job_name = create_result.name.split("/")[-1] create_job.delete_scheduler_job(TEST_PROJECT_ID, TEST_LOCATION, job_name) out, _ = capsys.readouterr() - assert 'Job deleted.' in out + assert "Job deleted." in out diff --git a/scheduler/snippets/main.py b/scheduler/snippets/main.py index 9d4d97537d27..4dad6afe73af 100644 --- a/scheduler/snippets/main.py +++ b/scheduler/snippets/main.py @@ -21,22 +21,24 @@ # Define relative URI for job endpoint -@app.route('/log_payload', methods=['POST']) +@app.route("/log_payload", methods=["POST"]) def example_task_handler(): """Log the job payload.""" - payload = request.get_data(as_text=True) or '(empty payload)' - print('Received job with payload: {}'.format(payload)) - return 'Printed job payload: {}'.format(payload) + payload = request.get_data(as_text=True) or "(empty payload)" + print("Received job with payload: {}".format(payload)) + return "Printed job payload: {}".format(payload) + + # [END cloud_scheduler_app] -@app.route('/') +@app.route("/") def hello(): """Basic index to verify app is serving.""" - return 'Hello World!' + return "Hello World!" -if __name__ == '__main__': +if __name__ == "__main__": # This is used when running locally. Gunicorn is used to run the # application on Google App Engine. See entrypoint in app.yaml. - app.run(host='127.0.0.1', port=8080, debug=True) + app.run(host="127.0.0.1", port=8080, debug=True) diff --git a/scheduler/snippets/main_test.py b/scheduler/snippets/main_test.py index 3d6745a5605c..75371c4b3c97 100644 --- a/scheduler/snippets/main_test.py +++ b/scheduler/snippets/main_test.py @@ -18,19 +18,20 @@ @pytest.fixture def app(): import main + main.app.testing = True return main.app.test_client() def test_index(app): - r = app.get('/') + r = app.get("/") assert r.status_code == 200 def test_log_payload(capsys, app): - payload = 'test_payload' + payload = "test_payload" - r = app.post('/log_payload', data=payload) + r = app.post("/log_payload", data=payload) assert r.status_code == 200 out, _ = capsys.readouterr() @@ -38,8 +39,8 @@ def test_log_payload(capsys, app): def test_empty_payload(capsys, app): - r = app.post('/log_payload') + r = app.post("/log_payload") assert r.status_code == 200 out, _ = capsys.readouterr() - assert 'empty payload' in out + assert "empty payload" in out