From 315fa4295a208262136df68a3e891c297a21313c Mon Sep 17 00:00:00 2001 From: KaiquanMah <7814298+KaiquanMah@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:48:49 +0800 Subject: [PATCH] Add files via upload --- .../appengine/flexible/dec2024/app.yaml | 31 ++++++++++++++ .../appengine/flexible/dec2024/main.py | 36 ++++++++++++++++ .../appengine/flexible/dec2024/main_test.py | 24 +++++++++++ .../flexible/dec2024/noxfile_config.py | 42 +++++++++++++++++++ .../flexible/dec2024/requirements-test.txt | 1 + .../flexible/dec2024/requirements.txt | 5 +++ 6 files changed, 139 insertions(+) create mode 100644 csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/app.yaml create mode 100644 csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/main.py create mode 100644 csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/main_test.py create mode 100644 csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/noxfile_config.py create mode 100644 csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/requirements-test.txt create mode 100644 csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/requirements.txt diff --git a/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/app.yaml b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/app.yaml new file mode 100644 index 00000000..ac38af83 --- /dev/null +++ b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/app.yaml @@ -0,0 +1,31 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +runtime: python +env: flex +entrypoint: gunicorn -b :$PORT main:app + +runtime_config: + operating_system: ubuntu22 + +# This sample incurs costs to run on the App Engine flexible environment. +# The settings below are to reduce costs during testing and are not appropriate +# for production use. For more information, see: +# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml +manual_scaling: + instances: 1 +resources: + cpu: 1 + memory_gb: 0.5 + disk_size_gb: 10 diff --git a/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/main.py b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/main.py new file mode 100644 index 00000000..9caf1f5d --- /dev/null +++ b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/main.py @@ -0,0 +1,36 @@ +# Copyright 2015 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gae_flex_quickstart] +from flask import Flask + + +app = Flask(__name__) + + +@app.route("/") +def hello() -> str: + """Return a friendly HTTP greeting. + + Returns: + A string with the words 'Hello World!'. + """ + return "Hello World!" + + +if __name__ == "__main__": + # This is used when running locally only. When deploying to Google App + # Engine, a webserver process such as Gunicorn will serve the app. + app.run(host="127.0.0.1", port=8080, debug=True) +# [END gae_flex_quickstart] diff --git a/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/main_test.py b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/main_test.py new file mode 100644 index 00000000..b74c52b0 --- /dev/null +++ b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/main_test.py @@ -0,0 +1,24 @@ +# Copyright 2015 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import main + + +def test_index() -> str: + main.app.testing = True + client = main.app.test_client() + + r = client.get("/") + assert r.status_code == 200 + assert "Hello World" in r.data.decode("utf-8") diff --git a/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/noxfile_config.py b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/noxfile_config.py new file mode 100644 index 00000000..ae3ed14d --- /dev/null +++ b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/noxfile_config.py @@ -0,0 +1,42 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be imported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + "ignored_versions": ["2.7", "3.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": True, + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + "envs": {}, +} diff --git a/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/requirements-test.txt b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/requirements-test.txt new file mode 100644 index 00000000..15d066af --- /dev/null +++ b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/requirements-test.txt @@ -0,0 +1 @@ +pytest==8.2.0 diff --git a/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/requirements.txt b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/requirements.txt new file mode 100644 index 00000000..68e81e27 --- /dev/null +++ b/csit-exercise/python-docs-samples-main/appengine/flexible/dec2024/requirements.txt @@ -0,0 +1,5 @@ +Flask==3.0.3; python_version > '3.6' +Flask==2.3.3; python_version < '3.7' +Werkzeug==3.0.3; python_version > '3.6' +Werkzeug==2.3.7; python_version < '3.7' +gunicorn==22.0.0 \ No newline at end of file