<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Using the Django App - Developers Resource — mailman_django v0.1 documentation</title> <link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '', VERSION: '0.1', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <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="mailman_django v0.1 documentation" href="index.html" /> <link rel="next" title="Acknowledgements" href="acknowledgements.html" /> <link rel="prev" title="Installation" href="setup.html" /> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <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="acknowledgements.html" title="Acknowledgements" accesskey="N">next</a> |</li> <li class="right" > <a href="setup.html" title="Installation" accesskey="P">previous</a> |</li> <li><a href="index.html">mailman_django v0.1 documentation</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-tests.tests"> <span id="using-the-django-app-developers-resource"></span><h1>Using the Django App - Developers Resource<a class="headerlink" href="#module-tests.tests" title="Permalink to this headline">¶</a></h1> <div class="section" id="functionality-and-test"> <h2>Functionality and Test<a class="headerlink" href="#functionality-and-test" title="Permalink to this headline">¶</a></h2> <p>This document both acts as a test for all the functions implemented in the UI as well as documenting what can be done</p> <div class="section" id="test-pre-requirements"> <h3>Test Pre Requirements<a class="headerlink" href="#test-pre-requirements" title="Permalink to this headline">¶</a></h3> <ul> <li><p class="first">We’ve created a special Testobject which will run it’s own instance of Mailman3 with a new empty Database.</p> <blockquote> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">setup</span> <span class="kn">import</span> <span class="n">setup_mm</span><span class="p">,</span> <span class="n">Testobject</span><span class="p">,</span> <span class="n">teardown_mm</span> <span class="gp">>>> </span><span class="n">testobject</span> <span class="o">=</span> <span class="n">setup_mm</span><span class="p">(</span><span class="n">Testobject</span><span class="p">())</span> </pre></div> </div> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">You need to stop all Mailman3 instances before running the tests</p> </div> </blockquote> </li> <li><dl class="first docutils"> <dt>Modules needed</dt> <dd><p class="first">As we can’t make sure that you’re running the same language as we did we made sure that each test below is executed using the exact same translation mechanism as we use to Display you Status Messages and other GUI Texts.</p> <dl class="last docutils"> <dt>Import Translation Module to check success messages</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">django.utils.translation</span> <span class="kn">import</span> <span class="n">gettext</span> <span class="k">as</span> <span class="n">_</span> </pre></div> </div> </dd> <dt>Import HTTPRedirectObject to check whether a response redirects</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">HttpResponseRedirect</span> </pre></div> </div> </dd> </dl> </dd> </dl> </li> </ul> </div> <div class="section" id="getting-started"> <h3>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h3> <p>Starting the test module we do use a special Django Test Client which needs to be imported first.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">django.test.client</span> <span class="kn">import</span> <span class="n">Client</span> <span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">Client</span><span class="p">()</span> </pre></div> </div> <p>Once this is created we can try accessing our first Page and check that this was done successful</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/lists/'</span><span class="p">,)</span> <span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> </pre></div> </div> </div> <div class="section" id="login-required"> <h3>Login Required<a class="headerlink" href="#login-required" title="Permalink to this headline">¶</a></h3> <p>As described within the installation instructions we <em>already</em> started using authentification. The easiest way testing it is that we simply load a page which is restricted to some users only. This was done using Django’s @login_required Decorator in front of the View. One of the pages which requires a Login is the Domain Administration, if we can load the page without a redirect to the Login page, you’re either already logged in or something went wrong.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/domains/'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="nb">type</span><span class="p">(</span><span class="n">response</span><span class="p">)</span> <span class="o">==</span> <span class="n">HttpResponseRedirect</span> <span class="go">True</span> </pre></div> </div> </div> <div class="section" id="login-of-a-user"> <h3>Login of a User<a class="headerlink" href="#login-of-a-user" title="Permalink to this headline">¶</a></h3> <p>We’ve decided to write our own Authentification Backend to use with Django. This will handle all @login_required .authenticate() .login() requests.</p> <p>As we do not have the Authenticating Part which connects Both Mailman and the WebUI we had to hardcode usernames and permissions into the file (auth/restbackend.py) For more information what we’re planning to implement here take a look at the Acknowledgements.</p> <blockquote> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">If you’re planning to expand this feel free to use this wonderful resource: <a class="reference external" href="https://docs.djangoproject.com/en/dev/topics/auth/">https://docs.djangoproject.com/en/dev/topics/auth/</a></p> </div> </blockquote> <p>Once the new middleware is in place we will need to create a user first. At the moment the user is automaticly created upon success of the login procedure.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="c">#c.... adduser() #TODO add user</span> </pre></div> </div> <p>Users will have to use the Login form which is located at (/accounts/login/) in order to authenticate themself. The Login / Logout button is linked in the bottom left corner of each page as well.</p> <p>After each successful login users should be redirected either to the site which they requested before - stored in a GET Value named next - or get the List index. Only if they’ve used a faulty login they should stay on the Login Page to try again.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s">'/accounts/login/'</span><span class="p">,</span> <span class="gp">... </span> <span class="p">{</span><span class="s">"user"</span><span class="p">:</span> <span class="s">"james@example.com"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"password"</span><span class="p">:</span> <span class="s">"james"</span><span class="p">})</span> </pre></div> </div> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="nb">type</span><span class="p">(</span><span class="n">response</span><span class="p">)</span> <span class="o">==</span> <span class="n">HttpResponseRedirect</span> <span class="go">True</span> </pre></div> </div> <p>Unfortuneatly the Test Client requires to use the Login directly because it does handle each request seperately. For this reason we have to use the following part in the Tests only to authenticate a user. Each successful Login will return True and write the users object into the request context, which allows simple checks whether there is a user logged in and what his name is.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">login</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="s">'katie@example.com'</span><span class="p">,</span> <span class="n">password</span><span class="o">=</span><span class="s">'katie'</span><span class="p">)</span> <span class="go">True</span> </pre></div> </div> </div> <div class="section" id="permissions"> <h3>Permissions<a class="headerlink" href="#permissions" title="Permalink to this headline">¶</a></h3> <p>Check that only James does have the permission to get the domains administration #TODO - ACL is hardcoded in auth backend : permission domain_admin → == james@...</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/domains/'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="nb">type</span><span class="p">(</span><span class="n">response</span><span class="p">)</span> <span class="o">==</span> <span class="n">HttpResponseRedirect</span> <span class="go">True</span> </pre></div> </div> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">logout</span><span class="p">()</span> <span class="c">#katie</span> </pre></div> </div> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">login</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="s">'james@example.com'</span><span class="p">,</span> <span class="n">password</span><span class="o">=</span><span class="s">'james'</span><span class="p">)</span> <span class="c">#now Domains should work - see tests below</span> <span class="go">True</span> </pre></div> </div> </div> <div class="section" id="create-a-new-domain"> <h3>Create a New Domain<a class="headerlink" href="#create-a-new-domain" title="Permalink to this headline">¶</a></h3> <p>Check the content to see that we came to the create page after logging in.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/domains/'</span><span class="p">)</span> </pre></div> </div> <dl class="docutils"> <dt>Then we check that everything went well.</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> <span class="gp">>>> </span><span class="k">print</span> <span class="s">"Domain Index"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="c">#TODO - change heading</span> <span class="go">True</span> </pre></div> </div> </dd> <dt>Check the button which should allow creation of a new domains</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="s">'<li class="mm_new_domain"><a href="/domains/new/">New Domain</a></li>'</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> <dt>Now go to the Domains creation page</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/domains/new/'</span><span class="p">)</span> </pre></div> </div> </dd> </dl> <p>Then we check that everything went well.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> <span class="gp">>>> </span><span class="k">print</span> <span class="s">"Add a new Domain"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="c">#TODO - change heading</span> <span class="go">True</span> </pre></div> </div> <p>and create a new Domain called ‘mail.example.com’. Check that the new Domain exists in the list of existing domains which is above new_domain form</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s">'/domains/new/'</span><span class="p">,</span> <span class="gp">... </span> <span class="p">{</span><span class="s">"mail_host"</span><span class="p">:</span> <span class="s">"mail.example.com"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"web_host"</span><span class="p">:</span> <span class="s">"example.com"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"description"</span><span class="p">:</span> <span class="s">"doctest testing domain"</span><span class="p">})</span> <span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/domains/'</span><span class="p">)</span> </pre></div> </div> <dl class="docutils"> <dt>Then we check that everything went well.</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> <span class="gp">>>> </span><span class="k">print</span> <span class="s">"doctest testing domain"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> </dl> </div> <div class="section" id="create-a-new-list"> <h3>Create a New List<a class="headerlink" href="#create-a-new-list" title="Permalink to this headline">¶</a></h3> <dl class="docutils"> <dt>Try to access the list index</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/lists/'</span><span class="p">)</span> </pre></div> </div> </dd> <dt>Then we check that everything went well.</dt> <dd><div class="first highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> </pre></div> </div> <div class="last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="s">"All available Lists"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> </dl> <p>Try to create a new list. And check the content to see that we came to the create page after logging in.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/lists/new/'</span><span class="p">)</span> </pre></div> </div> <dl class="docutils"> <dt>Then we check that everything went well.</dt> <dd><div class="first highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> </pre></div> </div> <div class="last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="s">"Create a new List on"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> </dl> <p>Now create a new list called ‘new_list’. We should end up on a redirect</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s">'/lists/new/'</span><span class="p">,</span> <span class="gp">... </span> <span class="p">{</span><span class="s">"listname"</span><span class="p">:</span> <span class="s">"new_list1"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"mail_host"</span><span class="p">:</span> <span class="s">"mail.example.com"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"list_owner"</span><span class="p">:</span> <span class="s">"james@example.com"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"description"</span><span class="p">:</span> <span class="s">"doctest testing list"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"advertised"</span><span class="p">:</span> <span class="s">"True"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"languages"</span><span class="p">:</span> <span class="s">"English (USA)"</span><span class="p">})</span> <span class="gp">>>> </span><span class="k">print</span> <span class="nb">type</span><span class="p">(</span><span class="n">response</span><span class="p">)</span> <span class="o">==</span> <span class="n">HttpResponseRedirect</span> <span class="go">True</span> </pre></div> </div> <p>List index page should now include the realname of the list</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/lists/'</span><span class="p">,</span><span class="n">HTTP_HOST</span><span class="o">=</span><span class="s">'example.com'</span><span class="p">)</span> </pre></div> </div> <dl class="docutils"> <dt>Then we check that everything went well.</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> <span class="gp">>>> </span><span class="s">"New_list1"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> </dl> </div> <div class="section" id="list-summary"> <h3>List Summary<a class="headerlink" href="#list-summary" title="Permalink to this headline">¶</a></h3> <p>Four options appear on this page. The first one is to subscribe, 2. to view archives 3. to edit the list settings #at least if you do have permission to do so 4. to unsubscribe</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/lists/new_list1%40mail.example.com/'</span><span class="p">,)</span> </pre></div> </div> <dl class="docutils"> <dt>Then we check that everything went well.</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> <span class="gp">>>> </span><span class="s">"Subscribe"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> <span class="gp">>>> </span><span class="s">"Archives"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> <span class="gp">>>> </span><span class="s">"Edit Options"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> <span class="gp">>>> </span><span class="s">"Unsubscribe"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> </dl> </div> <div class="section" id="subscriptions"> <h3>Subscriptions<a class="headerlink" href="#subscriptions" title="Permalink to this headline">¶</a></h3> <dl class="docutils"> <dt>Get the Subscriptions Page and check that the form was prefilled with the users E-Mail</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">url</span> <span class="o">=</span> <span class="s">'/subscriptions/new_list1%40mail.example.com/subscribe'</span> <span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span> </pre></div> </div> </dd> <dt>Then we check that everything went well.</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> <span class="gp">>>> </span><span class="s">"james@example.com"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> </dl> <p>Now subscribe James and Katie and check that you get redirected to List Summary which should now have an additional Button allowing to modify your user options.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="gp">... </span> <span class="p">{</span><span class="s">"email"</span><span class="p">:</span> <span class="s">"james@example.com"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"real_name"</span><span class="p">:</span> <span class="s">"James Watt"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"name"</span><span class="p">:</span> <span class="s">"subscribe"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"fqdn_listname"</span><span class="p">:</span> <span class="s">"new_list1@mail.example.com"</span><span class="p">})</span> <span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="gp">... </span> <span class="p">{</span><span class="s">"email"</span><span class="p">:</span> <span class="s">"katie@example.com"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"real_name"</span><span class="p">:</span> <span class="s">"Katie Doe"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"name"</span><span class="p">:</span> <span class="s">"subscribe"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"fqdn_listname"</span><span class="p">:</span> <span class="s">"new_list1@mail.example.com"</span><span class="p">})</span> <span class="gp">>>> </span><span class="k">print</span> <span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'Subscribed'</span><span class="p">)</span><span class="o">+</span><span class="s">' katie@example.com'</span><span class="p">)</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> <dl class="docutils"> <dt>The logged in user (<a class="reference external" href="mailto:james%40example.com">james<span>@</span>example<span>.</span>com</a>) can now modify his own membership using a button which is displayed in list_summary </dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/lists/new_list1%40mail.example.com/'</span><span class="p">)</span> <span class="gp">>>> </span><span class="s">"mm_membership"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> <dt>Using the same subscription page we can unsubscribe as well. </dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s">'/subscriptions/new_list1%40mail.example.com/unsubscribe'</span><span class="p">,</span> <span class="gp">... </span> <span class="p">{</span><span class="s">"email"</span><span class="p">:</span> <span class="s">"katie@example.com"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"name"</span><span class="p">:</span> <span class="s">"unsubscribe"</span><span class="p">,</span> <span class="gp">... </span> <span class="s">"fqdn_listname"</span><span class="p">:</span> <span class="s">"new_list1@mail.example.com"</span><span class="p">})</span> <span class="gp">>>> </span><span class="k">print</span> <span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'Unsubscribed'</span><span class="p">)</span><span class="o">+</span><span class="s">' katie@example.com'</span><span class="p">)</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> </dl> </div> <div class="section" id="mass-subscribe-users-within-settings"> <h3>Mass Subscribe Users (within settings)<a class="headerlink" href="#mass-subscribe-users-within-settings" title="Permalink to this headline">¶</a></h3> <p>Now we want to mass subscribe a few users to the list. Therefore, go to the mass subscription page.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">url</span> <span class="o">=</span> <span class="s">'/subscriptions/new_list1%40mail.example.com/mass_subscribe/'</span> <span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span> </pre></div> </div> <p>Check that everything went well by making sure the status code was correct.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> </pre></div> </div> <p>Try mass subscribing the users <a class="reference external" href="mailto:'liza%40example.com">'liza<span>@</span>example<span>.</span>com</a>‘ and <a class="reference external" href="mailto:'george%40example.com">'george<span>@</span>example<span>.</span>com</a>‘. Each address should be provided on a separate line so add ‘n’ between the names to indicate that this was done (we’re on a Linux machine which is why the letter ‘n’ was used and the double ‘’ instead of a single one is to escape the string parsing of Python).</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">url</span> <span class="o">=</span> <span class="s">'/subscriptions/new_list1%40mail.example.com/mass_subscribe/'</span> <span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="gp">... </span> <span class="p">{</span><span class="s">"emails"</span><span class="p">:</span> <span class="s">"liza@example.com</span><span class="se">\n</span><span class="s">george@example.com"</span><span class="p">})</span> </pre></div> </div> <p>If everything was successful, we shall get a positive response from the page. We’ll check that this was the case.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="n">_</span><span class="p">(</span><span class="s">"The mass subscription was successful."</span><span class="p">)</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </div> <div class="section" id="change-the-memebership-settings"> <h3>Change the Memebership Settings<a class="headerlink" href="#change-the-memebership-settings" title="Permalink to this headline">¶</a></h3> <p>Now let’s go to the membership settings page. Once we go there we should get a list of all the available lists.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/membership_settings/new_list1%40mail.example.com/'</span><span class="p">)</span> </pre></div> </div> <p>Check that we came to the right place...</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="s">"Membership Settings"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> <p>...and select the list <a class="reference external" href="mailto:'test-one%40example.com">'test-one<span>@</span>example<span>.</span>com</a>‘.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/membership_settings/new_list1%40mail.example.com/'</span><span class="p">)</span> </pre></div> </div> <p>Lets make sure we got to the right page.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="p">(</span><span class="s">"Membership Settings"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="s">"for new_list1@mail.example.com"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span><span class="p">)</span> <span class="go">True</span> </pre></div> </div> </div> <div class="section" id="delete-the-list"> <h3>Delete the List<a class="headerlink" href="#delete-the-list" title="Permalink to this headline">¶</a></h3> <p>Finally, let’s delete the list. We start by checking that the list is really there (for reference).</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/lists/'</span><span class="p">,</span><span class="n">HTTP_HOST</span><span class="o">=</span><span class="s">'example.com'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="s">"New_list1"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> <dl class="docutils"> <dt>Trying to delete the List we have to confirm this action</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/delete_list/new_list1%40mail.example.com/'</span><span class="p">,)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="s">"Please confirm"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">True</span> </pre></div> </div> </dd> <dt>Confirmed by pressing the button which requests the same page using POST</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s">'/delete_list/new_list1%40mail.example.com/'</span><span class="p">,)</span> </pre></div> </div> </dd> <dt>...and check that it’s been deleted.</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'/lists/'</span><span class="p">,</span><span class="n">HTTP_HOST</span><span class="o">=</span><span class="s">'example.com'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="s">"new_list1</span><span class="si">%40e</span><span class="s">xample.com"</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span> <span class="go">False</span> </pre></div> </div> </dd> </dl> <p>So far this is what you can do in the UI. More tests can be added here later.</p> </div> <div class="section" id="finishing-test"> <h3>Finishing Test<a class="headerlink" href="#finishing-test" title="Permalink to this headline">¶</a></h3> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">teardown_mm</span><span class="p">(</span><span class="n">testobject</span><span class="p">)</span> </pre></div> </div> </div> </div> <div class="section" id="running-the-tests-explained-above"> <h2>Running the tests explained above.<a class="headerlink" href="#running-the-tests-explained-above" title="Permalink to this headline">¶</a></h2> <p>We’ve added our own test-suite to the Django App which will be executed together with the Django Test. Last thing you should do is running these tests. If they fail you did something wrong, if they succeed you can enjoy the site.</p> <p>Run the following in the Site Directory</p> <blockquote> <div class="highlight-bash"><div class="highlight"><pre><span class="nv">$ </span>python manage.py <span class="nb">test</span> </pre></div> </div> </blockquote> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Please be aware that we want to run a development instance of mailman you need to stop the stable one first and the tests will open it’s own mailman temporily.</p> </div> </div> <div class="section" id="accessing-the-rest-client-for-testing"> <h2>Accessing the REST Client for Testing<a class="headerlink" href="#accessing-the-rest-client-for-testing" title="Permalink to this headline">¶</a></h2> <p>If you want to access the Functions, which we use in the views, directly feel free to run the following block of code within a Shell which does have it’s current Directory within the Django Site Directory.</p> <blockquote> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">settings</span> <span class="kn">import</span> <span class="n">API_USER</span><span class="p">,</span> <span class="n">API_PASS</span> <span class="kn">from</span> <span class="nn">mailman.client</span> <span class="kn">import</span> <span class="n">Client</span> <span class="n">c</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="s">'http://localhost:8001/3.0'</span><span class="p">,</span> <span class="n">API_USER</span><span class="p">,</span> <span class="n">API_PASS</span><span class="p">)</span> <span class="c">#DEBUG: Python Session</span> </pre></div> </div> </blockquote> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Using the Django App - Developers Resource</a><ul> <li><a class="reference internal" href="#functionality-and-test">Functionality and Test</a><ul> <li><a class="reference internal" href="#test-pre-requirements">Test Pre Requirements</a></li> <li><a class="reference internal" href="#getting-started">Getting Started</a></li> <li><a class="reference internal" href="#login-required">Login Required</a></li> <li><a class="reference internal" href="#login-of-a-user">Login of a User</a></li> <li><a class="reference internal" href="#permissions">Permissions</a></li> <li><a class="reference internal" href="#create-a-new-domain">Create a New Domain</a></li> <li><a class="reference internal" href="#create-a-new-list">Create a New List</a></li> <li><a class="reference internal" href="#list-summary">List Summary</a></li> <li><a class="reference internal" href="#subscriptions">Subscriptions</a></li> <li><a class="reference internal" href="#mass-subscribe-users-within-settings">Mass Subscribe Users (within settings)</a></li> <li><a class="reference internal" href="#change-the-memebership-settings">Change the Memebership Settings</a></li> <li><a class="reference internal" href="#delete-the-list">Delete the List</a></li> <li><a class="reference internal" href="#finishing-test">Finishing Test</a></li> </ul> </li> <li><a class="reference internal" href="#running-the-tests-explained-above">Running the tests explained above.</a></li> <li><a class="reference internal" href="#accessing-the-rest-client-for-testing">Accessing the REST Client for Testing</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="setup.html" title="previous chapter">Installation</a></p> <h4>Next topic</h4> <p class="topless"><a href="acknowledgements.html" title="next chapter">Acknowledgements</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/using.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <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="acknowledgements.html" title="Acknowledgements" >next</a> |</li> <li class="right" > <a href="setup.html" title="Installation" >previous</a> |</li> <li><a href="index.html">mailman_django v0.1 documentation</a> »</li> </ul> </div> <div class="footer"> © Copyright 2011, Benedict Stein. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1. </div> </body> </html>