| Shuqian Zhao | 8754a1a | 2016-08-24 12:54:11 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Unittests for deploy_server_local.py.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import unittest |
| 11 | |
| 12 | import deploy_server as deploy_server |
| 13 | |
| 14 | |
| 15 | class TestDeployServer(unittest.TestCase): |
| 16 | """Test deploy_server_local with commands mocked out.""" |
| 17 | |
| 18 | def test_parse_arguments(self): |
| 19 | """Test deploy_server_local.parse_arguments.""" |
| 20 | # Only requires args. |
| 21 | results = deploy_server.parse_arguments(['--afe', 'foo']) |
| 22 | self.assertEqual( |
| 23 | {'afe': 'foo', 'servers': [], 'args': [], |
| 24 | 'cont': False, 'dryrun': False, 'verbose': False, |
| 25 | 'update_push_servers': False}, |
| 26 | vars(results)) |
| 27 | |
| 28 | # Dryrun, continue |
| 29 | results = deploy_server.parse_arguments(['--afe', 'foo', |
| 30 | '--dryrun', '--continue']) |
| 31 | self.assertDictContainsSubset( |
| 32 | {'afe': 'foo', 'servers': [], 'args': [], |
| 33 | 'cont': True, 'dryrun': True, 'verbose': False, |
| 34 | 'update_push_servers': False}, |
| 35 | vars(results)) |
| 36 | |
| 37 | # List some servers |
| 38 | results = deploy_server.parse_arguments(['--afe', 'foo', |
| 39 | 'dummy', 'bar']) |
| 40 | self.assertDictContainsSubset( |
| 41 | {'afe': 'foo', 'servers': ['dummy', 'bar'], 'args': [], |
| 42 | 'cont': False, 'dryrun': False, 'verbose': False, |
| 43 | 'update_push_servers': False}, |
| 44 | vars(results)) |
| 45 | |
| 46 | # List some local args |
| 47 | results = deploy_server.parse_arguments(['--afe', 'foo', |
| 48 | '--', 'dummy', 'bar']) |
| 49 | self.assertDictContainsSubset( |
| 50 | {'afe': 'foo', 'servers': [], 'args': ['dummy', 'bar'], |
| 51 | 'cont': False, 'dryrun': False, 'verbose': False, |
| 52 | 'update_push_servers': False}, |
| 53 | vars(results)) |
| 54 | |
| 55 | # List everything. |
| 56 | results = deploy_server.parse_arguments( |
| 57 | ['--continue', '--afe', 'foo', '--dryrun', 'dummy', 'bar', |
| 58 | '--', '--actions-only', '--dryrun', '--update_push_servers']) |
| 59 | self.assertDictContainsSubset( |
| 60 | {'afe': 'foo', 'servers': ['dummy', 'bar'], |
| 61 | 'args': ['--actions-only', '--dryrun', |
| 62 | '--update_push_servers'], |
| 63 | 'cont': True, 'dryrun': True, 'verbose': False}, |
| 64 | vars(results)) |
| 65 | |
| 66 | |
| 67 | if __name__ == '__main__': |
| 68 | unittest.main() |