1 # Copyright (C) 2009 Google Inc. All rights reserved. 2 # 3 # Redistribution and use in source and binary forms, with or without 4 # modification, are permitted provided that the following conditions are 5 # met: 6 # 7 # * Redistributions of source code must retain the above copyright 8 # notice, this list of conditions and the following disclaimer. 9 # * Redistributions in binary form must reproduce the above 10 # copyright notice, this list of conditions and the following disclaimer 11 # in the documentation and/or other materials provided with the 12 # distribution. 13 # * Neither the name of Google Inc. nor the names of its 14 # contributors may be used to endorse or promote products derived from 15 # this software without specific prior written permission. 16 # 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 import unittest 30 31 from webkitpy.bugzilla import Attachment 32 from webkitpy.mock import Mock 33 from webkitpy.mock_bugzillatool import MockBugzillaTool 34 from webkitpy.outputcapture import OutputCapture 35 36 37 class MockQueueEngine(object): 38 def __init__(self, name, queue): 39 pass 40 41 def run(self): 42 pass 43 44 45 class QueuesTest(unittest.TestCase): 46 mock_work_item = Attachment({ 47 "id" : 1234, 48 "bug_id" : 345, 49 "attacher_email": "adam (at] example.com", 50 }, None) 51 52 def assert_queue_outputs(self, queue, args=None, work_item=None, expected_stdout=None, expected_stderr=None, options=Mock(), tool=MockBugzillaTool()): 53 if not expected_stdout: 54 expected_stdout = {} 55 if not expected_stderr: 56 expected_stderr = {} 57 if not args: 58 args = [] 59 if not work_item: 60 work_item = self.mock_work_item 61 tool.user.prompt = lambda message: "yes" 62 63 queue.execute(options, args, tool, engine=MockQueueEngine) 64 65 OutputCapture().assert_outputs(self, 66 queue.queue_log_path, 67 expected_stdout=expected_stdout.get("queue_log_path", ""), 68 expected_stderr=expected_stderr.get("queue_log_path", "")) 69 OutputCapture().assert_outputs(self, 70 queue.work_item_log_path, 71 args=[work_item], 72 expected_stdout=expected_stdout.get("work_item_log_path", ""), 73 expected_stderr=expected_stderr.get("work_item_log_path", "")) 74 OutputCapture().assert_outputs(self, 75 queue.begin_work_queue, 76 expected_stdout=expected_stdout.get("begin_work_queue", ""), 77 expected_stderr=expected_stderr.get("begin_work_queue", "")) 78 OutputCapture().assert_outputs(self, 79 queue.should_continue_work_queue, 80 expected_stdout=expected_stdout.get("should_continue_work_queue", ""), expected_stderr=expected_stderr.get("should_continue_work_queue", "")) 81 OutputCapture().assert_outputs(self, 82 queue.next_work_item, 83 expected_stdout=expected_stdout.get("next_work_item", ""), 84 expected_stderr=expected_stderr.get("next_work_item", "")) 85 OutputCapture().assert_outputs(self, 86 queue.should_proceed_with_work_item, 87 args=[work_item], 88 expected_stdout=expected_stdout.get("should_proceed_with_work_item", ""), 89 expected_stderr=expected_stderr.get("should_proceed_with_work_item", "")) 90 OutputCapture().assert_outputs(self, 91 queue.process_work_item, 92 args=[work_item], 93 expected_stdout=expected_stdout.get("process_work_item", ""), 94 expected_stderr=expected_stderr.get("process_work_item", "")) 95 OutputCapture().assert_outputs(self, 96 queue.handle_unexpected_error, 97 args=[work_item, "Mock error message"], 98 expected_stdout=expected_stdout.get("handle_unexpected_error", ""), 99 expected_stderr=expected_stderr.get("handle_unexpected_error", "")) 100