Skip to content

Commit

Permalink
chore(python): run blacken session for all directories with a noxfile (
Browse files Browse the repository at this point in the history
…#162)

Source-Link: googleapis/synthtool@bc0de6e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:39ad8c0570e4f5d2d3124a509de4fe975e799e2b97e0f58aed88f8880d5a8b60

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Nov 11, 2021
1 parent 24182ae commit ce6881d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-scheduler/.github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
digest: sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60
digest: sha256:39ad8c0570e4f5d2d3124a509de4fe975e799e2b97e0f58aed88f8880d5a8b60
25 changes: 9 additions & 16 deletions packages/google-cloud-scheduler/samples/snippets/create_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 10 additions & 8 deletions packages/google-cloud-scheduler/samples/snippets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 6 additions & 5 deletions packages/google-cloud-scheduler/samples/snippets/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@
@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()
assert payload in out


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

0 comments on commit ce6881d

Please sign in to comment.