Changeset 5:573fdae8b1f6 in mailjam for postman/daemon.py


Ignore:
Timestamp:
May 16, 2012, 11:41:47 AM (13 years ago)
Author:
Francisco de Borja Lopez Rio <borja@…>
Branch:
default
Phase:
public
Message:

Added tests for postman.daemon.Postman

Added a method to postman.daemon.Postman to "clear" all the storage associated
to a given postman instance (removing all the files from disk)

Fixed some bugs, mostly caused by typos through the sources, detected while
writing more tests

Removed the storage and archive attributes from postman.models.MailingList,
now they are methods "marked" as properties using the @property decorator.
This keeps the storage objects from being serialized into json objects by
the storage backend (de-serializing them caused some trouble and it is not
necessary at all)

Added create() and delete() methods to postman.storage.JsonStorage. the first
one ensures the path to the storage file exists (creating all subdirs if
necessary) and the second one deletes the storage file from disk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postman/daemon.py

    r2 r5  
    4242            for m in self.mailings.keys():           
    4343                self.mailings[m].save()
     44            return True
     45        return False
    4446
    4547    def load(self):
     
    5961                mailing.load()
    6062                self.mailings[address] = mailing               
    61            
     63            return True
     64        return False
    6265
    63     def add_mailing_list(self, list_info={}):
     66    def clear(self):
     67        """
     68        Delete all stored data from disk (useful for testing).
     69        DANGER: Calling this method will remove all data from disk, leaving the
     70        postman instance with no persistence data, if the postman process die,
     71        before another .save() call is made, all data will be lost.
     72        """
     73        if self.dbs['mailings'].exists():
     74            # We do not delete each mailing list file, but only the file
     75            # containing the list of existing mailing lists
     76            self.dbs['mailings'].delete()
     77            return True
     78        return False
     79
     80    def add_mailing_list(self, info={}):
    6481        """
    6582        Add a new mailing list to this postman instance. expects one parameter,
    66         list_info, which is a dictionary that should contain, at least, the
     83        info, which is a dictionary that should contain, at least, the
    6784        following keys:
    6885
     
    7289         
    7390        """
    74         if not isinstance(list_info, dict):
    75             raise TypeError(list_info, ' is not a valid dictionary')
     91        if not isinstance(info, dict):
     92            raise TypeError(info, ' is not a valid dictionary')
    7693
    77         if 'name' not in list_info.keys() or \
    78            'address' not in list_info.keys() or \
    79            'members' not in list_info.keys():
    80             raise ValueError(list_info, ' does not seem to be a valid configuration')
     94        if 'name' not in info.keys() or \
     95           'address' not in info.keys() or \
     96           'members' not in info.keys() or \
     97           'config' not in info.keys():
     98            raise ValueError(info, ' does not seem to be a valid configuration')
    8199       
    82         if list_info['address'] in self.mailings_addresses:
    83             raise IndexError(list_info['address'],
     100        if info['address'] in self.mailings_addresses:
     101            raise IndexError(info['address'],
    84102                             ' has been already added to postman')
    85103
    86         mailing = MailingList(list_info['name'], list_info['address'],
    87                               list_info['members'])       
     104        mailing = MailingList(info['name'], info['address'],
     105                              info['members'], info['config'])       
    88106        self.mailings[mailing.address] = mailing
    89107        self.mailings_addresses.append(mailing.address)
    90108        # After adding new mailings, save them to disk
    91109        self.save()
     110        return True
    92111       
    93112    def add_mailing_member(self, member_addr=None, list_addr=None):
     
    109128            raise IndexError(list_addr, ' is not a valid mailing list')
    110129
    111         member = Member(member_addr)
    112        
     130        added = self.mailings[list_addr].add_member_by_address(member_addr)
     131        if added:
     132            self.save()
     133        return added
    113134       
    114135
Note: See TracChangeset for help on using the changeset viewer.