Index: commit-queue/tests/tree_status_test.py |
=================================================================== |
--- commit-queue/tests/tree_status_test.py (revision 249146) |
+++ commit-queue/tests/tree_status_test.py (working copy) |
@@ -1,140 +0,0 @@ |
-#!/usr/bin/env python |
-# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
-# Use of this source code is governed by a BSD-style license that can be |
-# found in the LICENSE file. |
- |
-"""Unit tests for verification/tree_status.py.""" |
- |
-import calendar |
-import json |
-import logging |
-import os |
-import StringIO |
-import sys |
-import unittest |
-import urllib2 |
- |
-ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
-sys.path.insert(0, os.path.join(ROOT_DIR, '..')) |
- |
-# From tests/ |
-import mocks |
- |
-from verification import tree_status |
- |
- |
-class TreeStatusTest(mocks.TestCase): |
- def setUp(self): |
- super(TreeStatusTest, self).setUp() |
- reference = calendar.timegm((2010, 1, 1, 12, 0, 0, 0, 0, -1)) |
- self.mock(tree_status.time, 'time', lambda: reference) |
- self.urlrequests = [] |
- self.mock(urllib2, 'urlopen', self._urlopen) |
- |
- def tearDown(self): |
- super(TreeStatusTest, self).setUp() |
- |
- def _urlopen(self, _): |
- return StringIO.StringIO(json.dumps(self.urlrequests.pop(0))) |
- |
- def test_fail(self): |
- self.urlrequests = [ |
- [ |
- { |
- 'date': '2010-01-01 11:56:00.0', |
- 'general_state': 'open', |
- 'message': 'Foo', |
- }, |
- { |
- 'date': '2010-01-01 11:57:00.0', |
- 'general_state': 'closed', |
- 'message': 'Bar', |
- }, |
- { |
- 'date': '2010-01-01 11:58:00.0', |
- 'general_state': 'open', |
- 'message': 'Baz', |
- }, |
- ], |
- ] |
- obj = tree_status.TreeStatus(tree_status_url='foo') |
- self.assertEqual(True, obj.postpone()) |
- self.assertEqual(u'Tree is currently not open: Bar', obj.why_not()) |
- self.assertEqual([], self.urlrequests) |
- |
- def test_pass(self): |
- self.urlrequests = [ |
- [ |
- { |
- 'date': '2010-01-01 11:54:00.0', |
- 'general_state': 'open', |
- 'message': 'Foo', |
- }, |
- { |
- 'date': '2010-01-01 11:57:00.0', |
- 'general_state': 'open', |
- 'message': 'Bar', |
- }, |
- { |
- 'date': '2010-01-01 11:53:00.0', |
- 'general_state': 'closed', |
- 'message': 'Baz', |
- }, |
- ], |
- ] |
- obj = tree_status.TreeStatus(tree_status_url='foo') |
- self.assertEqual(False, obj.postpone()) |
- self.assertEqual(None, obj.why_not()) |
- self.assertEqual([], self.urlrequests) |
- |
- def test_skip_tree_check(self): |
- self.urlrequests = [ |
- [ |
- { |
- 'date': '2010-01-01 11:56:00.0', |
- 'general_state': 'open', |
- 'message': 'Foo', |
- }, |
- { |
- 'date': '2010-01-01 11:57:00.0', |
- 'general_state': 'closed', |
- 'message': 'Bar', |
- }, |
- { |
- 'date': '2010-01-01 11:58:00.0', |
- 'general_state': 'open', |
- 'message': 'Baz', |
- }, |
- ], |
- ] |
- # Create a dummy pending obj to pass to the verifier. |
- class dummy_pending(object): |
- issue = 123 |
- description = 'foobarbaz\nNOTREECHECKS=true\nfoobarbaz' |
- verifications = {} |
- def __init__(self): |
- pass |
- |
- verifier = tree_status.TreeStatusVerifier('dummy_status_url') |
- verifier.verify(dummy_pending()) |
- |
- obj = dummy_pending.verifications['tree status'] |
- |
- self.assertEquals(tree_status.AlwaysOpenTreeStatus, type(obj)) |
- self.assertEqual(False, obj.postpone()) |
- self.assertEqual(None, obj.why_not()) |
- # None of the urls should have been opened since it is a skip request. |
- self.assertTrue(len(self.urlrequests[0]) == 3) |
- |
- def test_state(self): |
- t = tree_status.TreeStatus(tree_status_url='foo') |
- self.assertEqual(tree_status.base.SUCCEEDED, t.get_state()) |
- self.assertEqual([], self.urlrequests) |
- |
- |
-if __name__ == '__main__': |
- logging.basicConfig( |
- level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
- min(sys.argv.count('-v'), 3)], |
- format='%(levelname)5s %(module)15s(%(lineno)3d): %(message)s') |
- unittest.main() |