def headers_alternation_test(): headers = [('mime-version', '1'), ('rEceived', '2'), ('mime-version', '3'), ('ReceiveD', '4')] h = MimeHeaders(headers) assert_false(h.have_changed()) h.prepend('Received', 'Yo') ok_(h.have_changed()) h = MimeHeaders(headers) del h['Mime-Version'] ok_(h.have_changed()) h = MimeHeaders(headers) h['Mime-Version'] = 'a' ok_(h.have_changed()) h = MimeHeaders(headers) h.add('Mime-Version', 'a') ok_(h.have_changed()) h = MimeHeaders(headers) h.getall('Mime-Version') h.get('o') assert_false(h.have_changed())
def headers_alternation_test(): headers = [("mime-version", "1"), ("rEceived", "2"), ("mime-version", "3"), ("ReceiveD", "4")] h = MimeHeaders(headers) assert_false(h.have_changed()) h.prepend("Received", "Yo") ok_(h.have_changed()) h = MimeHeaders(headers) del h["Mime-Version"] ok_(h.have_changed()) h = MimeHeaders(headers) h["Mime-Version"] = "a" ok_(h.have_changed()) h = MimeHeaders(headers) h.add("Mime-Version", "a") ok_(h.have_changed()) h = MimeHeaders(headers) h.getall("Mime-Version") h.get("o") assert_false(h.have_changed())
def headers_case_insensitivity_test(): h = MimeHeaders() h['Content-Type'] = 1 eq_(1, h['Content-Type']) eq_(1, h['conTenT-TyPE']) ok_('cOnTenT-TyPE' in h) ok_('Content-Type' in h) eq_(1, h.get('Content-Type')) eq_(None, h.get('Content-Type2')) eq_([('Content-Type', 1)], h.items())
def headers_case_insensitivity_test(): h = MimeHeaders() h["Content-Type"] = 1 eq_(1, h["Content-Type"]) eq_(1, h["conTenT-TyPE"]) ok_("cOnTenT-TyPE" in h) ok_("Content-Type" in h) eq_(1, h.get("Content-Type")) eq_(None, h.get("Content-Type2")) eq_([("Content-Type", 1)], h.items())
def headers_transform_encodedword_test(): # Create a header with non-ascii characters that will be stored in encoded-word format. headers = [('Subject', encoding.to_mime('Subject', u'Hello ✓'))] h = MimeHeaders(headers) # transform should decode it for us when we pass decode=True h.transform(lambda key, val: (key, val.replace(u'✓', u'☃')), decode=True) eq_(u'Hello ☃', h.get('Subject'))
def headers_transform_encodedword_test(): # Create a header with non-ascii characters that will be stored in encoded-word format. headers = [('Subject', encoding.to_mime('Subject', u'Hello ✓'))] h = MimeHeaders(headers) # transform should decode it for us when we pass decode=True h.transform(lambda key,val: (key, val.replace(u'✓', u'☃')), decode=True) eq_(u'Hello ☃', h.get('Subject'))