Ejemplo n.º 1
0
    async def test_decode_template_on_loading(self):
        subject = u'This is a täßϑ subject.'
        to = u'*****@*****.**'
        _from = u'*****@*****.**'
        body = u'Body\n地初店会継思識棋御招告外児山望掲領環。\n€mail body €nd.'
        with tempfile.NamedTemporaryFile('wb', delete=False) as f:
            txt = u'Subject: {}\nTo: {}\nFrom: {}\n{}'.format(
                subject, to, _from, body)
            f.write(txt.encode('utf-8'))
        self.addCleanup(os.unlink, f.name)

        cmd = g_commands.ComposeCommand(template=f.name)

        # Crutch to exit the giant `apply` method early.
        with mock.patch(
                'alot.commands.globals.settings.get_account_by_address',
                mock.Mock(side_effect=Stop)):
            try:
                await cmd.apply(mock.Mock())
            except Stop:
                pass

        self.assertEqual({
            'To': [to],
            'From': [_from],
            'Subject': [subject]
        }, cmd.envelope.headers)
        self.assertEqual(body, cmd.envelope.body)
Ejemplo n.º 2
0
    def test_set_gpg_sign_by_default_but_no_key(self):
        envelope = self._make_envelope_mock()
        envelope.account = self._make_account_mock(gpg_key=None)
        cmd = g_commands.ComposeCommand(envelope=envelope)

        cmd._set_gpg_sign(mock.Mock())

        self.assertFalse(envelope.sign)
        self.assertIs(envelope.sign_key, None)
Ejemplo n.º 3
0
    def test_set_gpg_sign_by_default_okay(self):
        envelope = self._make_envelope_mock()
        envelope.account = self._make_account_mock()
        cmd = g_commands.ComposeCommand(envelope=envelope)

        cmd._set_gpg_sign(mock.Mock())

        self.assertTrue(envelope.sign)
        self.assertIs(envelope.sign_key, mock.sentinel.gpg_key)
Ejemplo n.º 4
0
    async def test_apply_sign_by_default_but_no_key(self):
        envelope = self._make_envelope_mock()
        envelope.account = self._make_account_mock(gpg_key=None)
        cmd = g_commands.ComposeCommand(envelope=envelope)

        with mock.patch('alot.commands.globals.settings.get_addressbooks',
                        mock.Mock(side_effect=Stop)):
            try:
                await cmd.apply(mock.Mock())
            except Stop:
                pass

        self.assertFalse(envelope.sign)
        self.assertIs(envelope.sign_key, None)
Ejemplo n.º 5
0
    async def test_single_account_no_from(self):
        # issue #1277
        envelope = self._make_envelope_mock()
        del envelope.headers['From']
        envelope.account = self._make_account_mock()
        envelope.account.realname = "foo"
        envelope.account.address = 1  # maybe this should be a real Address?
        cmd = g_commands.ComposeCommand(envelope=envelope)

        with mock.patch('alot.commands.globals.settings.get_addressbooks',
                        mock.Mock(side_effect=Stop)):
            try:
                await cmd.apply(mock.Mock())
            except Stop:
                pass
Ejemplo n.º 6
0
    def test_get_template_decode(self):
        subject = 'This is a täßϑ subject.'
        to = '*****@*****.**'
        _from = '*****@*****.**'
        body = 'Body\n地初店会継思識棋御招告外児山望掲領環。\n€mail body €nd.'
        with tempfile.NamedTemporaryFile('wb', delete=False) as f:
            txt = 'Subject: {}\nTo: {}\nFrom: {}\n{}'.format(subject, to,
                                                              _from, body)
            f.write(txt.encode('utf-8'))
        self.addCleanup(os.unlink, f.name)

        cmd = g_commands.ComposeCommand(template=f.name)
        cmd._set_envelope()
        cmd._get_template(mock.Mock())

        self.assertEqual({'To': [to],
                          'From': [_from],
                          'Subject': [subject]}, cmd.envelope.headers)
        self.assertEqual(body, cmd.envelope.body_txt)
Ejemplo n.º 7
0
    def test_apply_sign_by_default_false_doesnt_set_key(self):
        envelope = self._make_envelope_mock()
        account = self._make_account_mock(sign_by_default=False)
        cmd = g_commands.ComposeCommand(envelope=envelope)

        # This whole mess is required becasue ComposeCommand.apply is waaaaay
        # too complicated, it needs to be split into more manageable segments.
        with mock.patch(
                'alot.commands.globals.settings.get_account_by_address',
                mock.Mock(return_value=account)):
            with mock.patch('alot.commands.globals.settings.get_accounts',
                            mock.Mock(return_value=[account])):
                with mock.patch(
                        'alot.commands.globals.settings.get_addressbooks',
                        mock.Mock(side_effect=Stop)):
                    try:
                        yield cmd.apply(mock.Mock())
                    except Stop:
                        pass

        self.assertFalse(envelope.sign)
        self.assertIs(envelope.sign_key, None)
Ejemplo n.º 8
0
    async def test_single_account_no_from(self):
        # issue #1277
        envelope = self._make_envelope_mock()
        del envelope.headers['From']
        account = self._make_account_mock()
        account.realname = "foo"
        account.address = 1  # maybe this should be a real Address?
        cmd = g_commands.ComposeCommand(envelope=envelope)

        # This whole mess is required becasue ComposeCommand.apply is waaaaay
        # too complicated, it needs to be split into more manageable segments.
        with mock.patch(
                'alot.commands.globals.settings.get_account_by_address',
                mock.Mock(return_value=account)):
            with mock.patch('alot.commands.globals.settings.get_accounts',
                            mock.Mock(return_value=[account])):
                with mock.patch(
                        'alot.commands.globals.settings.get_addressbooks',
                        mock.Mock(side_effect=Stop)):
                    try:
                        await cmd.apply(mock.Mock())
                    except Stop:
                        pass