<!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="tests-login-and-permissions"> <h2>Tests Login and Permissions<a class="headerlink" href="#tests-login-and-permissions" 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>Our own Auth Backend allows the use of Djangos own Permission Decorator which is</p> <div class="highlight-python"><pre>@permission_required(NAME_OF_PERMISSION)</pre> </div> <p>At the moment we’ve installed this for Domain Administration,</p> <blockquote> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Please take a look at the ackownledgement to see what is working in this part</p> </div> </blockquote> <p>Get the Domains page and get redirected because Katie who is logged in doesn’t have the Permission</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> <p>Logout Katie who isn’t a Domain-Owner and Login James who should be allowed to view this page</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">logout</span><span class="p">()</span> <span class="c">#katie</span> <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="go">True</span> </pre></div> </div> <p>Check that the Page now loads correctly</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="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="go">200</span> </pre></div> </div> </div> </div> <div class="section" id="pages"> <h2>Pages<a class="headerlink" href="#pages" title="Permalink to this headline">¶</a></h2> <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>Domain Administration is called by opening the URL mentioned below. Prequirements like Authorisation and Permissions have been covered before. Now we do check that the response really does have the correct heading.</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="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="go">True</span> </pre></div> </div> <p>On this page there should be a button which allows to create a new Domain. If you’re running Mailman for the first time you need to create a Domain before creating Mailinglists. That’s only because each List is Part of a Domain and could not be created without it’s reference.</p> <div class="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> <dl class="docutils"> <dt>For sure the page allowing the creation of a new Domain should open correclty 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">get</span><span class="p">(</span><span class="s">'/domains/new/'</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> <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> </dd> </dl> <p>Each Domain has two main Data Parts, most obvious for a mailinglist we do need a mail_host that’s the part behind the @ when getting an email. In addition we offer you this WebUI for configuration, some may have multiple URLs they can use to access the same installation of mailman. For this reason each Mailinglist gets it’s own web_host as well - which doesn’t need to be unique.</p> <p>Testing the Site we do now submit the form we’ve loaded earlier by sending all necessary data in a POST request. The new Domain will be called mail.example.com and available via it’s web_host example.com.</p> <blockquote> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">If you do want to use web_host filtering in your webUI you need to remember adding the URL to your /etc/hosts - at least for development</p> </div> <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> </blockquote> <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> <p>After creating a Domain you should be able to create new Lists. The Button for doing so is shown on the List index Page which should offer a list of all available (adverrtised) 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">'/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> <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> <p>The new List creation form is opened by clicking on the Button mentioned above or accessing the page directly</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> <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">"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> <p>Creating a new List we do need to specify at least the below mentioned items. Those were entered using some nice GUI Forms which do only show up available Values or offer you to choose a name which will be checked during validation. We’re now submitting the form using a POST request and get redirected to the List Index Page</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>As List index is an overview of all advertised Lists and we’ve choosen to do so we should now see our new List within the overview. HTTP_HOST is added as META Data for the request because we do only want to see Domains which belong to the example.com web_host</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="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> </div> <div class="section" id="list-summary"> <h3>List Summary<a class="headerlink" href="#list-summary" title="Permalink to this headline">¶</a></h3> <p>List summary is a dashboard for each List. It does have Links to the most useful functions which are only related to that Domain. These include the Values mentioned below. _(function) is used to Translate these to you local language.</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> <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="n">_</span><span class="p">(</span><span class="s">"Subscribe"</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> <span class="gp">>>> </span><span class="n">_</span><span class="p">(</span><span class="s">"Archives"</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> <span class="gp">>>> </span><span class="n">_</span><span class="p">(</span><span class="s">"Edit Options"</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> <span class="gp">>>> </span><span class="n">_</span><span class="p">(</span><span class="s">"Unsubscribe"</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="subscriptions"> <h3>Subscriptions<a class="headerlink" href="#subscriptions" title="Permalink to this headline">¶</a></h3> <p>The Subscriptions form is found on the below URL. Last part of the Url is one of [None,’subscribe’,’unsubscribe’]</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/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> <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>Forms will be prefilled with the Users Email if so. is logged in.</p> <div class="highlight-python"><div class="highlight"><pre><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> <p>Now we can subscribe James and Katie and check that we get redirected to List Summary.</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> <p>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.</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> <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> <p>Using the same subscription page we can unsubscribe as 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">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> </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>Another page related to Mass Subscriptions will be available to List Owners as well. This page will allow adding a couple of users to one lists at the same time.</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> <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> <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>Select the list <a class="reference external" href="mailto:'new_list1%40example.com">'new_list1<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> <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 class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This page relies on the Middleware connecting the Django Project with Mailman - see acknowledgements</p> </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> </div> </div> <div class="section" id="finishing-test"> <h2>Finishing Test<a class="headerlink" href="#finishing-test" title="Permalink to this headline">¶</a></h2> <dl class="docutils"> <dt>Don’t forget to remove the test object after testing all functions</dt> <dd><div class="first last 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> </dd> </dl> </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="#tests-login-and-permissions">Tests Login and Permissions</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> </ul> </li> <li><a class="reference internal" href="#pages">Pages</a><ul> <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> </ul> </li> <li><a class="reference internal" href="#finishing-test">Finishing Test</a></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>