Example #1
0
    def test_from_addr(self):
        """Function:  test_from_addr

        Description:  Test with from address is passed.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr, subj=self.subj4, frm=self.frm2)

        self.assertEqual(email.frm, self.frm2)
Example #2
0
    def test_subj_list(self):
        """Function:  test_subj_list

        Description:  Test subject as a list.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)
        email.create_subject(subj=self.subj4)

        self.assertEqual(email.subj, self.subj4a)
Example #3
0
    def test_default(self):
        """Function:  test_default

        Description:  Test __init__ method with default arguments.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)

        self.assertEqual((email.to, email.subj, email.host_name, email.host),
                         (self.toaddr, None, None, None))
Example #4
0
    def test_subj_list_delimiter(self):
        """Function:  test_subj_list_delimiter

        Description:  Test with delimiter passed.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)
        email.create_subject(subj=self.subj4, delimiter="_")

        self.assertEqual(email.subj, self.subj4b)
Example #5
0
    def test_to_list(self):
        """Function:  test_to_list

        Description:  Test to line with a list.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)

        self.assertEqual((email.to, email.subj, email.host_name, email.host),
                         (self.toaddr, None, None, None))
Example #6
0
    def test_no_subject(self):
        """Function:  test_no_subject

        Description:  Test creating subject.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)
        email.create_subject(subj=self.subj)

        self.assertEqual(email.subj, self.subj)
    def test_send_mailx(self, mock_subp):
        """Function:  test_send_mailx

        Description:  Test send_mailx function.

        Arguments:

        """

        mail = gen_class.Mail(self.toaddr, subj=self.subj, frm=self.frm)
        mock_subp.side_effect = [self.subp, self.subp2]

        self.assertFalse(mail.send_mailx())
Example #8
0
    def test_subject_none(self):
        """Function:  test_subject_none

        Description:  Test with no subject passed.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr, subj=self.subj)
        email.create_subject(subj=None)

        self.assertEqual(email.subj, self.subj)
Example #9
0
    def test_initial_add(self):
        """Function:  test_initial_add

        Description:  Test with adding data to empty message.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)
        email.add_2_msg(self.msg)

        self.assertEqual((email.to, email.msg), (self.toaddr, self.msg))
Example #10
0
    def test_subj_overwrite(self):
        """Function:  test_subj_overwrite

        Description:  Test overwriting existing subject.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr, subj=self.subj)
        email.create_subject(subj=self.subj2)

        self.assertEqual(email.subj, self.subj2)
Example #11
0
    def test_subj_string(self):
        """Function:  test_subj_string

        Description:  Test subject as a string.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)
        email.create_subject(subj=self.subj3)

        self.assertEqual(email.subj, self.subj3)
Example #12
0
    def test_empty_test(self):
        """Function:  test_empty_test

        Description:  Test with empty text line.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)
        email.add_2_msg(self.msg)
        email.add_2_msg()

        self.assertEqual((email.to, email.msg), (self.toaddr, self.msg))
Example #13
0
    def test_with_data(self):
        """Function:  test_with_data

        Description:  Test other attributes with data.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr, subj=self.subj2, frm=self.frm2)

        self.assertEqual(
            (email.to, email.subj, email.frm, email.host_name, email.host),
            (email.to, self.subj2, self.frm2, None, None))
Example #14
0
    def test_send_mail(self, mock_smtp, mock_body):
        """Function:  test_send_mail

        Description:  Test test_send_mail function.

        Arguments:

        """

        mock_smtp.return_value = Smtplib()
        mock_body.return_value = True
        email = gen_class.Mail(self.toaddr)

        self.assertFalse(email.send_mail())
Example #15
0
    def test_to_string(self):
        """Function:  test_to_string

        Description:  Test to line with a string.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr)

        self.assertEqual(
            (self.mailaddr, email.subj, email.host_name, email.host),
            (self.mailaddr, None, None, None))
Example #16
0
    def test_subj_list(self):
        """Function:  test_subj_string

        Description:  Test subject line as a string.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr, subj=self.subj4, frm=self.frm2)

        self.assertEqual(
            (email.to, email.subj, email.frm, email.host_name, email.host),
            (email.to, self.subj4a, self.frm2, None, None))
Example #17
0
    def test_create_body(self):
        """Function:  test_create_body

        Description:  Test creating body.

        Arguments:

        """

        msg = "Test email line"
        email = gen_class.Mail(self.toaddr)
        email.add_2_msg(msg)
        email.create_body()

        self.assertEqual(email.create_body(), (self.subj_mask % (msg, msg)))
Example #18
0
    def test_to_list(self, mock_subp):
        """Function:  test_to_list

        Description:  Test to address as a list.

        Arguments:

        """

        mail = gen_class.Mail(self.toaddr2, subj=self.subj, frm=self.frm)
        mock_subp.side_effect = [self.subp, self.subp2]

        mail.send_mailx()

        self.assertEqual((mail.subj, mail.to), (self.subj, self.toaddr))
