Add CanonicalizationPolicy.to_c_value().

This commit is contained in:
William Grant
2011-06-04 14:37:07 +10:00
parent 206c860890
commit 6b4b98478b
2 changed files with 24 additions and 0 deletions
+4
View File
@@ -119,6 +119,10 @@ class CanonicalizationPolicy:
return None
return cls(header_algorithm, body_algorithm)
def to_c_value(self):
return b'/'.join(
(self.header_algorithm.name, self.body_algorithm.name))
def canonicalize_headers(self, headers):
return self.header_algorithm.canonicalize_headers(headers)
+20
View File
@@ -131,6 +131,26 @@ class TestCanonicalizationPolicyFromCValue(unittest.TestCase):
self.assertValueDoesNotParse(b'worried')
class TestCanonicalizationpolicyToCValue(unittest.TestCase):
def assertCValue(self, c_value, header_algo, body_algo):
self.assertEqual(
c_value,
CanonicalizationPolicy(header_algo, body_algo).to_c_value())
def test_both_simple(self):
self.assertCValue(b'simple/simple', Simple, Simple)
def test_relaxed_body(self):
self.assertCValue(b'simple/relaxed', Simple, Relaxed)
def test_both_relaxed(self):
self.assertCValue(b'relaxed/relaxed', Relaxed, Relaxed)
def test_relaxed_headers(self):
self.assertCValue(b'relaxed/simple', Relaxed, Simple)
def test_suite():
from unittest import TestLoader
return TestLoader().loadTestsFromName(__name__)