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

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

 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.requestresponse import RequestResponse 
18  from caldavclientlibrary.protocol.http.session import Session 
19  from caldavclientlibrary.protocol.http.data.string import RequestDataString 
20  from caldavclientlibrary.protocol.http.authentication.basic import Basic 
21  from caldavclientlibrary.protocol.http.definitions import methods 
22   
23  import unittest 
24   
25 -class TestRequestHeaders(unittest.TestCase):
26
27 - def test_NoEtag(self):
28 29 server = Session("www.example.com") 30 request = RequestResponse(server, methods.GET, "/") 31 self.assertEqual(request.generateRequestHeader(), """GET / HTTP/1.1 32 Host: www.example.com 33 34 """.replace("\n", "\r\n") 35 )
36
37 - def test_EtagMatch(self):
38 39 server = Session("www.example.com") 40 request = RequestResponse(server, methods.GET, "/", "\"etag\"", True) 41 self.assertEqual(request.generateRequestHeader(), """GET / HTTP/1.1 42 Host: www.example.com 43 If-Match: "etag" 44 45 """.replace("\n", "\r\n") 46 )
47
48 - def test_EtagNoneMatch(self):
49 50 server = Session("www.example.com") 51 request = RequestResponse(server, methods.GET, "/", "\"etag\"", False) 52 self.assertEqual(request.generateRequestHeader(), """GET / HTTP/1.1 53 Host: www.example.com 54 If-None-Match: "etag" 55 56 """.replace("\n", "\r\n") 57 )
58
59 - def test_Content(self):
60 61 server = Session("www.example.com") 62 request = RequestResponse(server, methods.GET, "/") 63 rawdata = "Here is some data\r\non multiple lines." 64 data = RequestDataString(rawdata, "text/plain") 65 request.setData(data, None) 66 self.assertEqual(request.generateRequestHeader(), """GET / HTTP/1.1 67 Host: www.example.com 68 Content-Length: %d 69 Content-Type: text/plain 70 71 """.replace("\n", "\r\n") % (len(rawdata),) 72 )
73
75 76 server = Session("www.example.com") 77 server.authorization = Basic("user", "pswd") 78 request = RequestResponse(server, methods.GET, "/") 79 rawdata = "Here is some data\r\non multiple lines." 80 data = RequestDataString(rawdata, "text/plain") 81 request.setData(data, None) 82 self.assertEqual(request.generateRequestHeader(), """GET / HTTP/1.1 83 Host: www.example.com 84 Authorization: Basic dXNlcjpwc3dk 85 Content-Length: %d 86 Content-Type: text/plain 87 88 """.replace("\n", "\r\n") % (len(rawdata),) 89 )
90