~flo-fuchs/mailman.client/archival_options

« back to all changes in this revision

Viewing changes to src/mailmanclient/docs/using.rst

  • Committer: Barry Warsaw
  • Date: 2015-01-04 22:43:40 UTC
  • mto: This revision was merged to the branch mainline in revision 60.
  • Revision ID: barry@list.org-20150104224340-j6t6srksn14bjjz3
* Remove an unused file.
* Port to Python 3.4
* Add `queues` resource.
* Clean up doctest.
* Move one corner case to unittest.
* Record HTTP traffic with vcr so that the test suite can be run off-line.
* Added `tox -e record` to run the vcr recorder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Mailman REST client
3
3
===================
4
4
 
5
 
    >>> import os
6
 
    >>> import time
7
 
    >>> import smtplib
8
 
    >>> import subprocess
9
 
 
10
 
    >>> from mock import patch
11
 
 
12
5
This is the official Python bindings for the GNU Mailman REST API.  In order
13
6
to talk to Mailman, the engine's REST server must be running.  You begin by
14
7
instantiating a client object to access the root of the REST hierarchy,
74
67
    >>> print(example_dot_com.base_url)
75
68
    http://example.com
76
69
 
77
 
But you cannot retrieve a non-existent domain.
78
 
 
79
 
    >>> client.get_domain('example.org')
80
 
    Traceback (most recent call last):
81
 
    ...
82
 
    HTTPError: HTTP Error 404: 404 Not Found
83
 
 
84
70
After creating a few more domains, we can print the list of all domains.
85
71
 
86
72
    >>> client.create_domain('example.net')
309
295
After a while, Anna decides to unsubscribe from the Test One mailing list,
310
296
though she keeps her Test Two membership active.
311
297
 
 
298
    >>> import time
312
299
    >>> time.sleep(2)
313
300
    >>> test_one.unsubscribe('anna@example.com')
314
301
    >>> for member in client.members:
645
632
Message Moderation
646
633
------------------
647
634
 
 
635
By injecting a message by a non-member into the incoming queue, we can
 
636
simulate a message being held for moderator approval.
 
637
 
648
638
    >>> msg = """From: nomember@example.com
649
639
    ... To: test-one@example.com
650
640
    ... Subject: Something
653
643
    ... Some text.
654
644
    ...
655
645
    ... """
656
 
    >>> inject_message('test-one@example.com', msg)
 
646
    >>> inq = client.queues['in']
 
647
    >>> inq.inject('test-one.example.com', msg)
 
648
 
 
649
Now wait until the message has been processed.
 
650
 
 
651
    >>> while True:
 
652
    ...     if len(inq.files) == 0:
 
653
    ...         break
 
654
    ...     time.sleep(0.1)
 
655
 
 
656
It might take a few moments for the message to show up in the moderation
 
657
queue.
 
658
 
 
659
    >>> while True:
 
660
    ...     held = test_one.held
 
661
    ...     if len(held) > 0:
 
662
    ...         break
 
663
    ...     time.sleep(0.1)
657
664
 
658
665
Messages held for moderation can be listed on a per list basis.
659
666
 
660
 
    >>> held = test_one.held
661
667
    >>> print(held[0]['subject'])
662
668
    Something
663
669
    >>> print(held[0]['reason'])