Example #19
0
    def test_add_exist(self):
        """Function:  test_add_exist

        Description:  Test with adding data to existing message.

        Arguments:

        """

        msg2 = "Test email line2"
        email = gen_class.Mail(self.toaddr)
        email.add_2_msg(self.msg)
        email.add_2_msg(msg2)

        self.assertEqual((email.to, email.msg), (self.toaddr, self.msg + msg2))
Example #20
0
    def test_subj_spaces(self, mock_subp):
        """Function:  test_subj_spaces

        Description:  Test subject line with white spaces.

        Arguments:

        """

        mail = gen_class.Mail(self.toaddr, subj=self.subj2, frm=self.frm)
        mock_subp.side_effect = [self.subp, self.subp2]

        mail.send_mailx()

        self.assertEqual((mail.subj, mail.to), (self.subj2a, self.toaddr))
Example #21
0
    def test_send_mailx2(self, mock_subp):
        """Function:  test_send_mailx2

        Description:  Test send_mailx function.

        Arguments:

        """

        mail = gen_class.Mail(self.toaddr, subj=self.subj, frm=self.frm)
        mock_subp.side_effect = [self.subp, self.subp2]

        mail.send_mailx()

        self.assertEqual((mail.subj, mail.to), (self.subj, self.toaddr))
Example #22
0
    def test_subj_str(self, mock_subp):
        """Function:  test_subj_str

        Description:  Test subject line as a string.

        Arguments:

        """

        mail = gen_class.Mail(self.toaddr, subj=self.subj, frm=self.frm)
        mock_subp.side_effect = [self.subp, self.subp2]

        mail.send_mail(use_mailx=True)

        self.assertEqual((mail.subj, mail.to), (self.subj, self.toaddr))
    def test_print_email(self):
        """Function:  test_print_email

        Description:  Test printing email.

        Arguments:

        """

        email = gen_class.Mail(self.toaddr, subj=self.subj, frm=self.frm)
        email.create_subject(subj=self.subj)
        email.add_2_msg(txt_ln=self.body)

        self.assertEqual(
            email.print_email(), "To: %s\nFrom: %s\n%s" %
            (self.toaddr, self.frm, email.create_body()))
Example #24
0
    def test_long_subject(self):
        """Function:  test_long_subject

        Description:  Test with subject line to maximum.

        Arguments:

        """

        msg = "Test email line with a line greater than thirty characters"
        email = gen_class.Mail(self.toaddr)
        email.add_2_msg(msg)
        email.create_body()

        self.assertEqual(email.create_body(),
                         (self.subj_mask % (msg[:30], msg)))
Example #25
0
    def test_with_subject(self):
        """Function:  test_with_subject

        Description:  Test creating body with subject line in place.

        Arguments:

        """

        msg = "Test email line"
        subj = "Test subject"
        email = gen_class.Mail(self.toaddr, subj=subj)
        email.add_2_msg(msg)
        email.create_body()

        self.assertEqual(email.create_body(), (self.subj_mask % (subj, msg)))
Example #26
0
    def setUp(self):
        """Function:  setUp

        Description:  Initialization for unit testing.

        Arguments:

        """

        self.data = {"key1": "value1", "key2": {"key3": "value2"}}
        self.data2 = {"key1": "value1", "key2": "value2"}
        self.ofile = "test/integration/gen_libs/tmp/test_print_dict.txt"
        self.basefile = "test/integration/gen_libs/basefiles/print_dict.txt"
        self.mail = gen_class.Mail("to_address", "subject_line")
        self.msg = '{\n    "key2": "value2", \n    "key1": "value1"\n}'
        self.msg2 = '{"key2": "value2", "key1": "value1"}'
Example #27
0
    def test_non_string(self):
        """Function:  test_non_string

        Description:  Test with a list argument.

        Arguments:

        """

        msg2 = ["Test ", "email ", "line2"]
        email = gen_class.Mail(self.toaddr)
        email.add_2_msg(self.msg)
        email.add_2_msg(msg2)

        self.assertEqual(
            (email.to, email.msg),
            (self.toaddr, self.msg + '["Test ", "email ", "line2"]'))
Example #28
0
    def setUp(self):
        """Function:  setUp

        Description:  Initialization for unit testing.

        Arguments:

        """

        self.data = {}
        self.data2 = {"key1": "value1"}
        self.ofile = "Out_File"
        self.json_fmt = True
        self.no_std = True
        self.mail = gen_class.Mail("to_address", "subject_line")
        self.msg = '{\n    "key1": "value1"\n}'
        self.msg2 = '{"key1": "value1"}'
Example #29
0
    def test_non_string2(self):
        """Function:  test_non_string2

        Description:  Test with a dictionary argument.

        Arguments:

        """

        msg2 = {1: "Test ", 2: "email ", 3: "line2"}
        email = gen_class.Mail(self.toaddr)
        email.add_2_msg(self.msg)
        email.add_2_msg(msg2)

        self.assertEqual(
            (email.to, email.msg),
            (self.toaddr,
             self.msg + '{"1": "Test ", "2": "email ", "3": "line2"}'))