[Python-modules-commits] [pytest-localserver] 01/05: Imported Upstream version 0.3.4

Daniel Stender danstender-guest at moszumanska.debian.org
Sat Jul 18 16:49:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

danstender-guest pushed a commit to branch master
in repository pytest-localserver.

commit a735e4ef0b6f7ddd7104ab8ae58c9de2ae485216
Author: Daniel Stender <debian at danielstender.com>
Date:   Sat Jul 18 18:22:41 2015 +0200

    Imported Upstream version 0.3.4
---
 LICENSE                                          |  19 ++
 MANIFEST.in                                      |   7 +
 PKG-INFO                                         | 222 +++++++++++++++++++++++
 README                                           | 200 ++++++++++++++++++++
 pytest_localserver.egg-info/PKG-INFO             | 222 +++++++++++++++++++++++
 pytest_localserver.egg-info/SOURCES.txt          |  23 +++
 pytest_localserver.egg-info/dependency_links.txt |   1 +
 pytest_localserver.egg-info/entry_points.txt     |   3 +
 pytest_localserver.egg-info/not-zip-safe         |   1 +
 pytest_localserver.egg-info/requires.txt         |   1 +
 pytest_localserver.egg-info/top_level.txt        |   1 +
 pytest_localserver/__init__.py                   |   1 +
 pytest_localserver/ca.crt                        |  36 ++++
 pytest_localserver/http.py                       | 131 +++++++++++++
 pytest_localserver/https.py                      | 133 ++++++++++++++
 pytest_localserver/plugin.py                     |  79 ++++++++
 pytest_localserver/server.pem                    |  81 +++++++++
 pytest_localserver/smtp.py                       |  98 ++++++++++
 setup.cfg                                        |   5 +
 setup.py                                         |  72 ++++++++
 tests/__init__.py                                |   0
 tests/test_http.py                               |  75 ++++++++
 tests/test_https.py                              |  46 +++++
 tests/test_smtp.py                               |  82 +++++++++
 tox.ini                                          |  17 ++
 25 files changed, 1556 insertions(+)

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d3023fe
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011, Sebastian Rahlf
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..b8f6546
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,7 @@
+include LICENSE
+include MANIFEST.in
+include README
+include pytest_localserver/server.*
+include pytest_localserver/ca.*
+recursive-include tests *.py
+include tox.ini
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..b87625a
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,222 @@
+Metadata-Version: 1.1
+Name: pytest-localserver
+Version: 0.3.4
+Summary: py.test plugin to test server connections locally.
+Home-page: http://bitbucket.org/basti/pytest-localserver/
+Author: Sebastian Rahlf
+Author-email: basti AT redtoad DOT de
+License: MIT License
+Download-URL: http://bitbucket.org/basti/pytest-localserver/downloads/
+Description: ==================
+        pytest-localserver
+        ==================
+        
+        pytest-localserver is a plugin for the `pytest`_ testing framework which enables
+        you to test server connections locally.
+        
+        Sometimes `monkeypatching`_ ``urllib2.urlopen()`` just does not cut it, for
+        instance if you work with ``urllib2.Request``, define your own openers/handlers
+        or work with ``httplib``. In these cases it may come in handy to have an HTTP
+        server running locally which behaves just like the real thing [1]_. Well, look
+        no further!
+        
+        Quickstart
+        ==========
+        
+        Let's say you have a function to scrape HTML which only required to be pointed
+        at a URL ::
+        
+            import requests
+            def scrape(url):
+                html = requests.get(url).text
+                # some parsing happens here
+                # ...
+                return result
+        
+        You want to test this function in its entirety without having to rely on a
+        remote server whose content you cannot control, neither do you want to waste
+        time setting up a complex mechanism to mock or patch the underlying Python
+        modules dealing with the actual HTTP request (of which there are more than one
+        BTW). So what do you do?
+        
+        You simply use pytest's `funcargs feature`_ and simulate an entire server
+        locally! ::
+        
+            def test_retrieve_some_content(httpserver):
+                httpserver.serve_content(open('cached-content.html').read())
+                assert scrape(httpserver.url) == 'Found it!'
+        
+        What happened here is that for the duration of your tests an HTTP server is
+        started on a random port on localhost which will serve the content you tell it
+        to and behaves just like the real thing.
+        
+        The added bonus is that you can test whether your code behaves gracefully if
+        there is a network problem::
+        
+            def test_content_retrieval_fails_graciously(httpserver):
+                httpserver.serve_content('File not found!', 404)
+                pytest.raises(ContentNotFoundException, scrape, httpserver.url)
+        
+        The same thing works for SMTP servers, too::
+        
+            def test_sending_some_message(smtpserver):
+                mailer = MyMailer(host=smtpserver.addr[0], port=smtpserver.addr[1])
+                mailer.send(to='bob at example.com', from_='alice at example.com',
+                    subject='MyMailer v1.0', body='Check out my mailer!')
+                assert len(smtpserver.outbox)==1
+        
+        Here an SMTP server is started which accepts e-mails being sent to it. The
+        nice feature here is that you can actually check if the message was received
+        and what was sent by looking into the smtpserver's ``outbox``.
+        
+        It is really that easy!
+        
+        Available funcargs
+        ==================
+        
+        Here is a short overview of the available funcargs. For more details I suggest
+        poking around in the code itself.
+        
+        ``httpserver``
+            provides a threaded HTTP server instance running on localhost. It has the
+            following attributes:
+        
+            * ``code`` - HTTP response code (int)
+            * ``content`` - content of next response (str)
+            * ``headers`` - response headers (dict)
+        
+            Once these attribute are set, all subsequent requests will be answered with
+            these values until they are changed or the server is stopped. A more 
+            convenient way to change these is ::
+        
+                httpserver.serve_content(content=None, code=200, headers=None) 
+        
+            The server address can be found in property
+        
+            * ``url``
+        
+            which is the string representation of tuple ``server_address`` (host as str,
+            port as int).
+        
+            If you want to check which form fields have been POSTed, Try ::
+        
+                httpserver.serve_content(..., show_post_vars=True)
+        
+            which will display them as parsable text.
+        
+        ``httpsserver``
+            is the same as ``httpserver`` only with SSL encryption.
+        
+        ``smtpserver``
+            provides a threaded instance of ``smtpd.SMTPServer`` runnning on localhost.
+            It has the following attributes:
+        
+            * ``addr`` - server address as tuple (host as str, port as int)
+            * ``outbox`` - list of ``email.message.Message`` instances received.
+        
+        Using your a WSGI application as test server
+        ============================================
+        
+        As of version 0.3 you can now use a `WSGI application`_ to run on the test
+        server ::
+        
+            from pytest_localserver.http import WSGIServer
+        
+            def simple_app(environ, start_response):
+                """Simplest possible WSGI application"""
+                status = '200 OK'
+                response_headers = [('Content-type', 'text/plain')]
+                start_response(status, response_headers)
+                return ['Hello world!\n']
+        
+            def pytest_funcarg__testserver(request):
+                """Defines the testserver funcarg"""
+                server = WSGIServer(application=simple_app)
+                server.start()
+                request.addfinalizer(server.stop)
+                return server
+        
+            def test_retrieve_some_content(testserver):
+                assert scrape(testserver.url) == 'Hello world!\n'
+        
+        Have a look at the following page for more information on WSGI:
+        http://wsgi.readthedocs.org/en/latest/learn.html
+        
+        Download and Installation
+        =========================
+        
+        You can install the plugin by running ::
+        
+            pip install pytest-localserver
+        
+        Alternatively, get the latest stable version from `PyPI`_ or the latest
+        `bleeding-edge archive`_ from bitbucket.org.
+        
+        License and Credits
+        ===================
+        
+        This plugin is released under the MIT license. You can find the full text of
+        the license in the LICENSE file.
+        
+        Copyright (C) 2010-2013 Sebastian Rahlf and others (see AUTHORS).
+        
+        Some parts of this package is based on ideas or code from other people:
+        
+        - I borrowed some implementation ideas for the httpserver from `linkchecker`_.
+        - The implementation for the SMTP server is based on the `Mailsink recipe`_ by 
+          Adam Feuer, Matt Branthwaite and Troy Frever.
+        - The HTTPS implementation is based on work by `Sebastien Martini`_.
+        
+        Thanks guys!
+        
+        Development and future plans
+        ============================
+        
+        Feel free to clone the repository and add your own changes. Pull requests are
+        always welcome!::
+        
+            hg clone https://bitbucket.org/basti/pytest-localserver
+        
+        If you find any bugs, please file a `report`_.
+        
+        Test can be run with tox. Note that you need virtualenv<1.8 to run tests for
+        Python 2.4.
+        
+        I already have a couple of ideas for future versions:
+        
+        * support for FTP, SSH (maybe base all on twisted?)
+        * making the SMTP outbox as convenient to use as ``django.core.mail.outbox``
+        * add your own here!
+        
+        ----
+        
+        .. [1] The idea for this project was born when I needed to check that `a piece
+               of software`_ behaved itself when receiving HTTP error codes 404 and 500.
+               Having unsuccessfully tried to mock a server, I stumbled across 
+               `linkchecker`_ which uses a the same idea to test its internals.
+        
+        .. _monkeypatching: http://pytest.org/latest/monkeypatch.html
+        .. _pytest: http://pytest.org/
+        .. _funcargs feature: http://pytest.org/latest/funcargs.html
+        .. _linkchecker: http://linkchecker.sourceforge.net/
+        .. _WSGI application: http://www.python.org/dev/peps/pep-0333/
+        .. _PyPI: http://pypi.python.org/pypi/pytest-localserver/
+        .. _bleeding-edge archive: https://bitbucket.org/basti/pytest-localserver/get/tip.tar.gz
+        .. _report: https://bitbucket.org/basti/pytest-localserver/issues/
+        .. _tox: http://testrun.org/tox/
+        .. _a piece of software: http://pypi.python.org/pypi/python-amazon-product-api/
+        .. _Mailsink recipe: http://code.activestate.com/recipes/440690/
+        .. _Sebastien Martini: http://code.activestate.com/recipes/442473/
+        
+Keywords: py.test pytest server localhost http smtp
+Platform: UNKNOWN
+Classifier: Operating System :: OS Independent
+Classifier: Development Status :: 4 - Beta
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Topic :: Software Development :: Testing
diff --git a/README b/README
new file mode 100644
index 0000000..f073e12
--- /dev/null
+++ b/README
@@ -0,0 +1,200 @@
+==================
+pytest-localserver
+==================
+
+pytest-localserver is a plugin for the `pytest`_ testing framework which enables
+you to test server connections locally.
+
+Sometimes `monkeypatching`_ ``urllib2.urlopen()`` just does not cut it, for
+instance if you work with ``urllib2.Request``, define your own openers/handlers
+or work with ``httplib``. In these cases it may come in handy to have an HTTP
+server running locally which behaves just like the real thing [1]_. Well, look
+no further!
+
+Quickstart
+==========
+
+Let's say you have a function to scrape HTML which only required to be pointed
+at a URL ::
+
+    import requests
+    def scrape(url):
+        html = requests.get(url).text
+        # some parsing happens here
+        # ...
+        return result
+
+You want to test this function in its entirety without having to rely on a
+remote server whose content you cannot control, neither do you want to waste
+time setting up a complex mechanism to mock or patch the underlying Python
+modules dealing with the actual HTTP request (of which there are more than one
+BTW). So what do you do?
+
+You simply use pytest's `funcargs feature`_ and simulate an entire server
+locally! ::
+
+    def test_retrieve_some_content(httpserver):
+        httpserver.serve_content(open('cached-content.html').read())
+        assert scrape(httpserver.url) == 'Found it!'
+
+What happened here is that for the duration of your tests an HTTP server is
+started on a random port on localhost which will serve the content you tell it
+to and behaves just like the real thing.
+
+The added bonus is that you can test whether your code behaves gracefully if
+there is a network problem::
+
+    def test_content_retrieval_fails_graciously(httpserver):
+        httpserver.serve_content('File not found!', 404)
+        pytest.raises(ContentNotFoundException, scrape, httpserver.url)
+
+The same thing works for SMTP servers, too::
+
+    def test_sending_some_message(smtpserver):
+        mailer = MyMailer(host=smtpserver.addr[0], port=smtpserver.addr[1])
+        mailer.send(to='bob at example.com', from_='alice at example.com',
+            subject='MyMailer v1.0', body='Check out my mailer!')
+        assert len(smtpserver.outbox)==1
+
+Here an SMTP server is started which accepts e-mails being sent to it. The
+nice feature here is that you can actually check if the message was received
+and what was sent by looking into the smtpserver's ``outbox``.
+
+It is really that easy!
+
+Available funcargs
+==================
+
+Here is a short overview of the available funcargs. For more details I suggest
+poking around in the code itself.
+
+``httpserver``
+    provides a threaded HTTP server instance running on localhost. It has the
+    following attributes:
+
+    * ``code`` - HTTP response code (int)
+    * ``content`` - content of next response (str)
+    * ``headers`` - response headers (dict)
+
+    Once these attribute are set, all subsequent requests will be answered with
+    these values until they are changed or the server is stopped. A more 
+    convenient way to change these is ::
+
+        httpserver.serve_content(content=None, code=200, headers=None) 
+
+    The server address can be found in property
+
+    * ``url``
+
+    which is the string representation of tuple ``server_address`` (host as str,
+    port as int).
+
+    If you want to check which form fields have been POSTed, Try ::
+
+        httpserver.serve_content(..., show_post_vars=True)
+
+    which will display them as parsable text.
+
+``httpsserver``
+    is the same as ``httpserver`` only with SSL encryption.
+
+``smtpserver``
+    provides a threaded instance of ``smtpd.SMTPServer`` runnning on localhost.
+    It has the following attributes:
+
+    * ``addr`` - server address as tuple (host as str, port as int)
+    * ``outbox`` - list of ``email.message.Message`` instances received.
+
+Using your a WSGI application as test server
+============================================
+
+As of version 0.3 you can now use a `WSGI application`_ to run on the test
+server ::
+
+    from pytest_localserver.http import WSGIServer
+
+    def simple_app(environ, start_response):
+        """Simplest possible WSGI application"""
+        status = '200 OK'
+        response_headers = [('Content-type', 'text/plain')]
+        start_response(status, response_headers)
+        return ['Hello world!\n']
+
+    def pytest_funcarg__testserver(request):
+        """Defines the testserver funcarg"""
+        server = WSGIServer(application=simple_app)
+        server.start()
+        request.addfinalizer(server.stop)
+        return server
+
+    def test_retrieve_some_content(testserver):
+        assert scrape(testserver.url) == 'Hello world!\n'
+
+Have a look at the following page for more information on WSGI:
+http://wsgi.readthedocs.org/en/latest/learn.html
+
+Download and Installation
+=========================
+
+You can install the plugin by running ::
+
+    pip install pytest-localserver
+
+Alternatively, get the latest stable version from `PyPI`_ or the latest
+`bleeding-edge archive`_ from bitbucket.org.
+
+License and Credits
+===================
+
+This plugin is released under the MIT license. You can find the full text of
+the license in the LICENSE file.
+
+Copyright (C) 2010-2013 Sebastian Rahlf and others (see AUTHORS).
+
+Some parts of this package is based on ideas or code from other people:
+
+- I borrowed some implementation ideas for the httpserver from `linkchecker`_.
+- The implementation for the SMTP server is based on the `Mailsink recipe`_ by 
+  Adam Feuer, Matt Branthwaite and Troy Frever.
+- The HTTPS implementation is based on work by `Sebastien Martini`_.
+
+Thanks guys!
+
+Development and future plans
+============================
+
+Feel free to clone the repository and add your own changes. Pull requests are
+always welcome!::
+
+    hg clone https://bitbucket.org/basti/pytest-localserver
+
+If you find any bugs, please file a `report`_.
+
+Test can be run with tox. Note that you need virtualenv<1.8 to run tests for
+Python 2.4.
+
+I already have a couple of ideas for future versions:
+
+* support for FTP, SSH (maybe base all on twisted?)
+* making the SMTP outbox as convenient to use as ``django.core.mail.outbox``
+* add your own here!
+
+----
+
+.. [1] The idea for this project was born when I needed to check that `a piece
+       of software`_ behaved itself when receiving HTTP error codes 404 and 500.
+       Having unsuccessfully tried to mock a server, I stumbled across 
+       `linkchecker`_ which uses a the same idea to test its internals.
+
+.. _monkeypatching: http://pytest.org/latest/monkeypatch.html
+.. _pytest: http://pytest.org/
+.. _funcargs feature: http://pytest.org/latest/funcargs.html
+.. _linkchecker: http://linkchecker.sourceforge.net/
+.. _WSGI application: http://www.python.org/dev/peps/pep-0333/
+.. _PyPI: http://pypi.python.org/pypi/pytest-localserver/
+.. _bleeding-edge archive: https://bitbucket.org/basti/pytest-localserver/get/tip.tar.gz
+.. _report: https://bitbucket.org/basti/pytest-localserver/issues/
+.. _tox: http://testrun.org/tox/
+.. _a piece of software: http://pypi.python.org/pypi/python-amazon-product-api/
+.. _Mailsink recipe: http://code.activestate.com/recipes/440690/
+.. _Sebastien Martini: http://code.activestate.com/recipes/442473/
diff --git a/pytest_localserver.egg-info/PKG-INFO b/pytest_localserver.egg-info/PKG-INFO
new file mode 100644
index 0000000..b87625a
--- /dev/null
+++ b/pytest_localserver.egg-info/PKG-INFO
@@ -0,0 +1,222 @@
+Metadata-Version: 1.1
+Name: pytest-localserver
+Version: 0.3.4
+Summary: py.test plugin to test server connections locally.
+Home-page: http://bitbucket.org/basti/pytest-localserver/
+Author: Sebastian Rahlf
+Author-email: basti AT redtoad DOT de
+License: MIT License
+Download-URL: http://bitbucket.org/basti/pytest-localserver/downloads/
+Description: ==================
+        pytest-localserver
+        ==================
+        
+        pytest-localserver is a plugin for the `pytest`_ testing framework which enables
+        you to test server connections locally.
+        
+        Sometimes `monkeypatching`_ ``urllib2.urlopen()`` just does not cut it, for
+        instance if you work with ``urllib2.Request``, define your own openers/handlers
+        or work with ``httplib``. In these cases it may come in handy to have an HTTP
+        server running locally which behaves just like the real thing [1]_. Well, look
+        no further!
+        
+        Quickstart
+        ==========
+        
+        Let's say you have a function to scrape HTML which only required to be pointed
+        at a URL ::
+        
+            import requests
+            def scrape(url):
+                html = requests.get(url).text
+                # some parsing happens here
+                # ...
+                return result
+        
+        You want to test this function in its entirety without having to rely on a
+        remote server whose content you cannot control, neither do you want to waste
+        time setting up a complex mechanism to mock or patch the underlying Python
+        modules dealing with the actual HTTP request (of which there are more than one
+        BTW). So what do you do?
+        
+        You simply use pytest's `funcargs feature`_ and simulate an entire server
+        locally! ::
+        
+            def test_retrieve_some_content(httpserver):
+                httpserver.serve_content(open('cached-content.html').read())
+                assert scrape(httpserver.url) == 'Found it!'
+        
+        What happened here is that for the duration of your tests an HTTP server is
+        started on a random port on localhost which will serve the content you tell it
+        to and behaves just like the real thing.
+        
+        The added bonus is that you can test whether your code behaves gracefully if
+        there is a network problem::
+        
+            def test_content_retrieval_fails_graciously(httpserver):
+                httpserver.serve_content('File not found!', 404)
+                pytest.raises(ContentNotFoundException, scrape, httpserver.url)
+        
+        The same thing works for SMTP servers, too::
+        
+            def test_sending_some_message(smtpserver):
+                mailer = MyMailer(host=smtpserver.addr[0], port=smtpserver.addr[1])
+                mailer.send(to='bob at example.com', from_='alice at example.com',
+                    subject='MyMailer v1.0', body='Check out my mailer!')
+                assert len(smtpserver.outbox)==1
+        
+        Here an SMTP server is started which accepts e-mails being sent to it. The
+        nice feature here is that you can actually check if the message was received
+        and what was sent by looking into the smtpserver's ``outbox``.
+        
+        It is really that easy!
+        
+        Available funcargs
+        ==================
+        
+        Here is a short overview of the available funcargs. For more details I suggest
+        poking around in the code itself.
+        
+        ``httpserver``
+            provides a threaded HTTP server instance running on localhost. It has the
+            following attributes:
+        
+            * ``code`` - HTTP response code (int)
+            * ``content`` - content of next response (str)
+            * ``headers`` - response headers (dict)
+        
+            Once these attribute are set, all subsequent requests will be answered with
+            these values until they are changed or the server is stopped. A more 
+            convenient way to change these is ::
+        
+                httpserver.serve_content(content=None, code=200, headers=None) 
+        
+            The server address can be found in property
+        
+            * ``url``
+        
+            which is the string representation of tuple ``server_address`` (host as str,
+            port as int).
+        
+            If you want to check which form fields have been POSTed, Try ::
+        
+                httpserver.serve_content(..., show_post_vars=True)
+        
+            which will display them as parsable text.
+        
+        ``httpsserver``
+            is the same as ``httpserver`` only with SSL encryption.
+        
+        ``smtpserver``
+            provides a threaded instance of ``smtpd.SMTPServer`` runnning on localhost.
+            It has the following attributes:
+        
+            * ``addr`` - server address as tuple (host as str, port as int)
+            * ``outbox`` - list of ``email.message.Message`` instances received.
+        
+        Using your a WSGI application as test server
+        ============================================
+        
+        As of version 0.3 you can now use a `WSGI application`_ to run on the test
+        server ::
+        
+            from pytest_localserver.http import WSGIServer
+        
+            def simple_app(environ, start_response):
+                """Simplest possible WSGI application"""
+                status = '200 OK'
+                response_headers = [('Content-type', 'text/plain')]
+                start_response(status, response_headers)
+                return ['Hello world!\n']
+        
+            def pytest_funcarg__testserver(request):
+                """Defines the testserver funcarg"""
+                server = WSGIServer(application=simple_app)
+                server.start()
+                request.addfinalizer(server.stop)
+                return server
+        
+            def test_retrieve_some_content(testserver):
+                assert scrape(testserver.url) == 'Hello world!\n'
+        
+        Have a look at the following page for more information on WSGI:
+        http://wsgi.readthedocs.org/en/latest/learn.html
+        
+        Download and Installation
+        =========================
+        
+        You can install the plugin by running ::
+        
+            pip install pytest-localserver
+        
+        Alternatively, get the latest stable version from `PyPI`_ or the latest
+        `bleeding-edge archive`_ from bitbucket.org.
+        
+        License and Credits
+        ===================
+        
+        This plugin is released under the MIT license. You can find the full text of
+        the license in the LICENSE file.
+        
+        Copyright (C) 2010-2013 Sebastian Rahlf and others (see AUTHORS).
+        
+        Some parts of this package is based on ideas or code from other people:
+        
+        - I borrowed some implementation ideas for the httpserver from `linkchecker`_.
+        - The implementation for the SMTP server is based on the `Mailsink recipe`_ by 
+          Adam Feuer, Matt Branthwaite and Troy Frever.
+        - The HTTPS implementation is based on work by `Sebastien Martini`_.
+        
+        Thanks guys!
+        
+        Development and future plans
+        ============================
+        
+        Feel free to clone the repository and add your own changes. Pull requests are
+        always welcome!::
+        
+            hg clone https://bitbucket.org/basti/pytest-localserver
+        
+        If you find any bugs, please file a `report`_.
+        
+        Test can be run with tox. Note that you need virtualenv<1.8 to run tests for
+        Python 2.4.
+        
+        I already have a couple of ideas for future versions:
+        
+        * support for FTP, SSH (maybe base all on twisted?)
+        * making the SMTP outbox as convenient to use as ``django.core.mail.outbox``
+        * add your own here!
+        
+        ----
+        
+        .. [1] The idea for this project was born when I needed to check that `a piece
+               of software`_ behaved itself when receiving HTTP error codes 404 and 500.
+               Having unsuccessfully tried to mock a server, I stumbled across 
+               `linkchecker`_ which uses a the same idea to test its internals.
+        
+        .. _monkeypatching: http://pytest.org/latest/monkeypatch.html
+        .. _pytest: http://pytest.org/
+        .. _funcargs feature: http://pytest.org/latest/funcargs.html
+        .. _linkchecker: http://linkchecker.sourceforge.net/
+        .. _WSGI application: http://www.python.org/dev/peps/pep-0333/
+        .. _PyPI: http://pypi.python.org/pypi/pytest-localserver/
+        .. _bleeding-edge archive: https://bitbucket.org/basti/pytest-localserver/get/tip.tar.gz
+        .. _report: https://bitbucket.org/basti/pytest-localserver/issues/
+        .. _tox: http://testrun.org/tox/
+        .. _a piece of software: http://pypi.python.org/pypi/python-amazon-product-api/
+        .. _Mailsink recipe: http://code.activestate.com/recipes/440690/
+        .. _Sebastien Martini: http://code.activestate.com/recipes/442473/
+        
+Keywords: py.test pytest server localhost http smtp
+Platform: UNKNOWN
+Classifier: Operating System :: OS Independent
+Classifier: Development Status :: 4 - Beta
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Topic :: Software Development :: Testing
diff --git a/pytest_localserver.egg-info/SOURCES.txt b/pytest_localserver.egg-info/SOURCES.txt
new file mode 100644
index 0000000..0f64ed0
--- /dev/null
+++ b/pytest_localserver.egg-info/SOURCES.txt
@@ -0,0 +1,23 @@
+LICENSE
+MANIFEST.in
+README
+setup.py
+tox.ini
+pytest_localserver/__init__.py
+pytest_localserver/ca.crt
+pytest_localserver/http.py
+pytest_localserver/https.py
+pytest_localserver/plugin.py
+pytest_localserver/server.pem
+pytest_localserver/smtp.py
+pytest_localserver.egg-info/PKG-INFO
+pytest_localserver.egg-info/SOURCES.txt
+pytest_localserver.egg-info/dependency_links.txt
+pytest_localserver.egg-info/entry_points.txt
+pytest_localserver.egg-info/not-zip-safe
+pytest_localserver.egg-info/requires.txt
+pytest_localserver.egg-info/top_level.txt
+tests/__init__.py
+tests/test_http.py
+tests/test_https.py
+tests/test_smtp.py
\ No newline at end of file
diff --git a/pytest_localserver.egg-info/dependency_links.txt b/pytest_localserver.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/pytest_localserver.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/pytest_localserver.egg-info/entry_points.txt b/pytest_localserver.egg-info/entry_points.txt
new file mode 100644
index 0000000..c75f0fc
--- /dev/null
+++ b/pytest_localserver.egg-info/entry_points.txt
@@ -0,0 +1,3 @@
+[pytest11]
+localserver = pytest_localserver.plugin
+
diff --git a/pytest_localserver.egg-info/not-zip-safe b/pytest_localserver.egg-info/not-zip-safe
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/pytest_localserver.egg-info/not-zip-safe
@@ -0,0 +1 @@
+
diff --git a/pytest_localserver.egg-info/requires.txt b/pytest_localserver.egg-info/requires.txt
new file mode 100644
index 0000000..e41be49
--- /dev/null
+++ b/pytest_localserver.egg-info/requires.txt
@@ -0,0 +1 @@
+werkzeug>=0.10
\ No newline at end of file
diff --git a/pytest_localserver.egg-info/top_level.txt b/pytest_localserver.egg-info/top_level.txt
new file mode 100644
index 0000000..cfe3f2c
--- /dev/null
+++ b/pytest_localserver.egg-info/top_level.txt
@@ -0,0 +1 @@
+pytest_localserver
diff --git a/pytest_localserver/__init__.py b/pytest_localserver/__init__.py
new file mode 100644
index 0000000..46df43f
--- /dev/null
+++ b/pytest_localserver/__init__.py
@@ -0,0 +1 @@
+VERSION = '0.3.4'
diff --git a/pytest_localserver/ca.crt b/pytest_localserver/ca.crt
new file mode 100644
index 0000000..87a7c35
--- /dev/null
+++ b/pytest_localserver/ca.crt
@@ -0,0 +1,36 @@
+-----BEGIN CERTIFICATE-----
+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
+-----END CERTIFICATE-----
diff --git a/pytest_localserver/http.py b/pytest_localserver/http.py
new file mode 100644
index 0000000..1e66ab5
--- /dev/null
+++ b/pytest_localserver/http.py
@@ -0,0 +1,131 @@
+# Copyright (C) 2010-2013 Sebastian Rahlf and others (see AUTHORS).
+#
+# This program is release under the MIT license. You can find the full text of
+# the license in the LICENSE file.
+
+import json
+import sys
+import threading
+
+from werkzeug.serving import make_server
+from werkzeug.wrappers import Response, Request
+
+
+class WSGIServer(threading.Thread):
+
+    """
+    HTTP server running a WSGI application in its own thread.
+    """
+
+    def __init__(self, host='127.0.0.1', port=0, application=None, **kwargs):
+        self.app = application
+        self._server = make_server(host, port, self.app, **kwargs)
+        self.server_address = self._server.server_address
+
+        super(WSGIServer, self).__init__(
+            name=self.__class__,
+            target=self._server.serve_forever)
+
+    def __del__(self):
+        self.stop()
+
+    def stop(self):
+        self._server.shutdown()
+
+    @property
+    def url(self):
+        host, port = self.server_address
+        proto = 'http' if self._server.ssl_context is None else 'https'
+        return '%s://%s:%i' % (proto, host, port)
+
+
+class ContentServer(WSGIServer):
+
+    """
+    Small test server which can be taught which content (i.e. string) to serve
+    with which response code. Try the following snippet for testing API calls::
+
+        server = ContentServer(port=8080)
+        server.start()
+        print 'Test server running at http://%s:%i' % server.server_address
+
+        # any request to http://localhost:8080 will get a 503 response.
+        server.content = 'Hello World!'
+        server.code = 503
+
+        # ...
+
+        # we're done
+        server.stop()
+
+    """
+
+    def __init__(self, host='127.0.0.1', port=0, ssl_context=None):
+        super(ContentServer, self).__init__(host, port, self, ssl_context=ssl_context)
+        self.content, self.code = ('', 204)  # HTTP 204: No Content
+        self.headers = {}
+        self.show_post_vars = False
+        self.compress = None
+
+    def __call__(self, environ, start_response):
+        """
+        This is the WSGI application.
+        """
+        request = Request(environ)
+        if (request.content_type == 'application/x-www-form-urlencoded'
+        and request.method == 'POST' and self.show_post_vars):
+            content = json.dumps(request.form)
+        else:
+            content = self.content
+
+        response = Response(status=self.code)
+        response.headers.clear()
+        response.headers.extend(self.headers)
+
+        # FIXME get compression working!
+        # if self.compress == 'gzip':
+        #     content = gzip.compress(content.encode('utf-8'))
+        #     response.content_encoding = 'gzip'
+
+        response.data = content
+        return response(environ, start_response)
+
+    def serve_content(self, content, code=200, headers=None):
+        """
+        Serves string content (with specified HTTP error code) as response to
+        all subsequent request.
+
+        :param content: content to be displayed
+        :param code: HTTP status code
+        :param headers: HTTP headers to be returned
+        """
+        self.content, self.code = (content, code)
+        if headers:
+            self.headers = headers
+
+
+if __name__ == '__main__':  # pragma: no cover
+    import os.path
+    import time
+
+    app = ContentServer()
+    server = WSGIServer(application=app)
+    server.start()
+
+    print('HTTP server is running at %s' % server.url)
+    print('Type <Ctrl-C> to stop')
+
+    try:
+        path = sys.argv[1]
+    except IndexError:
+        path = os.path.join(
+            os.path.dirname(os.path.abspath(__file__)), '..', 'README')
+
+    app.serve_content(open(path).read(), 302)
+
+    try:
+        while True:
+            time.sleep(1)
+    except KeyboardInterrupt:
+        print('\rstopping...')
+    server.stop()
diff --git a/pytest_localserver/https.py b/pytest_localserver/https.py
new file mode 100644
index 0000000..67d58bd
--- /dev/null
+++ b/pytest_localserver/https.py
@@ -0,0 +1,133 @@
+# Copyright (C) 2010-2013 Sebastian Rahlf and others (see AUTHORS).
+#
+# This program is release under the MIT license. You can find the full text of
+# the license in the LICENSE file.
+
+import os.path
+
... 738 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pytest-localserver.git



More information about the Python-modules-commits mailing list