Skip to content

Commit

Permalink
Adding mailgun tests. Fixes #181 (#356)
Browse files Browse the repository at this point in the history
Adding mailgun tests. Fixes #181
  • Loading branch information
Jon Wayne Parrott committed May 18, 2016
1 parent 6778f8c commit ec1a947
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions managed_vms/mailgun/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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 pytest
import requests
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,
'https://api.mailgun.net/v3/example.com/messages',
body='Test error',
status=500)

with pytest.raises(requests.exceptions.HTTPError):
app.post('/send/email', data={
'recipient': 'user@example.com',
'submit': 'Send simple email'})


@responses.activate
def test_send_simple(app):
responses.add(
responses.POST,
'https://api.mailgun.net/v3/example.com/messages',
body='')

response = app.post('/send/email', data={
'recipient': 'user@example.com',
'submit': 'Send simple email'})
assert response.status_code == 200
assert len(responses.calls) == 1


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

responses.add(
responses.POST,
'https://api.mailgun.net/v3/example.com/messages',
body='')

response = app.post('/send/email', data={
'recipient': 'user@example.com',
'submit': 'Send complex email'})
assert response.status_code == 200
assert len(responses.calls) == 1

0 comments on commit ec1a947

Please sign in to comment.