Package caldavclientlibrary :: Package protocol :: Package http :: Package tests :: Module test_util
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.protocol.http.tests.test_util

  1  ## 
  2  # Copyright (c) 2006-2016 Apple Inc. All rights reserved. 
  3  # 
  4  # Licensed under the Apache License, Version 2.0 (the "License"); 
  5  # you may not use this file except in compliance with the License. 
  6  # You may obtain a copy of the License at 
  7  # 
  8  # http://www.apache.org/licenses/LICENSE-2.0 
  9  # 
 10  # Unless required by applicable law or agreed to in writing, software 
 11  # distributed under the License is distributed on an "AS IS" BASIS, 
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 13  # See the License for the specific language governing permissions and 
 14  # limitations under the License. 
 15  ## 
 16   
 17  from caldavclientlibrary.protocol.http.util import parsequoted 
 18  from caldavclientlibrary.protocol.http.util import parsetoken 
 19  from caldavclientlibrary.protocol.http.util import parseStatusLine 
 20   
 21  import unittest 
 22   
23 -class TestParseQuoted(unittest.TestCase):
24
25 - def testParseQuotedOK(self):
26 27 data = { 28 "\"\"" : ("", ""), 29 "\"quoted\"" : ("quoted", ""), 30 "\"quoted words\"" : ("quoted words", ""), 31 "\"quoting a \\\"word\\\"\"" : ("quoting a \"word\"", ""), 32 "\"\" after" : ("", "after"), 33 "\"quoted\" after" : ("quoted", "after"), 34 "\"quoted words\" after" : ("quoted words", "after"), 35 "\"quoting a \\\"word\\\"\" after" : ("quoting a \"word\"", "after"), 36 "\"quoting a \\\"word\\\" after\" after": ("quoting a \"word\" after", "after"), 37 "\"quoted\"after" : ("quoted", "after"), 38 "\"" : ("", ""), 39 "\"unterminated" : ("unterminated", ""), 40 "\"unterminated words" : ("unterminated words", ""), 41 "\"unterminated a \\\"word\\\"" : ("unterminated a \"word\"", ""), 42 } 43 44 for input, result in data.iteritems(): 45 self.assertEqual(parsequoted(input), result)
46
47 - def testParseQuotedBAD(self):
48 49 data = ( 50 "", 51 "unquoted", 52 "unquoted \"quoted\"", 53 ) 54 55 for input in data: 56 self.assertRaises(AssertionError, parsequoted, input)
57
58 -class TestParseToken(unittest.TestCase):
59
60 - def testParseTokenOK(self):
61 62 data = { 63 "" : ("", ""), 64 "unquoted" : ("unquoted", ""), 65 "unquoted words" : ("unquoted", "words"), 66 "unquoted words" : ("unquoted", "words"), 67 "unquoting a \"word\"" : ("unquoting", "a \"word\""), 68 "unquoted\twords" : ("unquoted", "words"), 69 "unquoting\ta \"word\"" : ("unquoting", "a \"word\""), 70 "unquoted: words" : ("unquoted", "words"), 71 "unquoting: a \"word\"" : ("unquoting", "a \"word\""), 72 73 "\"\"" : ("", ""), 74 "\"quoted\"" : ("quoted", ""), 75 "\"quoted words\"" : ("quoted words", ""), 76 "\"quoting a \\\"word\\\"\"" : ("quoting a \"word\"", ""), 77 "\"\" after" : ("", "after"), 78 "\"quoted\" after" : ("quoted", "after"), 79 "\"quoted words\" after" : ("quoted words", "after"), 80 "\"quoting a \\\"word\\\"\" after" : ("quoting a \"word\"", "after"), 81 "\"quoting a \\\"word\\\" after\" after": ("quoting a \"word\" after", "after"), 82 "\"quoted\"after" : ("quoted", "after"), 83 "\"" : ("", ""), 84 "\"unterminated" : ("unterminated", ""), 85 "\"unterminated words" : ("unterminated words", ""), 86 "\"unterminated a \\\"word\\\"" : ("unterminated a \"word\"", ""), 87 } 88 89 for input, result in data.iteritems(): 90 self.assertEqual(parsetoken(input, " \t:"), result)
91
92 -class TestParseStatusLine(unittest.TestCase):
93
94 - def testParseTokenOK(self):
95 self.assertEqual(parseStatusLine("HTTP/1.1 200 OK"), 200)
96
97 - def testParseTokenBadStatus(self):
98 self.assertEqual(parseStatusLine("HTTP/1.2 2001 OK"), 0)
99
100 - def testParseTokenBadVersion(self):
101 self.assertEqual(parseStatusLine("HTTP/1.2 200 OK"), 0)
102
103 - def testParseTokenBadNumber(self):
104 self.assertEqual(parseStatusLine("HTTP/1.1 OK"), 0)
105
106 - def testParseTokenBad(self):
107 self.assertEqual(parseStatusLine("HTTP/1.1"), 0)
108