blob: b9e9f75d263e8d703f3074fdf070095cd674673e [file] [log] [blame]
Joe Gregorio6bcbcea2011-03-10 15:26:05 -05001#!/usr/bin/python2.4
2#
3# Copyright 2010 Google Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Http tests
18
19Unit tests for the apiclient.http.
20"""
21
22__author__ = 'jcgregorio@google.com (Joe Gregorio)'
23
24import unittest
25
26from apiclient.http import set_user_agent
27from apiclient.http import HttpMockSequence
28
29
30class TestUserAgent(unittest.TestCase):
31
32 def test_set_user_agent(self):
33 http = HttpMockSequence([
34 ({'status': '200'}, 'echo_request_headers'),
35 ])
36
37 http = set_user_agent(http, "my_app/5.5")
38 resp, content = http.request("http://example.com")
39 self.assertEqual(content['user-agent'], 'my_app/5.5')
40
41 def test_set_user_agent_nested(self):
42 http = HttpMockSequence([
43 ({'status': '200'}, 'echo_request_headers'),
44 ])
45
46 http = set_user_agent(http, "my_app/5.5")
47 http = set_user_agent(http, "my_library/0.1")
48 resp, content = http.request("http://example.com")
49 self.assertEqual(content['user-agent'], 'my_app/5.5 my_library/0.1')
50
51if __name__ == '__main__':
52 unittest.main()