File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <img src =" https://avatars2.githubusercontent.com/u/2810941?v=3&s=96 " alt =" Google Cloud Platform logo " title =" Google Cloud Platform " align =" right " height =" 96 " width =" 96 " />
2+
3+ # Google Cloud Functions - Using Environment Variables sample
4+
5+ See:
6+ * [ Cloud Functions Using Environment Variables tutorial] [ tutorial ]
7+ * [ Cloud Functions Using Environment Variables sample source code] [ code ]
8+ [ tutorial ] : https://cloud.google.com/functions/docs/env-var#functions_env_var-python
9+ [ code ] : main.py
Original file line number Diff line number Diff line change 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+ import os
16+
17+
18+ # [START functions_env_vars]
19+ def env_vars (request ):
20+ return os .environ .get ('FOO' , 'Specified environment variable is not set.' )
21+ # [END functions_env_vars]
Original file line number Diff line number Diff line change 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+ import os
16+
17+ import flask
18+ import pytest
19+
20+ import main
21+
22+
23+ # Create a fake "app" for generating test request contexts.
24+ @pytest .fixture (scope = "module" )
25+ def app ():
26+ return flask .Flask (__name__ )
27+
28+
29+ def test_env_vars (app ):
30+ with app .test_request_context ():
31+ os .environ ['FOO' ] = 'bar'
32+ res = main .env_vars (flask .request )
33+ assert res == 'bar'
You can’t perform that action at this time.
0 commit comments