質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Google App Engine

Google App Engineは、Googleの管理するデータセンター上でウェブアプリケーションの開発が可能なクラウドコンピュータ技術です。Java、Python、Go用にSDKが用意されています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

Q&A

解決済

1回答

1367閲覧

GAE、pythonサンプルソースの中に含まれるmain_test.pyというファイルについて

big_naminami

総合スコア15

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Google App Engine

Google App Engineは、Googleの管理するデータセンター上でウェブアプリケーションの開発が可能なクラウドコンピュータ技術です。Java、Python、Go用にSDKが用意されています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

0グッド

0クリップ

投稿2019/05/01 03:21

前提

今、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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

main_test.pyは動作テスト目的以外には使われることはないそうです。
main_test.pyについて言及しているのはここしかありませんでしたが、おそらくすべてのmain_test.pyについて同じことが言えると思います。

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/3d1f403bfad96ffc78a31183239bc8d2bf6572d8/appengine/standard_python37/pubsub/README.md

Note: Not all the files in the current directory are needed to run your code on App Engine. Specifically, main_test.py and the data directory, which contains a mocked private key file and a mocked public certs file, are for testing purposes only. They SHOULD NOT be included in when deploying your app. When your app is up and running, Cloud Pub/Sub creates tokens using a private key, then the Google Auth Python library takes care of verifying and decoding the token using Google's public certs, to confirm that the push requests indeed come from Cloud Pub/Sub.

投稿2019/05/01 04:15

編集2019/05/01 04:16
mistn

総合スコア1191

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

big_naminami

2019/05/01 04:35

ありがとうございます!疑問が解消されました! 本当にテスト目的だけだったのですね! 勉強になりました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問