~zulcss/ubuntu/precise/quantum/trunk

« back to all changes in this revision

Viewing changes to quantum/tests/unit/test_common_utils.py

  • Committer: Chuck Short
  • Date: 2012-11-26 19:51:11 UTC
  • mfrom: (26.1.1 raring-proposed)
  • Revision ID: zulcss@ubuntu.com-20121126195111-jnz2cr4xi6whemw2
* New upstream release for the Ubuntu Cloud Archive.
* debian/patches/*: Refreshed for opening of Grizzly.
* New upstream release.
* debian/rules: FTFBS if there is missing binaries.
* debian/quantum-server.install: Add quantum-debug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2012 OpenStack, LLC.
 
2
#
 
3
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
#    not use this file except in compliance with the License. You may obtain
 
5
#    a copy of the License at
 
6
#
 
7
#         http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
#    Unless required by applicable law or agreed to in writing, software
 
10
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
#    License for the specific language governing permissions and limitations
 
13
#    under the License.
 
14
 
 
15
import unittest2 as unittest
 
16
 
 
17
from quantum.common import utils
 
18
 
 
19
 
 
20
class TestParseMappings(unittest.TestCase):
 
21
    def parse(self, mapping_list, unique_values=True):
 
22
        return utils.parse_mappings(mapping_list, unique_values)
 
23
 
 
24
    def test_parse_mappings_fails_for_missing_separator(self):
 
25
        with self.assertRaises(ValueError):
 
26
            self.parse(['key'])
 
27
 
 
28
    def test_parse_mappings_fails_for_missing_key(self):
 
29
        with self.assertRaises(ValueError):
 
30
            self.parse([':val'])
 
31
 
 
32
    def test_parse_mappings_fails_for_missing_value(self):
 
33
        with self.assertRaises(ValueError):
 
34
            self.parse(['key:'])
 
35
 
 
36
    def test_parse_mappings_fails_for_extra_separator(self):
 
37
        with self.assertRaises(ValueError):
 
38
            self.parse(['key:val:junk'])
 
39
 
 
40
    def test_parse_mappings_fails_for_duplicate_key(self):
 
41
        with self.assertRaises(ValueError):
 
42
            self.parse(['key:val1', 'key:val2'])
 
43
 
 
44
    def test_parse_mappings_fails_for_duplicate_value(self):
 
45
        with self.assertRaises(ValueError):
 
46
            self.parse(['key1:val', 'key2:val'])
 
47
 
 
48
    def test_parse_mappings_succeeds_for_one_mapping(self):
 
49
        self.assertEqual(self.parse(['key:val']), {'key': 'val'})
 
50
 
 
51
    def test_parse_mappings_succeeds_for_n_mappings(self):
 
52
        self.assertEqual(self.parse(['key1:val1', 'key2:val2']),
 
53
                         {'key1': 'val1', 'key2': 'val2'})
 
54
 
 
55
    def test_parse_mappings_succeeds_for_duplicate_value(self):
 
56
        self.assertEqual(self.parse(['key1:val', 'key2:val'], False),
 
57
                         {'key1': 'val', 'key2': 'val'})
 
58
 
 
59
    def test_parse_mappings_succeeds_for_no_mappings(self):
 
60
        self.assertEqual(self.parse(['']), {})