Mercurial > libervia-backend
annotate tests/unit/test_email_gateway.py @ 4317:055930cc81f9
component email gateway: Add support for XEP-0131 headers:
Some email headers (`Keywords` and `Importance` for now) are converted between XMPP and
email.
rel 451
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Sep 2024 15:59:12 +0200 |
parents | d27228b3c704 |
children | 27bb22eace65 |
rev | line source |
---|---|
4310
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia: an XMPP client |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from email.utils import formataddr |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from unittest.mock import AsyncMock, MagicMock |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 import pytest |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from pytest_twisted import ensureDeferred as ed |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from twisted.words.protocols.jabber import jid |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from email.message import EmailMessage |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from libervia.backend.plugins.plugin_comp_email_gateway import EmailGatewayComponent |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from libervia.backend.plugins.plugin_comp_email_gateway.models import ( |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 Credentials, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 UserData, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 ) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 class TestEmailGatewayComponent: |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 @pytest.fixture |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 def email_gw(self, host): |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 email_gw = EmailGatewayComponent(host) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 email_gw.storage = MagicMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 email_gw.users_data = {} |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 return email_gw |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 def test_jid_to_email_gateway_jid(self, email_gw): |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 """JID from the gateway is converted to an email address.""" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 client = MagicMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 client.jid = jid.JID("gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 address_jid = jid.JID(r"user\40some-email-domain.example@gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 credentials = {"user_email": "user@example.org"} |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 result = email_gw.jid_to_email(client, address_jid, credentials) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 assert result == "user@some-email-domain.example" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 def test_jid_to_email_non_gateway_jid(self, email_gw): |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 """Non-gateway JID is converted to an email address with ``xmpp:``.""" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 client = MagicMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 client.jid = jid.JID("gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 address_jid = jid.JID("external@example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 credentials = {"user_email": "user@example.org"} |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 result = email_gw.jid_to_email(client, address_jid, credentials) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 assert result == '"xmpp:external@example.org" <user@example.org>' |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def test_email_to_jid_user_email(self, email_gw): |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 """User email returns user JID if no "xmpp:" scheme is used.""" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 client = MagicMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 client.jid = jid.JID("gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 email_name = "" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 email_addr = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 user_email = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 user_jid = jid.JID("gw-user@example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 result, name = email_gw.email_to_jid( |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 client, user_email, user_jid, email_name, email_addr |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 ) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 assert result == jid.JID("gw-user@example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 assert name is None |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 def test_email_to_jid_xmpp_address(self, email_gw): |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 """Email address with XMPP in name part is converted to a JID.""" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 client = MagicMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 client.jid = jid.JID("gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 email_name = "xmpp:user@example.net" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 email_addr = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 user_email = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 user_jid = jid.JID("gw-user@example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 result, name = email_gw.email_to_jid( |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 client, user_email, user_jid, email_name, email_addr |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 ) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 assert result == jid.JID("user@example.net") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 assert name is None |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 def test_email_to_jid_regular_email(self, email_gw): |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 """Regular email address is converted to a JID with escaped local part.""" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 client = MagicMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 client.jid = jid.JID("gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 email_name = "User Name" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 email_addr = "user@some-email-domain.example" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 user_email = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 user_jid = jid.JID("gw-user@example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 result, name = email_gw.email_to_jid( |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 client, user_email, user_jid, email_name, email_addr |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 ) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 assert result == jid.JID(r"user\40some-email-domain.example@gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 assert name == "User Name" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 @ed |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 async def test_on_new_email_single_recipient(self, email_gw): |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 """Email with a single recipient is correctly processed and sent as a message.""" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 client = MagicMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 client.get_virtual_client = lambda __: client |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 client.jid = jid.JID("gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 client.sendMessage = AsyncMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 email_gw.client = client |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 email = EmailMessage() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 email["from"] = formataddr(("User Name", "sender@somewhere.example")) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 email["to"] = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 email.set_content("Hello, world!") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 to_jid = jid.JID("gw-user@example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 user_email = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 user_data = UserData(Credentials({"user_email": user_email})) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 await email_gw.on_new_email(user_data, to_jid, email) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 client.sendMessage.assert_called_once() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 call_args = client.sendMessage.call_args[0] |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 assert call_args[0] == to_jid |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 assert call_args[1] == {"": "Hello, world!\n"} |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 assert call_args[2] == None |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 client.sendMessage.assert_called_once_with( |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 to_jid, {"": "Hello, world!\n"}, None, extra=None |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 ) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 @ed |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 async def test_on_new_email_multiple_recipients(self, email_gw): |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 """Email with multiple recipients is correctly processed and sent .""" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 client = MagicMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 client.get_virtual_client = lambda __: client |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 client.jid = jid.JID("gateway.example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 client.sendMessage = AsyncMock() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 email_gw.client = client |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 email = EmailMessage() |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 email["from"] = formataddr(("User Name", "user@example.org")) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 email["to"] = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 email["cc"] = "recipient2@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 email["bcc"] = "recipient3@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 email.set_content("Hello, world!") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 user_jid = jid.JID("gw-user@example.org") |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 user_email = "user@example.org" |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 user_data = UserData(Credentials({"user_email": user_email})) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 await email_gw.on_new_email(user_data, user_jid, email) |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 client.sendMessage.assert_called_once_with( |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 user_jid, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 {"": "Hello, world!\n"}, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 None, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 extra={ |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 "addresses": { |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 "to": [{"jid": "gw-user@example.org", "delivered": True}], |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 "cc": [ |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 { |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 "jid": "recipient2\\40example.org@gateway.example.org", |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 "delivered": True, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 } |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 ], |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 "bcc": [ |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 { |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 "jid": "recipient3\\40example.org@gateway.example.org", |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 "delivered": True, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 } |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 ], |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 } |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 }, |
d27228b3c704
test (unit): add test for email gateway:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 ) |