From 26b0511b4f00f57557ce64506df7efe6f828ecc4 Mon Sep 17 00:00:00 2001 From: ace-n Date: Tue, 6 Dec 2022 16:55:24 -0800 Subject: [PATCH 1/2] feat(functions/tips-gcp-apis): add tests --- functions/tips-gcp-apis/main_test.py | 41 +++++++++++++++++++ functions/tips-gcp-apis/requirements-test.txt | 2 + 2 files changed, 43 insertions(+) create mode 100644 functions/tips-gcp-apis/main_test.py create mode 100644 functions/tips-gcp-apis/requirements-test.txt diff --git a/functions/tips-gcp-apis/main_test.py b/functions/tips-gcp-apis/main_test.py new file mode 100644 index 00000000000..3c621b112e3 --- /dev/null +++ b/functions/tips-gcp-apis/main_test.py @@ -0,0 +1,41 @@ +# Copyright 2022 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 json +import os + +import flask + +import main + +import pytest + + +# Create a fake "app" for generating test request contexts. +@pytest.fixture(scope="module") +def app(): + return flask.Flask(__name__) + + +def test_publishes_message(app): + data = json.dumps({ + 'topic': os.getenv('FUNCTIONS_TOPIC') + }) + + with app.test_request_context( + data=data, + content_type='application/json' + ): + response = main.gcp_api_call(flask.request) + assert response == '1 message published' diff --git a/functions/tips-gcp-apis/requirements-test.txt b/functions/tips-gcp-apis/requirements-test.txt new file mode 100644 index 00000000000..e80042419ca --- /dev/null +++ b/functions/tips-gcp-apis/requirements-test.txt @@ -0,0 +1,2 @@ +flask==2.1.0 +pytest==7.0.1 From 8785945f08ce3631d32a3344c0d313d8b7d12aa3 Mon Sep 17 00:00:00 2001 From: ace-n Date: Tue, 6 Dec 2022 17:02:03 -0800 Subject: [PATCH 2/2] Lint --- functions/tips-gcp-apis/main_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions/tips-gcp-apis/main_test.py b/functions/tips-gcp-apis/main_test.py index 3c621b112e3..9d032cfa743 100644 --- a/functions/tips-gcp-apis/main_test.py +++ b/functions/tips-gcp-apis/main_test.py @@ -16,11 +16,10 @@ import os import flask +import pytest import main -import pytest - # Create a fake "app" for generating test request contexts. @pytest.fixture(scope="module")