Skip to content

Commit

Permalink
Adding mailgun tests. Fixes #181
Browse files Browse the repository at this point in the history
Change-Id: I3a2e34668fca8084e0eafc7502bc07fe3fabefe4
  • Loading branch information
Jon Wayne Parrott committed May 18, 2016
1 parent e56eb4d commit f0b919c
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions managed_vms/mailgun/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2015 Google Inc. All rights reserved.
#
# 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 os
import re

import pytest
import responses


@pytest.fixture
def app(monkeypatch):
monkeypatch.setenv('MAILGUN_DOMAIN_NAME', 'example.com')
monkeypatch.setenv('MAILGUN_API_KEY', 'apikey')

import main

main.app.testing = True
return main.app.test_client()


def test_index(app):
r = app.get('/')
assert r.status_code == 200


@responses.activate
def test_send_error(app):
responses.add(
responses.POST,
re.compile(r'.*'),
body='Test error',
status=500)

with pytest.raises(Exception):
app.post('/send/email', data={
'recipient': '[email protected]',
'submit': 'Send simple email'})


@responses.activate
def test_send_simple(app):
responses.add(
responses.POST,
re.compile(r'.*'),
body='')

response = app.post('/send/email', data={
'recipient': '[email protected]',
'submit': 'Send simple email'})
assert response.status_code == 200


@responses.activate
def test_send_complex(app, monkeypatch):
import main
monkeypatch.chdir(os.path.dirname(main.__file__))

responses.add(
responses.POST,
re.compile(r'.*'),
body='')

response = app.post('/send/email', data={
'recipient': '[email protected]',
'submit': 'Send complex email'})
assert response.status_code == 200

0 comments on commit f0b919c

Please sign in to comment.