def test_reopen_orphaned_ml(self): initial_members = { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" } fake_db.create_ml("tenant1", 'ml-000010', "hoge", initial_members, "*****@*****.**") fake_db.change_ml_status('ml-000010', const.STATUS_ORPHANED, "*****@*****.**") msg = 'From: Test1 <*****@*****.**>\n' \ 'To: ml-000010 <*****@*****.**>, ' \ 'Test2 <*****@*****.**>\n' \ 'Subject: REOPEN\n' \ '\n' \ 'Test mail\n' final_members = { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" } with mock.patch.object(self.handler, 'send_post') as m: m.side_effect = self._send_post self.handler.process_message(("127.0.0.2", 1000), "*****@*****.**", ["*****@*****.**"], msg) self.assertEqual(self.ml_name_arg, 'ml-000010') self.assertEqual(fake_db.get_members('ml-000010'), final_members) ml = fake_db.get_ml('ml-000010') self.assertEqual(ml['status'], const.STATUS_OPEN)
def _test(self, old_status, new_status, days, altered): self.tenant_name = "tenant1" config = { "admins": set(), "charset": "iso-2022-jp", "ml_name_format": "ml-%06d", "new_ml_account": "new", "days_to_close": days, "days_to_orphan": days, "welcome_msg": "welcome_msg", "readme_msg": "readme_msg", "add_msg": "add_msg", "remove_msg": "remove_msg", "reopen_msg": "reopen_msg", "goodbye_msg": "goodbye_msg", "report_subject": "report_subject", "report_msg": "report_msg", "orphaned_subject": "orphaned_subject", "orphaned_msg": "orphaned_msg", "closed_subject": "closed_subject", "closed_msg": "closed_msg", } fake_db.create_tenant(self.tenant_name, "hoge", config) members = {"*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**"} fake_db.create_ml(self.tenant_name, 'ml-000010', "hoge", members, "*****@*****.**") if old_status: fake_db.change_ml_status('ml-000010', old_status, "xxx") from amane.cmd import reviewer self.reviewer = reviewer.Reviewer( relay_host="localhost", relay_port=1025, db_url="mongodb://localhost", db_name=self.db_name, domain="example.net", charset="iso-2022-jp") with mock.patch.object(self.reviewer, 'send_post') as m: m.side_effect = self._send_post self.reviewer.notify( const.STATUS_ORPHANED, const.STATUS_CLOSED) self.reviewer.notify( const.STATUS_OPEN, const.STATUS_ORPHANED) ret = fake_db.get_ml('ml-000010') self.assertEqual(ret['status'], new_status) if altered: self.assertEqual(m.call_count, 1) self.assertEqual(self.ml_name_arg, 'ml-000010') self.assertEqual(self.members_arg, members) else: self.assertEqual(m.call_count, 0)
def test_create_ml(self): msg = 'From: Test1 <*****@*****.**>\n' \ 'To: New mail <*****@*****.**>\n' \ 'Subject: Test message\n' \ '\n' \ 'Test mail\n' final_members = {"*****@*****.**"} with mock.patch.object(self.handler, 'send_post') as m: m.side_effect = self._send_post self.handler.process_message( ("127.0.0.2", 1000), "*****@*****.**", ["*****@*****.**"], msg) self.assertEqual(self.ml_name_arg, 'ml-000001') self.assertEqual(fake_db.get_members('ml-000001'), final_members) ml = fake_db.get_ml('ml-000001') self.assertEqual(ml['subject'], 'Test message')