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, |
Shuqian Zhao | 9febd45 | 2017-01-31 15:36:40 -0800 | [diff] [blame] | 25 | 'force_update': False, 'logfile': '/tmp/deployment.log', |
| 26 | 'update_push_servers': False}, |
Shuqian Zhao | 8754a1a | 2016-08-24 12:54:11 -0700 | [diff] [blame] | 27 | vars(results)) |
| 28 | |
| 29 | # Dryrun, continue |
| 30 | results = deploy_server.parse_arguments(['--afe', 'foo', |
| 31 | '--dryrun', '--continue']) |
| 32 | self.assertDictContainsSubset( |
| 33 | {'afe': 'foo', 'servers': [], 'args': [], |
| 34 | 'cont': True, 'dryrun': True, 'verbose': False, |
Shuqian Zhao | 9febd45 | 2017-01-31 15:36:40 -0800 | [diff] [blame] | 35 | 'force_update': False, 'logfile': '/tmp/deployment.log', |
| 36 | 'update_push_servers': False}, |
Shuqian Zhao | 8754a1a | 2016-08-24 12:54:11 -0700 | [diff] [blame] | 37 | vars(results)) |
| 38 | |
| 39 | # List some servers |
| 40 | results = deploy_server.parse_arguments(['--afe', 'foo', |
| 41 | 'dummy', 'bar']) |
| 42 | self.assertDictContainsSubset( |
| 43 | {'afe': 'foo', 'servers': ['dummy', 'bar'], 'args': [], |
| 44 | 'cont': False, 'dryrun': False, 'verbose': False, |
Shuqian Zhao | 9febd45 | 2017-01-31 15:36:40 -0800 | [diff] [blame] | 45 | 'force_update': False, 'logfile': '/tmp/deployment.log', |
| 46 | 'update_push_servers': False}, |
Shuqian Zhao | 8754a1a | 2016-08-24 12:54:11 -0700 | [diff] [blame] | 47 | vars(results)) |
| 48 | |
| 49 | # List some local args |
| 50 | results = deploy_server.parse_arguments(['--afe', 'foo', |
| 51 | '--', 'dummy', 'bar']) |
| 52 | self.assertDictContainsSubset( |
| 53 | {'afe': 'foo', 'servers': [], 'args': ['dummy', 'bar'], |
| 54 | 'cont': False, 'dryrun': False, 'verbose': False, |
Shuqian Zhao | 9febd45 | 2017-01-31 15:36:40 -0800 | [diff] [blame] | 55 | 'force_update': False, 'logfile': '/tmp/deployment.log', |
| 56 | 'update_push_servers': False}, |
Shuqian Zhao | 8754a1a | 2016-08-24 12:54:11 -0700 | [diff] [blame] | 57 | vars(results)) |
| 58 | |
| 59 | # List everything. |
| 60 | results = deploy_server.parse_arguments( |
| 61 | ['--continue', '--afe', 'foo', '--dryrun', 'dummy', 'bar', |
Shuqian Zhao | a3438a5 | 2016-09-20 15:11:02 -0700 | [diff] [blame] | 62 | '--', '--actions-only', '--dryrun', '--update_push_servers', |
| 63 | '--force_update']) |
Shuqian Zhao | 8754a1a | 2016-08-24 12:54:11 -0700 | [diff] [blame] | 64 | self.assertDictContainsSubset( |
| 65 | {'afe': 'foo', 'servers': ['dummy', 'bar'], |
| 66 | 'args': ['--actions-only', '--dryrun', |
Shuqian Zhao | a3438a5 | 2016-09-20 15:11:02 -0700 | [diff] [blame] | 67 | '--update_push_servers', '--force_update'], |
Shuqian Zhao | 8754a1a | 2016-08-24 12:54:11 -0700 | [diff] [blame] | 68 | 'cont': True, 'dryrun': True, 'verbose': False}, |
| 69 | vars(results)) |
| 70 | |
| 71 | |
| 72 | if __name__ == '__main__': |
| 73 | unittest.main() |