|
| 1 | +# Copyright 2016 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 | + |
| 15 | +import main |
| 16 | + |
| 17 | +import mock |
| 18 | +import pytest |
| 19 | + |
| 20 | + |
| 21 | +@pytest.fixture |
| 22 | +def app(monkeypatch): |
| 23 | + monkeypatch.setenv('SENDGRID_API_KEY', 'apikey') |
| 24 | + monkeypatch.setenv('SENDGRID_SENDER', 'sender@example.com') |
| 25 | + |
| 26 | + import main |
| 27 | + |
| 28 | + main.app.testing = True |
| 29 | + return main.app.test_client() |
| 30 | + |
| 31 | + |
| 32 | +def test_get(app): |
| 33 | + r = app.get('/') |
| 34 | + assert r.status_code == 200 |
| 35 | + |
| 36 | + |
| 37 | +@mock.patch.object( |
| 38 | + main.sendgrid.SendGridClient, 'send', return_value=(200, "OK")) |
| 39 | +def test_post(send_mock, app): |
| 40 | + r = app.post('/send/email', data={ |
| 41 | + 'to': 'user@example.com' |
| 42 | + }) |
| 43 | + assert r.status_code == 200 |
| 44 | + assert send_mock.called |
0 commit comments