Exemple #1
0
    def test_cache_recreation(self):
        s1 = "Test"
        s2 = "Another"
        e = Envelope("dumb message").subject(s1)
        self.check_lines(e, f"Subject: {s1}")

        e.subject(s2)
        self.check_lines(e, f"Subject: {s2}")
Exemple #2
0
    def test_specific_header_manipulation(self):
        """ Specific headers are stored in instance attributes
            Ex: It is useful to have Subject as a special header since it can be encrypted.
            Ex: It is useful to have Cc as a special header since it can hold the list of receivers.
        """
        # Add a specific header like and delete it
        s = "my subject"
        id1 = "*****@*****.**"
        id2 = "*****@*****.**"
        id3 = "*****@*****.**"
        e = Envelope("dumb message") \
            .subject(s) \
            .header("custom", "1") \
            .cc(id1)  # set headers via their specific methods
        self.assertEqual(s, e.header("subject"))  # access via .header
        self.assertEqual(s, e.subject())  # access via specific method .subject
        self.assertIs(e, e.header("subject", replace=True))
        self.assertIs("", e.header("subject"))
        self.assertEqual(s,
                         e.header("subject",
                                  s).subject())  # set via generic method

        self.assertEqual([id1, id2],
                         e.header("cc",
                                  id2).header("cc"))  # access via .header
        self.assertEqual(e.cc(), [id1, id2])
        self.assertIs(e.header("cc", replace=True), e)
        self.assertEqual(e.cc(), [])
        self.assertIs(e.header("cc", id3), e)
        self.assertEqual(
            e.header("cc"), [id3]
        )  # cc and bcc headers always return list as documented (which is maybe not ideal)