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_production_local.py."""
7
8from __future__ import print_function
9
10import unittest
11
12import deploy_production as deploy_production
13
14
15class TestDeployProduction(unittest.TestCase):
16    """Test deploy_production_local with commands mocked out."""
17
18    def test_parse_arguments(self):
19        """Test deploy_production_local.parse_arguments."""
20        # No arguments.
21        results = deploy_production.parse_arguments([])
22        self.assertEqual(
23                {'afe': 'cautotest', 'servers': [], 'args': [],
24                 'cont': False, 'dryrun': False, 'verbose': False},
25                vars(results))
26
27        # Dryrun, continue
28        results = deploy_production.parse_arguments(['--dryrun', '--continue'])
29        self.assertDictContainsSubset(
30                {'afe': 'cautotest', 'servers': [], 'args': [],
31                 'cont': True, 'dryrun': True, 'verbose': False},
32                vars(results))
33
34        # List custom AFE server.
35        results = deploy_production.parse_arguments(['--afe', 'foo'])
36        self.assertDictContainsSubset(
37                {'afe': 'foo', 'servers': [], 'args': [],
38                 'cont': False, 'dryrun': False, 'verbose': False},
39                vars(results))
40
41        # List some servers
42        results = deploy_production.parse_arguments(['foo', 'bar'])
43        self.assertDictContainsSubset(
44                {'afe': 'cautotest', 'servers': ['foo', 'bar'], 'args': [],
45                 'cont': False, 'dryrun': False, 'verbose': False},
46                vars(results))
47
48        # List some local args
49        results = deploy_production.parse_arguments(['--', 'foo', 'bar'])
50        self.assertDictContainsSubset(
51                {'afe': 'cautotest', 'servers': [], 'args': ['foo', 'bar'],
52                 'cont': False, 'dryrun': False, 'verbose': False},
53                vars(results))
54
55        # List everything.
56        results = deploy_production.parse_arguments(
57                ['--continue', '--afe', 'foo', '--dryrun', 'foo', 'bar',
58                 '--', '--actions-only', '--dryrun'])
59        self.assertDictContainsSubset(
60                {'afe': 'foo', 'servers': ['foo', 'bar'],
61                 'args': ['--actions-only', '--dryrun'],
62                 'cont': True, 'dryrun': True, 'verbose': False},
63                vars(results))
64
65
66if __name__ == '__main__':
67    unittest.main()
68