test that email is sent when user is created

pull/22/head
Max Erenberg 1 year ago
parent 749ca41080
commit 3cba9680f5
  1. 2
      ceod/model/MailService.py
  2. 2
      tests/MockSMTPServer.py
  3. 11
      tests/ceod/api/test_members.py
  4. 1
      tests/conftest.py

@ -69,7 +69,7 @@ class MailService:
if '@' in auth_user:
auth_user = auth_user[:auth_user.index('@')]
if user.is_club():
if user.terms:
prog = 'addclubrep'
desc = 'Club Rep'
else:

@ -23,7 +23,7 @@ class MockHandler:
async def handle_DATA(self, server, session, envelope):
msg = {
'from': envelope.mail_from,
'to': envelope.rcpt_tos[0],
'to': ','.join(envelope.rcpt_tos),
'content': envelope.content.decode(),
}
self.mock_server.messages.append(msg)

@ -12,7 +12,8 @@ def test_api_user_not_found(client):
@pytest.fixture(scope='module')
def create_user_resp(client, mocks_for_create_user):
def create_user_resp(client, mocks_for_create_user, mock_mail_server):
mock_mail_server.messages.clear()
status, data = client.post('/api/members', json={
'uid': 'test_1',
'cn': 'Test One',
@ -35,7 +36,7 @@ def create_user_result(create_user_resp):
return data[-1]['result']
def test_api_create_user(cfg, create_user_resp):
def test_api_create_user(cfg, create_user_resp, mock_mail_server):
_, data = create_user_resp
min_uid = cfg.get('members_min_id')
expected = [
@ -62,6 +63,12 @@ def test_api_create_user(cfg, create_user_resp):
}},
]
assert data == expected
# Two messages should have been sent: a welcome message to the new member,
# and an announcement to the ceo mailing list
assert len(mock_mail_server.messages) == 2
assert mock_mail_server.messages[0]['to'] == 'test_1@csclub.internal'
assert mock_mail_server.messages[1]['to'] == 'ceo@csclub.internal,ctdalek@csclub.internal'
mock_mail_server.messages.clear()
def test_api_next_uid(cfg, client, create_user_result):

@ -208,7 +208,6 @@ def mock_mailman_server():
@pytest.fixture(scope='session')
def mailman_srv(mock_mailman_server, cfg, http_client):
# TODO: test the RemoteMailmanService as well
mailman = MailmanService()
component.getGlobalSiteManager().registerUtility(mailman, IMailmanService)
return mailman

Loading…
Cancel
Save