def test_50_notify_again_with_old_notify_values(self, mock_smtp, mock_run, mock_stderr): self.addUser(expire=35, mail=True, notified=(-178,7)) # call tool one time rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 1) # 7 days and a bit later rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--time', ldap_time(days=7, hours=1)]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) self.assertEqual(SMTP.sendmail.call_count, 3)
def test_15_sends_correct_html_user_emails(self, mock_smtp, mock_run, mock_stderr): self.addUser(name='expired_3', fullName="Alice", expire=3, mail=True) self.addUser(name='expired_12', expire=12, mail=True) # rule 14 has a html template self.addUser(name='no_mail', expire=3, mail=None) self.addUser(name='not_expired', expire=43, mail=True) self.addUser(name='no_grace', expire=3, mail=True, grace=0) self.addUser(name='disabled', expire=3, mail=True, disabled=True) # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # emails to the right addresses? SMTP = mock_smtp.return_value (config, ), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 3) # check only expiry_12 user args = SMTP.sendmail.mock_calls[1][1] self.assertEqual(args[0], config.admin.from_address) self.assertEqual(args[1], 'expired_12@localhost') lines = args[2].split('\n') self.assertIn('Content-Type: text/html; charset="utf-8"', lines) self.assertGrep( r"^From: %s <%s>$" % (config.rules[3].from_text.replace( '$Object', '.*'), config.admin.from_address), lines) self.assertIn('To: %s' % 'expired_12@localhost', lines) # we also have a text mime part self.assertIn('Content-Type: text/plain; charset="utf-8"', lines)
def test_15_sends_correct_html_user_emails(self, mock_smtp, mock_run, mock_stderr): self.addUser(name='expired_3', fullName="Alice", expire=3, mail=True) self.addUser(name='expired_12', expire=12, mail=True) # rule 14 has a html template self.addUser(name='no_mail', expire=3, mail=None) self.addUser(name='not_expired', expire=43, mail=True) self.addUser(name='no_grace', expire=3, mail=True, grace=0) self.addUser(name='disabled', expire=3, mail=True, disabled=True) # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # emails to the right addresses? SMTP = mock_smtp.return_value (config,), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 3) # check only expiry_12 user args = SMTP.sendmail.mock_calls[1][1] self.assertEqual(args[0], config.admin.from_address) self.assertEqual(args[1], 'expired_12@localhost') lines = args[2].split('\n') self.assertIn('Content-Type: text/html; charset="utf-8"', lines) self.assertGrep(r"^From: %s <%s>$" % (config.rules[3].from_text.replace('$Object', '.*'), config.admin.from_address), lines) self.assertIn('To: %s' % 'expired_12@localhost', lines) # we also have a text mime part self.assertIn('Content-Type: text/plain; charset="utf-8"', lines)
def test_30_restricted_users_are_case_insentive(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) self.addUser(expire=23, mail=True, name="myTestUser") self.addUser(expire=23, mail=True, name="mySeCONDTestUser") # call tool rc = main([ '-c', os.path.dirname(__file__) + "/password.conf", '--restrict', 'myTESTUSER;CN=mysecondTESTuser,OU=users,DC=LOCALHOST' ]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # only admin report and mail to the mytestuser SMTP = mock_smtp.return_value (config, ), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 3) self.assertEqual(map(lambda x: x[1][1], SMTP.sendmail.mock_calls), [ 'myTestUser@localhost', 'mySeCONDTestUser@localhost', config.admin.to_address ])
def test_10_sends_correct_admin_email(self, mock_smtp, mock_run, mock_stderr): self.addUser(name='expired_3', expire=3, mail=True) self.addUser(name='expired_23', expire=3, mail=True) self.addUser(name='no_mail', expire=3, mail=None) self.addUser(name='not_expired', expire=43, mail=True) self.addUser(name='no_grace', expire=3, mail=True, grace=0) self.addUser(name='no_grace_no_expiry', expire=None, mail=True, grace=0) self.addUser(name='disabled', expire=3, mail=True, disabled=True) # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # emails to the right addresses? SMTP = mock_smtp.return_value (config,), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 3) self.assertEqual(map(lambda x: x[1][1], SMTP.sendmail.mock_calls), ['expired_3@localhost', 'expired_23@localhost', config.admin.to_address]) # admin email content correct? args = SMTP.sendmail.mock_calls[-1][1] self.assertEqual(args[0], config.admin.from_address) self.assertEqual(args[1], config.admin.to_address) lines = args[2].split('\n') self.assertIn('Content-Type: text/plain; charset="utf-8"', lines) self.assertGrep(r"^Subject: %s$" % (config.admin.subject.replace('$Object', '.*')), lines) self.assertGrep(r"^From: %s <%s>$" % (config.admin.from_text.replace('$Object', '.*'), config.admin.from_address), lines) self.assertIn('To: %s' % config.admin.to_address, lines) self.assertGrep(r"Without grace logins: *2$", lines) self.assertGrep(r"^Without email: *1$", lines) self.assertGrep(r'^Failed: *0$', lines) self.assertGrep(r'^Notified: *2$', lines)
def test_40_sends_no_admin_mail_in_dry_mode(self, mock_smtp, mock_run, mock_stderr): rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--dry']) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertFalse(SMTP.sendmail.called)
def test_10_sends_correct_user_emails(self, mock_smtp, mock_run, mock_stderr): self.addUser(name='expired_3', fullName="Alice", expire=3, mail=True) self.addUser(name='expired_23', expire=23, mail=True) self.addUser(name='no_mail', expire=3, mail=None) self.addUser(name='not_expired', expire=43, mail=True) self.addUser(name='no_grace', expire=3, mail=True, grace=0) self.addUser(name='disabled', expire=3, mail=True, disabled=True) # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # emails to the right addresses? SMTP = mock_smtp.return_value (config,), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 3) user_mails = ['expired_3@localhost', 'expired_23@localhost'] user_fullNames = ['Alice', 'expired_23'] user_days = [3, 23] user_rule = [2, 4] self.assertEqual(map(lambda x: x[1][1], SMTP.sendmail.mock_calls)[:2], user_mails) for i in range(2): args = SMTP.sendmail.mock_calls[i][1] self.assertEqual(args[0], config.admin.from_address) self.assertEqual(args[1], user_mails[i]) lines = args[2].split('\n') self.assertIn('Content-Type: text/plain; charset="utf-8"', lines) self.assertGrep(r"^From: %s <%s>$" % (config.rules[user_rule[i]].from_text.replace('$Object', '.*'), config.admin.from_address), lines) self.assertIn('To: %s' % user_mails[i], lines) self.assertIn('Dear %s,' % user_fullNames[i], lines) self.assertGrep(r'3 logins left', lines) self.assertGrep(r'within %i days' % user_days[i], lines)
def test_80_handles_users_without_grace_login_attribute(self, mock_smtp, mock_run, mock_stderr): self.addUser(expire=11, mail=True, grace=2) self.addUser(expire=23, mail=True, grace=None) # call tool one time rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 3)
def test_15_finds_expired_users_in_all_base_contexts(self, mock_smtp, mock_run, mock_stderr): self.addUser(name='lazyadmin', expire=12, mail=True, ou='ou=admins,dc=localhost') self.addUser(name='lostadmin', expire=12, mail=True, ou='ou=nirvana,dc=localhost') rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 2)
def test_40_notifies_again_after_smtp_error(self, mock_smtp, mock_run, mock_stderr): self.addUser(expire=23, mail=True) # refuse SMTP connection import smtplib mock_smtp.side_effect = smtplib.SMTPConnectError(42, 'Connection refused') # call tool one time rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), "SMTP error: (42, 'Connection refused')\n") self.assertEqual(rc, 1) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 0) # 7 days and a bit later without SMTP problems mock_smtp.side_effect = None rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--time', ldap_time(hours=1)]) self.assertEqual(rc, 0) self.assertEqual(SMTP.sendmail.call_count, 2)
def test_30_sends_admin_report(self, mock_smtp, mock_run, mock_stderr): rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 1) (config,), _ = mock_run.call_args sendmail_args, _ = SMTP.sendmail.call_args self.assertEqual(sendmail_args[:2], (config.admin.from_address, config.admin.to_address))
def test_60_does_not_sends_users_mails_in_dry_mode(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) # call tool one time rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--dry']) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 0)
def test_30_notify_again_when_time_passes(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) # call tool one time rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 6) # call tool a second time, second server an hour later rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--time', ldap_time(hours=1)]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) self.assertEqual(SMTP.sendmail.call_count, 7) # a day and a bit later: # - user 2 => rule 1 appies now rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--time', ldap_time(days=1, hours=1)]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) self.assertEqual(SMTP.sendmail.call_count, 9) # 2 days and a bit later: # - user 5 => rule 3 appies now # - user 9 => rule 7 applies now rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--time', ldap_time(days=2, hours=1)]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) self.assertEqual(SMTP.sendmail.call_count, 12) # 6 days and a bit later: # - user 9 => rule 3 appies now # - user 20 => rule 14 applies now # - user 35 => rule 30 applies now rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--time', ldap_time(days=6, hours=1)]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) self.assertEqual(SMTP.sendmail.call_count, 16)
def test_20_sends_notification_only_once(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) # call tool one time rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # 7 mails as before SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 6) # call tool a second time rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # only the admin report, the other user were notified before self.assertEqual(SMTP.sendmail.call_count, 7)
def test_60_ignores_disabled_users(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) self.addUser(expire=23, mail=True, disabled=True) # call tool one time rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 6)
def test_10_finds_expired_users(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # mails to all but -2 and 35 + admin report SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 6)
def test_50_sends_admin_report_in_test_mode(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--test', 'tester@localhost']) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # only mails to tester@localhost SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 6) self.assertEqual(set(map(lambda x: x[1][1], SMTP.sendmail.mock_calls)), set(['tester@localhost']))
def test_70_does_not_send_mails_for_users_without_mail(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True if days!=9 else False) self.addUser(expire=23, mail=False) # call tool one time rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 5)
def test_20_only_sends_to_restricted_users_with_dn(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) self.addUser(expire=23, mail=True, name="mytestuser") # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--restrict', 'cn=mytestuser,ou=users,dc=localhost']) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # only admin report and mail to the mytestuser SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 2)
def test_10_only_sends_to_restricted_users(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) self.addUser(expire=23, mail=True, name="mytestuser") # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--restrict', 'mytestuser']) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # only admin report and mail to the mytestuser SMTP = mock_smtp.return_value (config,), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 2) self.assertEqual(map(lambda x: x[1][1], SMTP.sendmail.mock_calls), ['mytestuser@localhost', config.admin.to_address])
def test_18_finds_expired_users_with_a_subtree_root_search(self, mock_smtp, mock_run, mock_stderr): self.addUser(name='lazyadmin', expire=12, mail=True, ou='ou=admins,dc=localhost') self.addUser(name='lostadmin', expire=12, mail=True, ou='ou=nirvana,dc=localhost') self.addUser(expire=3, mail=True) original_evaluate = ldap_notify.config.evaluate class setup_subtree_search: def __call__(self, preconfig): preconfig.set('common', 'base_dn', '') return original_evaluate(preconfig) with patch('ldap_notify.config.evaluate', new_callable=setup_subtree_search): rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 4)
def test_10_sends_correct_admin_email(self, mock_smtp, mock_run, mock_stderr): self.addUser(name='expired_3', expire=3, mail=True) self.addUser(name='expired_23', expire=3, mail=True) self.addUser(name='no_mail', expire=3, mail=None) self.addUser(name='not_expired', expire=43, mail=True) self.addUser(name='no_grace', expire=3, mail=True, grace=0) self.addUser(name='no_grace_no_expiry', expire=None, mail=True, grace=0) self.addUser(name='disabled', expire=3, mail=True, disabled=True) # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # emails to the right addresses? SMTP = mock_smtp.return_value (config, ), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 3) self.assertEqual(map(lambda x: x[1][1], SMTP.sendmail.mock_calls), [ 'expired_3@localhost', 'expired_23@localhost', config.admin.to_address ]) # admin email content correct? args = SMTP.sendmail.mock_calls[-1][1] self.assertEqual(args[0], config.admin.from_address) self.assertEqual(args[1], config.admin.to_address) lines = args[2].split('\n') self.assertIn('Content-Type: text/plain; charset="utf-8"', lines) self.assertGrep( r"^Subject: %s$" % (config.admin.subject.replace('$Object', '.*')), lines) self.assertGrep( r"^From: %s <%s>$" % (config.admin.from_text.replace( '$Object', '.*'), config.admin.from_address), lines) self.assertIn('To: %s' % config.admin.to_address, lines) self.assertGrep(r"Without grace logins: *2$", lines) self.assertGrep(r"^Without email: *1$", lines) self.assertGrep(r'^Failed: *0$', lines) self.assertGrep(r'^Notified: *2$', lines)
def test_30_restricted_users_are_case_insentive(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) self.addUser(expire=23, mail=True, name="myTestUser") self.addUser(expire=23, mail=True, name="mySeCONDTestUser") # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--restrict', 'myTESTUSER;CN=mysecondTESTuser,OU=users,DC=LOCALHOST']) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # only admin report and mail to the mytestuser SMTP = mock_smtp.return_value (config,), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 3) self.assertEqual(map(lambda x: x[1][1], SMTP.sendmail.mock_calls), ['myTestUser@localhost', 'mySeCONDTestUser@localhost', config.admin.to_address])
def test_20_only_sends_to_restricted_users_with_dn(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) self.addUser(expire=23, mail=True, name="mytestuser") # call tool rc = main([ '-c', os.path.dirname(__file__) + "/password.conf", '--restrict', 'cn=mytestuser,ou=users,dc=localhost' ]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # only admin report and mail to the mytestuser SMTP = mock_smtp.return_value self.assertEqual(SMTP.sendmail.call_count, 2)
def test_10_sends_correct_user_emails(self, mock_smtp, mock_run, mock_stderr): self.addUser(name='expired_3', fullName="Alice", expire=3, mail=True) self.addUser(name='expired_23', expire=23, mail=True) self.addUser(name='no_mail', expire=3, mail=None) self.addUser(name='not_expired', expire=43, mail=True) self.addUser(name='no_grace', expire=3, mail=True, grace=0) self.addUser(name='disabled', expire=3, mail=True, disabled=True) # call tool rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # emails to the right addresses? SMTP = mock_smtp.return_value (config, ), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 3) user_mails = ['expired_3@localhost', 'expired_23@localhost'] user_fullNames = ['Alice', 'expired_23'] user_days = [3, 23] user_rule = [2, 4] self.assertEqual( map(lambda x: x[1][1], SMTP.sendmail.mock_calls)[:2], user_mails) for i in range(2): args = SMTP.sendmail.mock_calls[i][1] self.assertEqual(args[0], config.admin.from_address) self.assertEqual(args[1], user_mails[i]) lines = args[2].split('\n') self.assertIn('Content-Type: text/plain; charset="utf-8"', lines) self.assertGrep( r"^From: %s <%s>$" % (config.rules[user_rule[i]].from_text.replace( '$Object', '.*'), config.admin.from_address), lines) self.assertIn('To: %s' % user_mails[i], lines) self.assertIn('Dear %s,' % user_fullNames[i], lines) self.assertGrep(r'3 logins left', lines) self.assertGrep(r'within %i days' % user_days[i], lines)
def test_10_only_sends_to_restricted_users(self, mock_smtp, mock_run, mock_stderr): # prepare users for days in [-2, 0.5, 2, 5, 9, 20, 35]: self.addUser(expire=days, mail=True) self.addUser(expire=23, mail=True, name="mytestuser") # call tool rc = main([ '-c', os.path.dirname(__file__) + "/password.conf", '--restrict', 'mytestuser' ]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) # only admin report and mail to the mytestuser SMTP = mock_smtp.return_value (config, ), _ = mock_run.call_args self.assertEqual(SMTP.sendmail.call_count, 2) self.assertEqual(map(lambda x: x[1][1], SMTP.sendmail.mock_calls), ['mytestuser@localhost', config.admin.to_address])
def test_20_connect_without_tls(self, mock_smtp, mock_stderr): rc = main(['-c', os.path.dirname(__file__) + "/password.conf"]) self.assertEqual(mock_stderr.getvalue(), '') self.assertEqual(rc, 0) self.assertTrue(self.ldapobj.methods_called() >= ['initialize', 'simple_bind_s', 'search_s'], self.ldapobj.methods_called())