class TestConfirm(unittest.TestCase): """Test the `confirm` command.""" layer = ConfigLayer def setUp(self): self._mlist = create_list("*****@*****.**") anne = getUtility(IUserManager).create_address("*****@*****.**", "Anne Person") self._token, token_owner, member = IRegistrar(self._mlist).register(anne) self._command = Confirm() # Clear the virgin queue. get_queue_messages("virgin") def test_welcome_message(self): # A confirmation causes a welcome message to be sent to the member, if # enabled by the mailing list. status = self._command.process(self._mlist, Message(), {}, (self._token,), Results()) self.assertEqual(status, ContinueProcessing.yes) # There should be one messages in the queue; the welcome message. messages = get_queue_messages("virgin") self.assertEqual(len(messages), 1) # Grab the welcome message. welcome = messages[0].msg self.assertEqual(welcome["subject"], 'Welcome to the "Test" mailing list') self.assertEqual(welcome["to"], "Anne Person <*****@*****.**>") def test_no_welcome_message(self): # When configured not to send a welcome message, none is sent. self._mlist.send_welcome_message = False status = self._command.process(self._mlist, Message(), {}, (self._token,), Results()) self.assertEqual(status, ContinueProcessing.yes) # There will be no messages in the queue. messages = get_queue_messages("virgin") self.assertEqual(len(messages), 0)
class TestConfirmJoin(unittest.TestCase): """Test the `confirm` command when joining a mailing list.""" layer = ConfigLayer def setUp(self): self._mlist = create_list('*****@*****.**') anne = getUtility(IUserManager).create_address('*****@*****.**', 'Anne Person') self._token, token_owner, member = ISubscriptionManager( self._mlist).register(anne) self._command = Confirm() # Clear the virgin queue. get_queue_messages('virgin') def test_welcome_message(self): # A confirmation causes a welcome message to be sent to the member, if # enabled by the mailing list. status = self._command.process(self._mlist, Message(), {}, (self._token, ), Results()) self.assertEqual(status, ContinueProcessing.no) # There should be one messages in the queue; the welcome message. items = get_queue_messages('virgin', expected_count=1) # Grab the welcome message. welcome = items[0].msg self.assertEqual(welcome['subject'], 'Welcome to the "Test" mailing list') self.assertEqual(welcome['to'], 'Anne Person <*****@*****.**>') def test_no_welcome_message(self): # When configured not to send a welcome message, none is sent. self._mlist.send_welcome_message = False status = self._command.process(self._mlist, Message(), {}, (self._token, ), Results()) self.assertEqual(status, ContinueProcessing.no) # There will be no messages in the queue. get_queue_messages('virgin', expected_count=0) def test_confim_token_twice(self): # Don't try to confirm the same token twice. # We test this by passing a result that already confirms the same # token and it doesn't try to look at the database. result = Results() result.confirms = self._token status = self._command.process(self._mlist, Message(), {}, (self._token, ), result) self.assertEqual(status, ContinueProcessing.no)
class TestConfirm(unittest.TestCase): """Test the `confirm` command.""" layer = ConfigLayer def setUp(self): self._mlist = create_list('*****@*****.**') self._token = getUtility(IRegistrar).register(self._mlist, '*****@*****.**', 'Anne Person') self._command = Confirm() # Clear the virgin queue. get_queue_messages('virgin') def tearDown(self): reset_the_world() def test_welcome_message(self): # A confirmation causes a welcome message to be sent to the member, if # enabled by the mailing list. status = self._command.process(self._mlist, Message(), {}, (self._token, ), Results()) self.assertEqual(status, ContinueProcessing.yes) # There should be one messages in the queue; the welcome message. messages = get_queue_messages('virgin') self.assertEqual(len(messages), 1) # Grab the welcome message. welcome = messages[0].msg self.assertEqual(welcome['subject'], 'Welcome to the "Test" mailing list') self.assertEqual(welcome['to'], 'Anne Person <*****@*****.**>') def test_no_welcome_message(self): # When configured not to send a welcome message, none is sent. self._mlist.send_welcome_message = False status = self._command.process(self._mlist, Message(), {}, (self._token, ), Results()) self.assertEqual(status, ContinueProcessing.yes) # There will be no messages in the queue. messages = get_queue_messages('virgin') self.assertEqual(len(messages), 0)
class TestConfirm(unittest.TestCase): """Test the `confirm` command.""" layer = ConfigLayer def setUp(self): self._mlist = create_list('*****@*****.**') self._token = getUtility(IRegistrar).register( self._mlist, '*****@*****.**', 'Anne Person') self._command = Confirm() # Clear the virgin queue. get_queue_messages('virgin') def tearDown(self): reset_the_world() def test_welcome_message(self): # A confirmation causes a welcome message to be sent to the member, if # enabled by the mailing list. status = self._command.process( self._mlist, Message(), {}, (self._token,), Results()) self.assertEqual(status, ContinueProcessing.yes) # There should be one messages in the queue; the welcome message. messages = get_queue_messages('virgin') self.assertEqual(len(messages), 1) # Grab the welcome message. welcome = messages[0].msg self.assertEqual(welcome['subject'], 'Welcome to the "Test" mailing list') self.assertEqual(welcome['to'], 'Anne Person <*****@*****.**>') def test_no_welcome_message(self): # When configured not to send a welcome message, none is sent. self._mlist.send_welcome_message = False status = self._command.process( self._mlist, Message(), {}, (self._token,), Results()) self.assertEqual(status, ContinueProcessing.yes) # There will be no messages in the queue. messages = get_queue_messages('virgin') self.assertEqual(len(messages), 0)