Example #1
0
    def test_to_yaml_without_defaults(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        console:
            email:
                host: 127.0.0.1
                port: 80
                username: emailuser
                password: emailpassword
        """, ConsoleConfiguration(), ".")

        client_config = yaml.get_section("console")

        email_config = EmailConfiguration()
        email_config.load_config_section(yaml, client_config, ".")

        data = {}
        email_config.to_yaml(data, defaults=False)
        self.assertEquals(
            {
                'from_addr': 'emailuser',
                'host': '127.0.0.1',
                'password': '******',
                'port': 80,
                'username': '******'
            }, data)
Example #2
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        console:
            email:
                host: 127.0.0.1
                port: 80
                username: emailuser
                password: emailpassword
                from_addr: emailfromuser
        """, ConsoleConfiguration(), ".")

        client_config = yaml.get_section("console")

        email_config = EmailConfiguration()
        email_config.load_config_section(yaml, client_config, ".")

        license_keys = LicenseKeys()
        email_config.check_for_license_keys(license_keys)

        self.assertEqual("127.0.0.1", email_config.host)
        self.assertEqual(80, email_config.port)
        self.assertEqual("emailuser", email_config.username)
        self.assertEqual("emailpassword", email_config.password)
        self.assertEqual("emailfromuser", email_config.from_addr)
Example #3
0
    def test_send(self):

        config = EmailConfiguration()

        sender = EmailSender(config)

        sender.send("*****@*****.**", "New patio",
                    "Do you need any help with the slabs?")
Example #4
0
    def test_get_ctype_and_attachment(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80))

        attachment = os.path.dirname(__file__) + os.sep + "test.txt"

        sender._get_ctype_and_attachment(attachment, "utf-8")
Example #5
0
    def test_send_message_with_unknown_file_attachment(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80))

        attachment = os.path.dirname(__file__) + os.sep + "unknown.???"

        sender.send("*****@*****.**", "New patio", "Do you need any help with the slabs?", [attachment])

        self.assertFalse(sender.mock_sender.did_ehlo)
Example #6
0
    def test_send_message_multiple_recipients(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80))

        sender.send(["*****@*****.**", "*****@*****.**"], "New patio", "Do you need any help with the slabs?")

        self.assertTrue(sender.mock_sender.did_ehlo)
        self.assertTrue(sender.mock_sender.did_starttls)
        self.assertTrue(sender.mock_sender.did_login)
        self.assertTrue(sender.mock_sender.did_quit)
Example #7
0
    def test_get_ctype_and_attachment_attachment_not_nonw(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80), ctype=None, attachment_encoding="utf-8")

        attachment = os.path.dirname(__file__) + os.sep + "test.txt"

        ctype, attachment_encoding = sender._get_ctype_and_attachment(attachment, None)

        self.assertEquals("application/octet-stream", ctype)
        self.assertEquals("utf-8", attachment_encoding)
Example #8
0
    def test_get_ctype_and_attachment_both_none(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80), ctype=None, attachment_encoding=None)

        attachment = os.path.dirname(__file__) + os.sep + "test.txt"

        ctype, attachment_encoding = sender._get_ctype_and_attachment(attachment, None)

        self.assertEquals("text/plain", ctype)
        self.assertEquals("utf-8", attachment_encoding)
Example #9
0
 def __init__(self, name):
     BaseContainerConfigurationData.__init__(self, name)
     self._description = 'ProgramY AIML2.0 Client'
     self._bot_configs = []
     self._bot_configs.append(BotConfiguration("bot"))
     self._bot_selector = None
     self._renderer = None
     self._scheduler = SchedulerConfiguration()
     self._storage = StorageConfiguration()
     self._email = EmailConfiguration()
     self._triggers = TriggerConfiguration()
Example #10
0
 def test_to_yaml_with_defaults(self):
     email_config = EmailConfiguration()
     data = {}
     email_config.to_yaml(data, defaults=True)
     self.assertEquals(
         {
             'from_addr': None,
             'host': None,
             'password': None,
             'port': None,
             'username': None
         }, data)
Example #11
0
    def test_add_attachement_ctype_ecoding(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80))

        msg = MIMEMultipart()

        attachment = os.path.dirname(__file__) + os.sep + "test.txt"

        sender._add_attachement(msg, attachment, ctype='text/plain', encoding="utf-8")

        self.assertEquals([('Content-Type', 'multipart/mixed'), ('MIME-Version', '1.0')], msg.items())
        self.assertEquals(1, len(msg.get_payload()))
Example #12
0
    def test_add_attachement_no_ctype_no_encoding_compressed(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80))

        msg = MIMEMultipart()

        attachment = os.path.dirname(__file__) + os.sep + "something.zip"

        sender._add_attachement(msg, attachment, ctype=None, encoding=None)

        self.assertEquals([('Content-Type', 'multipart/mixed'), ('MIME-Version', '1.0')], msg.items())
        self.assertEquals(1, len(msg.get_payload()))
Example #13
0
    def test_send_message_with_text_file_attachment(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80))

        attachment = os.path.dirname(__file__) + os.sep + "test.txt"

        sender.send("*****@*****.**", "New patio", "Do you need any help with the slabs?", [attachment])

        self.assertTrue(sender.mock_sender.did_ehlo)
        self.assertTrue(sender.mock_sender.did_starttls)
        self.assertTrue(sender.mock_sender.did_login)
        self.assertTrue(sender.mock_sender.did_quit)
Example #14
0
    def __init__(self, name):
        BaseContainerConfigurationData.__init__(self, name)
        self._description = 'ProgramY AIML2.0 Client'
        self._renderer = self._get_renderer_class()
        self._scheduler = SchedulerConfiguration()
        self._storage = StorageConfiguration()
        self._email = EmailConfiguration()
        self._triggers = TriggerConfiguration()
        self._responder = PingResponderConfig()

        self._bot_selector = self._get_bot_selector_class()
        bot_config = BotConfiguration('bot')
        self._bot_configs = [bot_config]
Example #15
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
        """, ConsoleConfiguration(), ".")

        client_config = yaml.get_section("email")

        email_config = EmailConfiguration()
        email_config.load_config_section(yaml, client_config, ".")

        self.assertIsNone(email_config.host)
        self.assertIsNone(email_config.port)
        self.assertIsNone(email_config.username)
        self.assertIsNone(email_config.password)
        self.assertIsNone(email_config.from_addr)
Example #16
0
    def test_with_username_for_addr(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        console:
            email:
                host: 127.0.0.1
                port: 80
                username: emailuser
                password: emailpassword
        """, ConsoleConfiguration(), ".")

        client_config = yaml.get_section("console")

        email_config = EmailConfiguration()
        email_config.load_config_section(yaml, client_config, ".")

        self.assertEquals("emailuser", email_config.from_addr)
Example #17
0
    def test_send_message_multi_result(self):
        config = EmailConfiguration()

        sender = MockEmailSender(config, mock_sender=MockSMTPServer("127.0.0.1", 80), result=MockResult({1: "Failed", 2: "Bad"}))

        sender.send("*****@*****.**", "New patio", "Do you need any help with the slabs?")
Example #18
0
    def test_defaults(self):
        email_config = EmailConfiguration()
        data = {}
        email_config.to_yaml(data, True)

        EmailConfigurationTests.assert_defaults(self, data)