Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ec1a947

Browse filesBrowse files
author
Jon Wayne Parrott
committed
Adding mailgun tests. Fixes GoogleCloudPlatform#181 (GoogleCloudPlatform#356)
Adding mailgun tests. Fixes GoogleCloudPlatform#181
1 parent 6778f8c commit ec1a947
Copy full SHA for ec1a947

File tree

Expand file treeCollapse file tree

1 file changed

+80
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+80
-0
lines changed

‎managed_vms/mailgun/main_test.py

Copy file name to clipboard
+80Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
15+
import os
16+
17+
import pytest
18+
import requests
19+
import responses
20+
21+
22+
@pytest.fixture
23+
def app(monkeypatch):
24+
monkeypatch.setenv('MAILGUN_DOMAIN_NAME', 'example.com')
25+
monkeypatch.setenv('MAILGUN_API_KEY', 'apikey')
26+
27+
import main
28+
29+
main.app.testing = True
30+
return main.app.test_client()
31+
32+
33+
def test_index(app):
34+
r = app.get('/')
35+
assert r.status_code == 200
36+
37+
38+
@responses.activate
39+
def test_send_error(app):
40+
responses.add(
41+
responses.POST,
42+
'https://api.mailgun.net/v3/example.com/messages',
43+
body='Test error',
44+
status=500)
45+
46+
with pytest.raises(requests.exceptions.HTTPError):
47+
app.post('/send/email', data={
48+
'recipient': 'user@example.com',
49+
'submit': 'Send simple email'})
50+
51+
52+
@responses.activate
53+
def test_send_simple(app):
54+
responses.add(
55+
responses.POST,
56+
'https://api.mailgun.net/v3/example.com/messages',
57+
body='')
58+
59+
response = app.post('/send/email', data={
60+
'recipient': 'user@example.com',
61+
'submit': 'Send simple email'})
62+
assert response.status_code == 200
63+
assert len(responses.calls) == 1
64+
65+
66+
@responses.activate
67+
def test_send_complex(app, monkeypatch):
68+
import main
69+
monkeypatch.chdir(os.path.dirname(main.__file__))
70+
71+
responses.add(
72+
responses.POST,
73+
'https://api.mailgun.net/v3/example.com/messages',
74+
body='')
75+
76+
response = app.post('/send/email', data={
77+
'recipient': 'user@example.com',
78+
'submit': 'Send complex email'})
79+
assert response.status_code == 200
80+
assert len(responses.calls) == 1

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.