Revision a7aacf12 kamaki/cli/argument/test.py

b/kamaki/cli/argument/test.py
34 34
#from mock import patch, call
35 35
from unittest import TestCase
36 36
from StringIO import StringIO
37
from sys import stdin, stdout
37 38
#from itertools import product
38 39

  
39 40
from kamaki.cli import argument
41
from kamaki.cli.config import Config
40 42

  
41 43

  
42 44
class Argument(TestCase):
......
85 87
            del arp
86 88

  
87 89

  
90
class ConfigArgument(TestCase):
91

  
92
    #  A cloud name in config with a URL but no TOKEN
93
    SEMI_CLOUD = 'production'
94

  
95
    # A cloud name that is not configured in config
96
    INVALID_CLOUD = 'QWERTY_123456'
97

  
98
    def setUp(self):
99
        argument._config_arg = argument.ConfigArgument('Recovered Path')
100

  
101
    def test_value(self):
102
        c = argument._config_arg
103
        self.assertEqual(c.value, None)
104
        exp = '/some/random/path'
105
        c.value = exp
106
        self.assertTrue(isinstance(c.value, Config))
107
        self.assertEqual(c.file_path, exp)
108
        self.assertEqual(c.value.path, exp)
109

  
110
    def test_get(self):
111
        c = argument._config_arg
112
        c.value = None
113
        self.assertEqual(c.value.get('global', 'config_cli'), 'config')
114

  
115
    def test_groups(self):
116
        c = argument._config_arg
117
        c.value = None
118
        self.assertTrue(set(c.groups).issuperset([
119
            'image', 'config', 'history']))
120

  
121
    def test_cli_specs(self):
122
        c = argument._config_arg
123
        c.value = None
124
        self.assertTrue(set(c.cli_specs).issuperset([
125
            ('image', 'image'), ('config', 'config'), ('history', 'history')]))
126

  
127
    def test_get_global(self):
128
        c = argument._config_arg
129
        c.value = None
130
        for k, v in (
131
                ('config_cli', 'config'),
132
                ('image_cli', 'image'),
133
                ('history_cli', 'history')):
134
            self.assertEqual(c.get_global(k), v)
135

  
136
    def test_get_cloud(self):
137
        """test_get_cloud (!! hard-set SEMI/INVALID_CLOUD to run this !!)"""
138
        c = argument._config_arg
139
        c.value = None
140
        if not self.SEMI_CLOUD:
141
            stdout.write(
142
                '\n\tA cloud name set in config file with URL but no TOKEN: ')
143
            self.SEMI_CLOUD = stdin.readline()[:-1]
144
        self.assertTrue(len(c.get_cloud(self.SEMI_CLOUD, 'url')) > 0)
145
        self.assertRaises(KeyError, c.get_cloud, self.SEMI_CLOUD, 'token')
146

  
147
        if not self.INVALID_CLOUD:
148
            stdout.write('\tok\n\tA cloud name NOT in your config file: ')
149
            self.INVALID_CLOUD = stdin.readline()[:-1]
150
        self.assertRaises(KeyError, c.get_cloud, self.INVALID_CLOUD, 'url')
151

  
152

  
88 153
if __name__ == '__main__':
89 154
    from sys import argv
90 155
    from kamaki.cli.test import runTestCase
91 156
    runTestCase(Argument, 'Argument', argv[1:])
157
    runTestCase(ConfigArgument, 'ConfigArgument', argv[1:])

Also available in: Unified diff