OLD | NEW |
1 # Copyright (C) 2012 Google Inc. All rights reserved. | 1 # Copyright (C) 2012 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 self.errors_sent.add(code) | 46 self.errors_sent.add(code) |
47 | 47 |
48 def function_one(self): | 48 def function_one(self): |
49 self.functions_run.add("function_one") | 49 self.functions_run.add("function_one") |
50 | 50 |
51 def some_html(self): | 51 def some_html(self): |
52 self.functions_run.add("some_html") | 52 self.functions_run.add("some_html") |
53 | 53 |
54 | 54 |
55 class WriteConvertingLogger(object): | 55 class WriteConvertingLogger(object): |
| 56 |
56 def __init__(self): | 57 def __init__(self): |
57 self.data = '' | 58 self.data = '' |
58 | 59 |
59 def write(self, data): | 60 def write(self, data): |
60 # If data is still in ASCII, this will throw an exception. | 61 # If data is still in ASCII, this will throw an exception. |
61 self.data = str(data) | 62 self.data = str(data) |
62 | 63 |
63 | 64 |
64 class TestReflectionHandlerServeXML(ReflectionHandler): | 65 class TestReflectionHandlerServeXML(ReflectionHandler): |
| 66 |
65 def __init__(self): | 67 def __init__(self): |
66 self.requestline = False | 68 self.requestline = False |
67 self.client_address = '127.0.0.1' | 69 self.client_address = '127.0.0.1' |
68 self.request_version = '1' | 70 self.request_version = '1' |
69 self.wfile = WriteConvertingLogger() | 71 self.wfile = WriteConvertingLogger() |
70 | 72 |
71 def serve_xml(self, data): | 73 def serve_xml(self, data): |
72 self._serve_xml(data) | 74 self._serve_xml(data) |
73 | 75 |
74 def log_message(self, _format, *_args): | 76 def log_message(self, _format, *_args): |
75 pass | 77 pass |
76 | 78 |
77 | 79 |
78 class ReflectionHandlerTest(unittest.TestCase): | 80 class ReflectionHandlerTest(unittest.TestCase): |
| 81 |
79 def assert_handler_response(self, requests, expected_static_files, expected_
errors, expected_functions): | 82 def assert_handler_response(self, requests, expected_static_files, expected_
errors, expected_functions): |
80 handler = TestReflectionHandler() | 83 handler = TestReflectionHandler() |
81 for request in requests: | 84 for request in requests: |
82 handler.path = request | 85 handler.path = request |
83 handler._handle_request() | 86 handler._handle_request() |
84 self.assertEqual(handler.static_files_served, expected_static_files) | 87 self.assertEqual(handler.static_files_served, expected_static_files) |
85 self.assertEqual(handler.errors_sent, expected_errors) | 88 self.assertEqual(handler.errors_sent, expected_errors) |
86 self.assertEqual(handler.functions_run, expected_functions) | 89 self.assertEqual(handler.functions_run, expected_functions) |
87 | 90 |
88 def test_static_content_or_function_switch(self): | 91 def test_static_content_or_function_switch(self): |
89 self.assert_handler_response(["/test.js"], set(["test.js"]), set(), set(
)) | 92 self.assert_handler_response(["/test.js"], set(["test.js"]), set(), set(
)) |
90 self.assert_handler_response(["/test.js", "/test.css", "/test.html"], se
t(["test.js", "test.html", "test.css"]), set(), set()) | 93 self.assert_handler_response(["/test.js", "/test.css", "/test.html"], |
| 94 set(["test.js", "test.html", "test.css"]),
set(), set()) |
91 self.assert_handler_response(["/test.js", "/test.exe", "/testhtml"], set
(["test.js"]), set([404]), set()) | 95 self.assert_handler_response(["/test.js", "/test.exe", "/testhtml"], set
(["test.js"]), set([404]), set()) |
92 self.assert_handler_response(["/test.html", "/function.one"], set(["test
.html"]), set(), set(['function_one'])) | 96 self.assert_handler_response(["/test.html", "/function.one"], set(["test
.html"]), set(), set(['function_one'])) |
93 self.assert_handler_response(["/some.html"], set(["some.html"]), set(),
set()) | 97 self.assert_handler_response(["/some.html"], set(["some.html"]), set(),
set()) |
94 | 98 |
95 def test_svn_log_non_ascii(self): | 99 def test_svn_log_non_ascii(self): |
96 xmlChangelog = u'<?xml version="1.0"?>\n<log>\n<logentry revision="1">\n
<msg>Patch from John Do\xe9.</msg>\n</logentry>\n</log>' | 100 xmlChangelog = u'<?xml version="1.0"?>\n<log>\n<logentry revision="1">\n
<msg>Patch from John Do\xe9.</msg>\n</logentry>\n</log>' |
97 handler = TestReflectionHandlerServeXML() | 101 handler = TestReflectionHandlerServeXML() |
98 handler.serve_xml(xmlChangelog) | 102 handler.serve_xml(xmlChangelog) |
99 self.assertEqual(handler.wfile.data, xmlChangelog.encode('utf-8')) | 103 self.assertEqual(handler.wfile.data, xmlChangelog.encode('utf-8')) |
OLD | NEW |