|
| 1 | +# Copyright 2023 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 unittest |
| 16 | +import unittest.mock |
| 17 | + |
| 18 | +import main |
| 19 | + |
| 20 | + |
| 21 | +class TestHello(unittest.TestCase): |
| 22 | + def test_hello_world(self): |
| 23 | + request = unittest.mock.Mock() |
| 24 | + |
| 25 | + response = main.hello_world(request) |
| 26 | + assert response.status_code == 200 |
| 27 | + assert response.get_data(as_text=True) == "Hello World! 👋" |
| 28 | + |
| 29 | + def test_hello_name_no_name(self): |
| 30 | + request = unittest.mock.Mock(args={}) |
| 31 | + |
| 32 | + response = main.hello_name(request) |
| 33 | + assert response.status_code == 200 |
| 34 | + assert response.get_data(as_text=True) == "Hello World! 🚀" |
| 35 | + |
| 36 | + def test_hello_name_with_name(self): |
| 37 | + name = "FirstName LastName" |
| 38 | + request = unittest.mock.Mock(args={"name": name}) |
| 39 | + |
| 40 | + response = main.hello_name(request) |
| 41 | + assert response.status_code == 200 |
| 42 | + assert response.get_data(as_text=True) == f"Hello {name}! 🚀" |
0 commit comments