Commit 58e77813 authored by Emanuele Rocca's avatar Emanuele Rocca

New upstream version 0.5.0

parent 6a1e2815
Metadata-Version: 1.1
Name: pytest-localserver
Version: 0.3.7
Version: 0.5.0
Summary: py.test plugin to test server connections locally.
Home-page: http://bitbucket.org/pytest-dev/pytest-localserver/
Author: Sebastian Rahlf
Author-email: basti AT redtoad DOT de
Author-email: basti@redtoad.de
License: MIT License
Download-URL: http://bitbucket.org/pytest-dev/pytest-localserver/downloads/
Description: ==================
......@@ -104,6 +104,13 @@ Description: ==================
which will display them as parsable text.
If you need to inspect the requests sent to the server, a list of all
received requests can be found in property
* ``requests``
which is a list of ``werkzeug.wrappers.Request`` objects.
``httpsserver``
is the same as ``httpserver`` only with SSL encryption.
......@@ -222,4 +229,6 @@ Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Topic :: Software Development :: Testing
......@@ -95,6 +95,13 @@ poking around in the code itself.
which will display them as parsable text.
If you need to inspect the requests sent to the server, a list of all
received requests can be found in property
* ``requests``
which is a list of ``werkzeug.wrappers.Request`` objects.
``httpsserver``
is the same as ``httpserver`` only with SSL encryption.
......
VERSION = '0.3.7'
VERSION = '0.5.0'
......@@ -66,12 +66,14 @@ class ContentServer(WSGIServer):
self.headers = {}
self.show_post_vars = False
self.compress = None
self.requests = []
def __call__(self, environ, start_response):
"""
This is the WSGI application.
"""
request = Request(environ)
self.requests.append(request)
if (request.content_type == 'application/x-www-form-urlencoded'
and request.method == 'POST' and self.show_post_vars):
content = json.dumps(request.form)
......
......@@ -10,9 +10,12 @@
import asyncore
import email
import smtpd
import sys
import threading
PY35_OR_NEWER = sys.version_info[:2] >= (3, 5)
class Server (smtpd.SMTPServer, threading.Thread):
"""
......@@ -32,7 +35,12 @@ class Server (smtpd.SMTPServer, threading.Thread):
WAIT_BETWEEN_CHECKS = 0.001
def __init__(self, host='localhost', port=0):
smtpd.SMTPServer.__init__(self, (host, port), None)
# Workaround for deprecated signature in Python 3.6
if PY35_OR_NEWER:
smtpd.SMTPServer.__init__(self, (host, port), None, decode_data=True)
else:
smtpd.SMTPServer.__init__(self, (host, port), None)
if self._localaddr[1] == 0:
self.addr = self.socket.getsockname()
......@@ -48,9 +56,22 @@ class Server (smtpd.SMTPServer, threading.Thread):
Adds message to outbox.
"""
try:
self.outbox += [email.message_from_bytes(data)]
message = email.message_from_bytes(data)
except AttributeError:
self.outbox += [email.message_from_string(data)]
message = email.message_from_string(data)
# on the message, also set the envelope details
class Bunch:
def __init__(self, **kwds):
vars(self).update(kwds)
message.details = Bunch(
peer=peer,
mailfrom=mailfrom,
rcpttos=rcpttos,
**kwargs
)
self.outbox.append(message)
def run(self):
"""
......
[metadata]
description-file = README
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
......@@ -2,7 +2,7 @@ from setuptools import setup, Command
import sys
VERSION = '0.3.7'
VERSION = '0.5.0'
def read(fname):
......@@ -32,7 +32,7 @@ setup(
name='pytest-localserver',
version=VERSION,
author='Sebastian Rahlf',
author_email='basti AT redtoad DOT de',
author_email='basti@redtoad.de',
license='MIT License',
description='py.test plugin to test server connections locally.',
long_description=read('README'),
......@@ -46,7 +46,6 @@ setup(
cmdclass={'test': PyTest},
tests_require=[
'pytest>=2.0.0',
'six',
'requests'
],
entry_points={
......@@ -69,6 +68,8 @@ setup(
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Software Development :: Testing'
]
)
import gzip
import requests
import six
from pytest_localserver import http, plugin
from pytest_localserver import VERSION
# define test fixture here again in order to run tests without having to
......@@ -29,6 +26,13 @@ def test_some_content_retrieval(httpserver):
assert resp.status_code == 200
def test_request_is_stored(httpserver):
httpserver.serve_content('TEST!')
assert len(httpserver.requests) == 0
resp = requests.get(httpserver.url)
assert len(httpserver.requests) == 1
def test_GET_request(httpserver):
httpserver.serve_content('TEST!', headers={'Content-type': 'text/plain'})
resp = requests.get(httpserver.url, headers={'User-Agent': 'Test method'})
......
......@@ -65,6 +65,9 @@ def test_send_email(smtpserver):
assert msg['To'] == 'alice@example.com'
assert msg['From'] == 'webmaster@example.com'
assert msg['Subject'] == 'Your e-mail is getting there'
assert msg.details.rcpttos == ['alice@example.com']
assert msg.details.peer
assert msg.details.mailfrom
# send another e-mail
send_plain_email(
......
[tox]
envlist = py26,py27,py33,py34,py35,py36
envlist = py26,py27,py33,py34,py35,py36,py37
recreate = True
[tox:hudson]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment