Home | History | Annotate | Download | only in model
      1 # Copyright (C) 2010 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 Research in Motion Ltd. 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 
     32 from model.queues import Queue
     33 
     34 
     35 class QueueTest(unittest.TestCase):
     36     def test_is_ews(self):
     37         mac_ews = Queue("mac-ews")
     38         self.assertTrue(mac_ews.is_ews())
     39 
     40     def test_queue_with_name(self):
     41         self.assertEqual(Queue.queue_with_name("bogus"), None)
     42         self.assertEqual(Queue.queue_with_name("mac-ews").name(), "mac-ews")
     43         self.assertRaises(AssertionError, Queue, ("bogus"))
     44 
     45     def _assert_short_name(self, queue_name, short_name):
     46         self.assertEquals(Queue(queue_name).short_name(), short_name)
     47 
     48     def test_short_name(self):
     49         self._assert_short_name("mac-ews", "Mac")
     50         self._assert_short_name("chromium-ews", "Cr-Linux")
     51         self._assert_short_name("commit-queue", "Commit")
     52         self._assert_short_name("style-queue", "Style")
     53 
     54     def _assert_display_name(self, queue_name, short_name):
     55         self.assertEquals(Queue(queue_name).display_name(), short_name)
     56 
     57     def test_display_name(self):
     58         self._assert_display_name("mac-ews", "Mac EWS")
     59         self._assert_display_name("chromium-ews", "Chromium Linux EWS")
     60         self._assert_display_name("commit-queue", "Commit Queue")
     61         self._assert_display_name("style-queue", "Style Queue")
     62 
     63     def _assert_name_with_underscores(self, queue_name, short_name):
     64         self.assertEquals(Queue(queue_name).name_with_underscores(), short_name)
     65 
     66     def test_name_with_underscores(self):
     67         self._assert_name_with_underscores("mac-ews", "mac_ews")
     68         self._assert_name_with_underscores("chromium-ews", "chromium_ews")
     69         self._assert_name_with_underscores("commit-queue", "commit_queue")
     70 
     71     def test_style_queue_is_ews(self):
     72         # For now we treat the style-queue as an EWS since most users would
     73         # describe it as such.  If is_ews() ever needs to mean "builds the patch"
     74         # or similar, then we will need to adjust all callers.
     75         self.assertTrue(Queue("style-queue").is_ews())
     76         self.assertTrue("style-queue" in map(Queue.name, Queue.all_ews()))
     77 
     78 
     79 if __name__ == '__main__':
     80     unittest.main()
     81