Commit f958678d authored by Florian Fuchs's avatar Florian Fuchs

- added empty settings file to doc folder to make sphinx able to import postorius modules

- fixed typo in development doc
parent 2a89b3dd
......@@ -25,48 +25,10 @@ runner find your tests, make sure to add them to the folder's ``__init__.py``:
}
``postorius.*`` imports in test modules
---------------------------------------
When writing unittests make sure that any ``postorius.*`` imports are made
at the test method level and not at the module level. Here's why:
The Postorius documentation (the one you are reading right now) imports some
doctest modules from the test package using Sphinx's autodoc extension. This is
a very nice feature, but in this scenario it has the nasty side effect of
breaking the build process if application code is imported as well (it will
fail to find an environment variable that Django needs to run). This can be
easily prevented by avoiding module level imports of postorius code in the test
modules.
Good:
::
from django.utils import unittest
from mock import patch
class SomeTest(unittest.TestCase):
def test_some_method(self):
from postorius.views import SomeViewClass
foo = 'bar'
Bad:
::
from django.utils import unittest
from mock import patch
from postorius.views import SomeViewClass
class SomeTest(unittest.TestCase):
def test_some_method(self):
foo = 'bar'
Running the tests
-----------------
To run the tests go to your project folder and run ``python manage.py test postorius`` from there.
Mocking
......
......@@ -30,6 +30,10 @@ along with Postorius. If not, see <http://www.gnu.org/licenses/>.
* installation documentation for Apache/mod_wsgi
* moved project files to separate branch
* show error message if connection to Mailman API fails
* added list members view
* added developer documentation
* added test helper utils
* all code now conform to PEP8
1.0 alpha 1 -- "Space Farm"
......
......@@ -79,11 +79,11 @@ div.sphinxsidebar input {
font-size: 1em;
}
div.sphinxsidebar #searchbox input[type="text"] {
div.sphinxsidebar input[type="text"] {
width: 170px;
}
div.sphinxsidebar #searchbox input[type="submit"] {
div.sphinxsidebar input[type="submit"] {
width: 30px;
}
......
......@@ -70,41 +70,9 @@ runner find your tests, make sure to add them to the folder&#8217;s <tt class="d
<span class="p">}</span>
</pre></div>
</div>
<div class="section" id="postorius-imports-in-test-modules">
<h3><tt class="docutils literal"><span class="pre">postorius.*</span></tt> imports in test modules<a class="headerlink" href="#postorius-imports-in-test-modules" title="Permalink to this headline"></a></h3>
<p>When writing unittests make sure that any <tt class="docutils literal"><span class="pre">postorius.*</span></tt> imports are made
at the test method level and not at the module level. Here&#8217;s why:</p>
<p>The Postorius documentation (the one you are reading right now) imports some
doctest modules from the test package using Sphinx&#8217;s autodoc extension. This is
a very nice feature, but in this scenario it has the nasty side effect of
breaking the build process if application code is imported as well (it will
fail to find an environment variable that Django needs to run). This can be
easily prevented by avoiding module level imports of postorius code in the test
modules.</p>
<p>Good:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">unittest</span>
<span class="kn">from</span> <span class="nn">mock</span> <span class="kn">import</span> <span class="n">patch</span>
<span class="k">class</span> <span class="nc">SomeTest</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">test_some_method</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">postorius.views</span> <span class="kn">import</span> <span class="n">SomeViewClass</span>
<span class="n">foo</span> <span class="o">=</span> <span class="s">&#39;bar&#39;</span>
</pre></div>
</div>
<p>Bad:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">unittest</span>
<span class="kn">from</span> <span class="nn">mock</span> <span class="kn">import</span> <span class="n">patch</span>
<span class="kn">from</span> <span class="nn">postorius.views</span> <span class="kn">import</span> <span class="n">SomeViewClass</span>
<span class="k">class</span> <span class="nc">SomeTest</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">test_some_method</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">foo</span> <span class="o">=</span> <span class="s">&#39;bar&#39;</span>
</pre></div>
</div>
<div class="section" id="running-the-tests">
<h3>Running the tests<a class="headerlink" href="#running-the-tests" title="Permalink to this headline"></a></h3>
<p>To run the tests go to your project folder and run <tt class="docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">test</span> <span class="pre">postorius</span></tt> from there.</p>
</div>
<div class="section" id="mocking">
<h3>Mocking<a class="headerlink" href="#mocking" title="Permalink to this headline"></a></h3>
......@@ -122,7 +90,7 @@ objects retreived from mailman.client, like:</p>
<span id="mocking-mailman-client-objects"></span><h4>Mocking mailman.client objects<a class="headerlink" href="#module-postorius.tests.test_utils" title="Permalink to this headline"></a></h4>
<div class="section" id="domains">
<h5>Domains<a class="headerlink" href="#domains" title="Permalink to this headline"></a></h5>
<p><tt class="docutils literal"><span class="pre">postorius.tests.utils.create_mock_list</span></tt> creates a mock domain object:</p>
<p><tt class="docutils literal"><span class="pre">postorius.tests.utils.create_mock_domain</span></tt> creates a mock domain object:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">properties</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">contact_address</span><span class="o">=</span><span class="s">&#39;postmaster@example.org&#39;</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">description</span><span class="o">=</span><span class="s">&#39;Example dot Org&#39;</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">mail_host</span><span class="o">=</span><span class="s">&#39;example.org&#39;</span><span class="p">,</span>
......@@ -192,7 +160,7 @@ objects retreived from mailman.client, like:</p>
<ul>
<li><a class="reference internal" href="#">Development</a><ul>
<li><a class="reference internal" href="#testing">Testing</a><ul>
<li><a class="reference internal" href="#postorius-imports-in-test-modules"><tt class="docutils literal"><span class="pre">postorius.*</span></tt> imports in test modules</a></li>
<li><a class="reference internal" href="#running-the-tests">Running the tests</a></li>
<li><a class="reference internal" href="#mocking">Mocking</a><ul>
<li><a class="reference internal" href="#module-postorius.tests.test_utils">Mocking mailman.client objects</a><ul>
<li><a class="reference internal" href="#domains">Domains</a></li>
......@@ -250,7 +218,7 @@ objects retreived from mailman.client, like:</p>
</div>
<div class="footer">
&copy; Copyright 2012, The Free Software Foundation.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
......@@ -117,7 +117,7 @@
</div>
<div class="footer">
&copy; Copyright 2012, The Free Software Foundation.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
......@@ -110,7 +110,7 @@
</div>
<div class="footer">
&copy; Copyright 2012, The Free Software Foundation.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
......@@ -36,9 +36,6 @@
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="setup.html" title="Installation"
accesskey="N">next</a> |</li>
......@@ -78,6 +75,10 @@ along with Postorius. If not, see &lt;<a class="reference external" href="http:/
<li>installation documentation for Apache/mod_wsgi</li>
<li>moved project files to separate branch</li>
<li>show error message if connection to Mailman API fails</li>
<li>added list members view</li>
<li>added developer documentation</li>
<li>added test helper utils</li>
<li>all code now conform to PEP8</li>
</ul>
</div>
<div class="section" id="alpha-1-space-farm">
......@@ -153,9 +154,6 @@ Daniel Mizyrycki</li>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="setup.html" title="Installation"
>next</a> |</li>
......@@ -167,7 +165,7 @@ Daniel Mizyrycki</li>
</div>
<div class="footer">
&copy; Copyright 2012, The Free Software Foundation.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
......@@ -125,7 +125,7 @@
</div>
<div class="footer">
&copy; Copyright 2012, The Free Software Foundation.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
......@@ -99,7 +99,7 @@
</div>
<div class="footer">
&copy; Copyright 2012, The Free Software Foundation.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
......@@ -36,9 +36,6 @@
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="development.html" title="Development"
accesskey="N">next</a> |</li>
......@@ -238,9 +235,6 @@ site directory. All you have to do is to change into the
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="development.html" title="Development"
>next</a> |</li>
......@@ -252,7 +246,7 @@ site directory. All you have to do is to change into the
</div>
<div class="footer">
&copy; Copyright 2012, The Free Software Foundation.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
......@@ -25,8 +25,7 @@
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Postorius 1.0a2 documentation" href="index.html" />
<link rel="prev" title="Installation" href="setup.html" />
<link rel="top" title="Postorius 1.0a2 documentation" href="index.html" />
</head>
<body>
<div class="related">
......@@ -38,9 +37,6 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="setup.html" title="Installation"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Postorius 1.0a2 documentation</a> &raquo;</li>
</ul>
</div>
......@@ -364,9 +360,6 @@ We start by checking that the list is really there (for reference).</p>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="setup.html"
title="previous chapter">Installation</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/using.txt"
......@@ -398,9 +391,6 @@ We start by checking that the list is really there (for reference).</p>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="setup.html" title="Installation"
>previous</a> |</li>
<li><a href="index.html">Postorius 1.0a2 documentation</a> &raquo;</li>
</ul>
</div>
......
......@@ -13,6 +13,9 @@
import sys, os
# add dummy settings environment variable so sphinx can import from Postorius.
os.environ['DJANGO_SETTINGS_MODULE'] = 'postorius.doc.settings'
#import the source code directory into Python Path for use with Auto Module
APP_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.split(APP_ROOT)[0])
......
......@@ -25,48 +25,10 @@ runner find your tests, make sure to add them to the folder's ``__init__.py``:
}
``postorius.*`` imports in test modules
---------------------------------------
When writing unittests make sure that any ``postorius.*`` imports are made
at the test method level and not at the module level. Here's why:
The Postorius documentation (the one you are reading right now) imports some
doctest modules from the test package using Sphinx's autodoc extension. This is
a very nice feature, but in this scenario it has the nasty side effect of
breaking the build process if application code is imported as well (it will
fail to find an environment variable that Django needs to run). This can be
easily prevented by avoiding module level imports of postorius code in the test
modules.
Good:
::
from django.utils import unittest
from mock import patch
class SomeTest(unittest.TestCase):
def test_some_method(self):
from postorius.views import SomeViewClass
foo = 'bar'
Bad:
::
from django.utils import unittest
from mock import patch
from postorius.views import SomeViewClass
class SomeTest(unittest.TestCase):
def test_some_method(self):
foo = 'bar'
Running the tests
-----------------
To run the tests go to your project folder and run ``python manage.py test postorius`` from there.
Mocking
......
#-*- coding: utf-8 -*-
# Copyright (C) 1998-2012 by the Free Software Foundation, Inc.
#
# This file is part of Postorius.
#
# Postorius is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Postorius is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# Postorius. If not, see <http://www.gnu.org/licenses/>.
"""This is just an empty settings file to make Sphinx able to export
the DJANGO_SETTINGS_MODULE env variable before building the docs."""
......@@ -26,7 +26,7 @@
Domains
=======
``postorius.tests.utils.create_mock_list`` creates a mock domain object:
``postorius.tests.utils.create_mock_domain`` creates a mock domain object:
>>> properties = dict(contact_address='postmaster@example.org',
... description='Example dot Org',
......
......@@ -48,6 +48,7 @@ def create_mock_list(properties=None):
:rtype: MagicMock
"""
mock_object = MagicMock(name='List')
# like in mock_domain, some defaults need to be added...
if properties is not None:
for key in properties:
setattr(mock_object, key, properties[key])
......@@ -63,6 +64,7 @@ def create_mock_member(properties=None):
:rtype: MagicMock
"""
mock_object = MagicMock(name='Member')
# like in mock_domain, some defaults need to be added...
if properties is not None:
for key in properties:
setattr(mock_object, key, properties[key])
......
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