def test_delete_messages(self):
        """
        Test that checks the correct behaivour of messages deletion adding two
        messages, deleting one and checking that this one and only this one has
        been removed.
        """
        sms_list = [
            ShortMessage(u'+3456345435',
                         u'how are you man',
                         _datetime=datetime.datetime.now()),
            ShortMessage(u'+3400000000',
                         u'how are you?',
                         _datetime=datetime.datetime.now())
        ]

        responses = self.messages.add_messages(sms_list, 1)

        def check_messages(list):
            self.failIfIn(responses[0], list)
            self.failUnlessIn(responses[1], list)
            self.messages.delete_messages([responses[1]])

        def delete_one(list):
            self.messages.delete_messages([responses[0]])
            d2 = self.messages.get_messages()
            d2.addCallback(check_messages)
            return d2

        d = self.messages.get_messages()
        d.addCallback(delete_one)
        return d
    def test_add_messages(self):
        now = datetime.datetime.now()
        _sms1 = ShortMessage(u'+4554354333', u'how are ya', self.now)
        _sms2 = ShortMessage(u'+3546564564', u'hola!', self.now)
        _sms3 = ShortMessage(u'+4354534534', u'adios', self.now)

        _list = [_sms1, _sms2, _sms3]
        responses = self.mana.add_messages(_list, where=2)

        for _sms in [_sms1, _sms2, _sms3]:
            self.failUnlessIn(_sms, responses)
    def test_delete_messages(self):
        smslist = [
            ShortMessage(u'+455438983', u'hey man', self.now),
            ShortMessage(u'+4554354333', u'how are ya', self.now),
            ShortMessage(u'+3546564564', u'hola!', self.now),
            ShortMessage(u'+4354534534', u'adios', self.now),
        ]

        responses = self.mana.add_messages(smslist, where=2)
        exp = responses.pop(0)

        for _sms in responses:
            self.mana.delete_message_by_id(_sms.get_index())

        messages = list(self.mana.get_messages())
        self.failUnlessIn(exp, messages)
    def test_add_messages_in_db_and_get_messages(self):
        """
        Test that checks if a list of messages is correctly added, and if
        get_messages works
        """       
        sms_list = [ShortMessage(u'+3456345435', u'how are you man',
                            _datetime=datetime.datetime.now()),
                    ShortMessage(u'+3400000000', u'how are you?',
                            _datetime=datetime.datetime.now())]
        
        responses = self.messages.add_messages(sms_list, 1)

        def check_messages(list):
            for sms in responses:
                self.assertIn(sms, list)
            self.messages.delete_messages(responses)

        d = self.messages.get_messages()        
        d.addCallback(check_messages)
        return d
    def test_add_message_in_db(self):
        """
        Test that checks if a message is correctly added.
        """
        s = ShortMessage(u'+3456345435', u'how are you man',
                            _datetime=datetime.datetime.now())
        d = self.messages.add_message(s, 2)
        def add_message_cb(sms):
            d2 = self.messages.get_messages()
            d2.addCallback(lambda smslist: self.assertIn(sms, smslist))
            d2.addCallback(lambda _: self.messages.delete_messages([sms]))
            return d2

        d.addCallback(add_message_cb)            
        return d