コード例 #1
0
ファイル: message_test.py プロジェクト: ptomblin/EmmaPython
class MessageTest(unittest.TestCase):
    def setUp(self):
        Account.default_adapter = MockAdapter
        self.message = Message(
            Mailing(
                Account(account_id="100", public_key="xxx", private_key="yyy"),
                {'mailing_id': 200}), 1024)

    def test_can_forward_a_message(self):
        MockAdapter.expected = False
        with self.assertRaises(ex.MailingForwardError):
            self.message.forward(["*****@*****.**"])
        self.assertEquals(self.message.mailing.account.adapter.called, 1)
        self.assertEquals(self.message.mailing.account.adapter.call,
                          ('POST', '/forwards/200/1024', {
                              'recipient_emails': ["*****@*****.**"]
                          }))

    def test_can_forward_a_message2(self):
        MockAdapter.expected = {'mailing_id': 2048}
        mailing_id = self.message.forward(["*****@*****.**"])
        self.assertEquals(self.message.mailing.account.adapter.called, 1)
        self.assertEquals(self.message.mailing.account.adapter.call,
                          ('POST', '/forwards/200/1024', {
                              'recipient_emails': ["*****@*****.**"]
                          }))
        self.assertIsInstance(mailing_id, int)
        self.assertEquals(mailing_id, 2048)

    def test_can_forward_a_message3(self):
        del (self.message.mailing['mailing_id'])
        with self.assertRaises(ex.NoMailingIdError):
            self.message.forward(["*****@*****.**"])
        self.assertEquals(self.message.mailing.account.adapter.called, 0)

    def test_can_forward_a_message4(self):
        self.message.member_id = None
        with self.assertRaises(ex.NoMemberIdError):
            self.message.forward(["*****@*****.**"])
        self.assertEquals(self.message.mailing.account.adapter.called, 0)

    def test_can_forward_a_message5(self):
        result = self.message.forward()
        self.assertEquals(self.message.mailing.account.adapter.called, 0)
        self.assertIsNone(result)

    def test_can_forward_a_message6(self):
        MockAdapter.expected = {'mailing_id': 2048}
        mailing_id = self.message.forward(["*****@*****.**"], "Test Note")
        self.assertEquals(self.message.mailing.account.adapter.called, 1)
        self.assertEquals(self.message.mailing.account.adapter.call,
                          ('POST', '/forwards/200/1024', {
                              'recipient_emails': ["*****@*****.**"],
                              'note': "Test Note"
                          }))
        self.assertIsInstance(mailing_id, int)
        self.assertEquals(mailing_id, 2048)
コード例 #2
0
ファイル: message_test.py プロジェクト: aezell/EmmaPython
 def setUp(self):
     Account.default_adapter = MockAdapter
     self.message = Message(
         Mailing(
             Account(account_id="100", public_key="xxx", private_key="yyy"),
             {'mailing_id': 200}
         ),
         1024
     )
コード例 #3
0
ファイル: message_test.py プロジェクト: aezell/EmmaPython
class MessageTest(unittest.TestCase):
    def setUp(self):
        Account.default_adapter = MockAdapter
        self.message = Message(
            Mailing(
                Account(account_id="100", public_key="xxx", private_key="yyy"),
                {'mailing_id': 200}
            ),
            1024
        )

    def test_can_forward_a_message(self):
        MockAdapter.expected = False
        with self.assertRaises(ex.MailingForwardError):
            self.message.forward(["*****@*****.**"])
        self.assertEquals(self.message.mailing.account.adapter.called, 1)
        self.assertEquals(
            self.message.mailing.account.adapter.call,
            ('POST', '/forwards/200/1024', {'recipient_emails':["*****@*****.**"]}))

    def test_can_forward_a_message2(self):
        MockAdapter.expected = {'mailing_id': 2048}
        mailing_id = self.message.forward(["*****@*****.**"])
        self.assertEquals(self.message.mailing.account.adapter.called, 1)
        self.assertEquals(
            self.message.mailing.account.adapter.call,
            (
                'POST',
                '/forwards/200/1024',
                {'recipient_emails':["*****@*****.**"]}))
        self.assertIsInstance(mailing_id, int)
        self.assertEquals(mailing_id, 2048)

    def test_can_forward_a_message3(self):
        del(self.message.mailing['mailing_id'])
        with self.assertRaises(ex.NoMailingIdError):
            self.message.forward(["*****@*****.**"])
        self.assertEquals(self.message.mailing.account.adapter.called, 0)

    def test_can_forward_a_message4(self):
        self.message.member_id = None
        with self.assertRaises(ex.NoMemberIdError):
            self.message.forward(["*****@*****.**"])
        self.assertEquals(self.message.mailing.account.adapter.called, 0)

    def test_can_forward_a_message5(self):
        result = self.message.forward()
        self.assertEquals(self.message.mailing.account.adapter.called, 0)
        self.assertIsNone(result)

    def test_can_forward_a_message6(self):
        MockAdapter.expected = {'mailing_id': 2048}
        mailing_id = self.message.forward(["*****@*****.**"], "Test Note")
        self.assertEquals(self.message.mailing.account.adapter.called, 1)
        self.assertEquals(
            self.message.mailing.account.adapter.call,
            (
                'POST',
                '/forwards/200/1024',
                {
                    'recipient_emails':["*****@*****.**"],
                    'note': "Test Note"
                }))
        self.assertIsInstance(mailing_id, int)
        self.assertEquals(mailing_id, 2048)
コード例 #4
0
ファイル: message_test.py プロジェクト: ptomblin/EmmaPython
 def setUp(self):
     Account.default_adapter = MockAdapter
     self.message = Message(
         Mailing(
             Account(account_id="100", public_key="xxx", private_key="yyy"),
             {'mailing_id': 200}), 1024)