示例#1
0
    def test_smtp_config_host_and_port_not_set(self):
        temp_dir = tempfile.mkdtemp()
        try:

            cfile = os.path.join(temp_dir, 'foo')
            con = configparser.ConfigParser()
            con.add_section(SmtpConfig.DEFAULT)
            con.set(SmtpConfig.DEFAULT, SmtpConfig.SMTP_FROM_ADDRESS, 'from')
            con.set(SmtpConfig.DEFAULT, SmtpConfig.SMTP_REPLYTO_ADDRESS,
                    'replyto')
            con.set(SmtpConfig.DEFAULT, SmtpConfig.SMTP_PASS, 'pass')
            f = open(cfile, 'w')
            con.write(f)
            f.flush()
            f.close()

            smtpconfig = SmtpConfig(configfile=cfile)
            self.assertEqual(smtpconfig.get_user(), None)
            self.assertEqual(smtpconfig.get_host(), 'localhost')
            self.assertEqual(smtpconfig.get_port(), 25)
            self.assertEqual(smtpconfig.get_password(), 'pass')
            self.assertEqual(smtpconfig.get_from_address(), 'from')
            self.assertEqual(smtpconfig.get_replyto_address(), 'replyto')
        finally:
            shutil.rmtree(temp_dir)
示例#2
0
 def test_smtp_config_noconfig(self):
     smtpconfig = SmtpConfig()
     self.assertEqual(smtpconfig.get_from_address(), None)
     self.assertEqual(smtpconfig.get_host(), 'localhost')
     self.assertEqual(smtpconfig.get_port(), 25)
     self.assertEqual(smtpconfig.get_password(), None)
     self.assertEqual(smtpconfig.get_from_address(), None)
     self.assertEqual(smtpconfig.get_replyto_address(), None)
示例#3
0
 def test_smtp_config_parse_error(self):
     temp_dir = tempfile.mkdtemp()
     try:
         cfile = os.path.join(temp_dir, 'foo')
         f = open(cfile, 'w')
         f.write('[smtp\nas = xx=12=\n')
         f.flush()
         f.close()
         # this is a coverage test. Basically the
         # _parse_config method called from constructor
         # below should catch the parsing error and
         # not complain
         smtpconfig = SmtpConfig(cfile)
         self.assertEqual(smtpconfig.get_from_address(), None)
         self.assertEqual(smtpconfig.get_host(), 'localhost')
         self.assertEqual(smtpconfig.get_port(), 25)
         self.assertEqual(smtpconfig.get_password(), None)
         self.assertEqual(smtpconfig.get_from_address(), None)
         self.assertEqual(smtpconfig.get_replyto_address(), None)
     finally:
         shutil.rmtree(temp_dir)