前提
今、pythonで作ったプログラムをGoogle App Engine上で動かそうとテストしています。
↓のGAEの公式チュートリアルを進めています。
https://cloud.google.com/appengine/docs/standard/python3/building-app/deploying-web-service
そこでダウンロードしたサンプルコードで分からないことがあり、質問しました。
発生している問題・エラーメッセージ
ダウンロードしたサンプルコードの中で↓を触っています。
python-docs-samples/appengine/standard/firebase/firenotes/py3/building-an-app/building-an-app-1
その中で↓のコードが含まれています。
app.yaml main.py main_test.py requirements.txt static templates
アドバイス頂きたいのは、” main_test.py ”というファイルの意味です。
チュートリアル上でも特に触れられていないと思います。
GAEのyamlファイルでも” main_test.py ”というのは特に参照はされていません。
しかし、公式チュートリアルでそんな無意味なファイルが入ったまま配布するとも思えません。
どなたかおわかりになる方、アドバイス頂けませんでしょうか。
参考に、各ファイルのコードを↓に貼ります。
該当のソースコード
app.yaml
yaml
1runtime: python37 2 3handlers: 4 # This configures Google App Engine to serve the files in the app's static 5 # directory. 6- url: /static 7 static_dir: static 8 9 # This handler routes all requests not caught above to your main app. It is 10 # required when static routes are defined, but can be omitted (along with 11 # the entire handlers section) when there are no static files defined. 12- url: /.* 13 script: auto
main.py
python3
1# Copyright 2018 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# [START gae_python37_render_template] 16import datetime 17 18from flask import Flask, render_template 19 20app = Flask(__name__) 21 22 23@app.route('/') 24def root(): 25 # For the sake of example, use static information to inflate the template. 26 # This will be replaced with real information in later steps. 27 dummy_times = [datetime.datetime(2018, 1, 1, 10, 0, 0), 28 datetime.datetime(2018, 1, 2, 10, 30, 0), 29 datetime.datetime(2018, 1, 3, 11, 0, 0), 30 ] 31 32 return render_template('index.html', times=dummy_times) 33 34 35if __name__ == '__main__': 36 # This is used when running locally only. When deploying to Google App 37 # Engine, a webserver process such as Gunicorn will serve the app. This 38 # can be configured by adding an `entrypoint` to app.yaml. 39 # Flask's development server will automatically serve static files in 40 # the "static" directory. See: 41 # http://flask.pocoo.org/docs/1.0/quickstart/#static-files. Once deployed, 42 # App Engine itself will serve those files as configured in app.yaml. 43 app.run(host='127.0.0.1', port=8080, debug=True) 44# [START gae_python37_render_template]
main_test.py
python3
1# Copyright 2015 Google Inc. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import main 16 17 18def test_index(): 19 main.app.testing = True 20 client = main.app.test_client() 21 22 r = client.get('/') 23 assert r.status_code == 200 24
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/01 04:35