blob: bba63d8d21c89447a28a6c6e5fdc8be67bd1191c [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
Joe Gregorio7cbceab2011-06-27 10:46:54 -040024# Do not remove the httplib2 import
25import httplib2
Joe Gregorio6bcbcea2011-03-10 15:26:05 -050026import unittest
27
28from apiclient.http import set_user_agent
29from apiclient.http import HttpMockSequence
30
31
32class TestUserAgent(unittest.TestCase):
33
34 def test_set_user_agent(self):
35 http = HttpMockSequence([
36 ({'status': '200'}, 'echo_request_headers'),
37 ])
38
39 http = set_user_agent(http, "my_app/5.5")
40 resp, content = http.request("http://example.com")
41 self.assertEqual(content['user-agent'], 'my_app/5.5')
42
43 def test_set_user_agent_nested(self):
44 http = HttpMockSequence([
45 ({'status': '200'}, 'echo_request_headers'),
46 ])
47
48 http = set_user_agent(http, "my_app/5.5")
49 http = set_user_agent(http, "my_library/0.1")
50 resp, content = http.request("http://example.com")
51 self.assertEqual(content['user-agent'], 'my_app/5.5 my_library/0.1')
52
53if __name__ == '__main__':
54 unittest.main()