Revision 5207c784

b/kamaki/cli/commands/test_cli.py
44 44

  
45 45
class _test_init(_command_init):
46 46

  
47
    def main(self, client, method=None):
47
    def _run(self, client, method=None):
48 48
        if method:
49 49
            tests._main([client, method], config=self.config)
50 50
        else:
51 51
            tests._main([client], config=self.config)
52 52

  
53
    def main(self, client, method=None):
54
        return self._run(client, method)
55

  
53 56

  
54 57
@command(test_cmds)
55 58
class test_error(_test_init):
......
87 90
    @errors.generic.all
88 91
    def _run(self):
89 92
        for client in ('pithos', 'cyclades', 'image', 'astakos'):
90
            super(self.__class__, self).main(client)
93
            super(self.__class__, self)._run(client)
91 94

  
92 95
    def main(self):
93 96
        self._run()
......
99 102

  
100 103
    @errors.generic.all
101 104
    def _run(self, method=None):
102
        super(self.__class__, self).main('pithos', method)
105
        super(self.__class__, self)._run('pithos', method)
103 106

  
104 107
    def main(self, method=None):
105 108
        self._run(method)
......
111 114

  
112 115
    @errors.generic.all
113 116
    def _run(self, method=None):
114
        super(self.__class__, self).main('cyclades', method)
117
        super(self.__class__, self)._run('cyclades', method)
115 118

  
116 119
    def main(self, method=None):
117 120
        self._run(method)
......
123 126

  
124 127
    @errors.generic.all
125 128
    def _run(self, method=None):
126
        super(self.__class__, self).main('image', method)
129
        super(self.__class__, self)._run('image', method)
127 130

  
128 131
    def main(self, method=None):
129 132
        self._run(method)
......
135 138

  
136 139
    @errors.generic.all
137 140
    def _run(self, method=None):
138
        super(self.__class__, self).main('astakos', method)
141
        super(self.__class__, self)._run('astakos', method)
139 142

  
140 143
    def main(self, method=None):
141 144
        self._run(method)
b/kamaki/clients/astakos.py
49 49
        :returns: (dict) authentication information
50 50
        """
51 51
        self.token = token or self.token
52
        self._cache[token] = self.get('/im/authenticate')
53
        return self._cache[token].json
52
        self._cache[token] = self.get('/im/authenticate').json
53
        return self._cache[token]
54

  
55
    def list(self):
56
        return self._cache.values()
54 57

  
55 58
    def _user_info(self, token=None):
56 59
        token = token or self.token
......
59 62
        except KeyError:
60 63
            return self.authenticate(token)
61 64

  
62
    def uuid(self, token=None):
63
        return self._user_info(token)['uuid'].strip()
64

  
65
    def name(self, token=None):
66
        return self._user_info(token)['name'].strip()
67

  
68
    def username(self, token=None):
69
        return self._user_info(token)['username'].strip()
70

  
71
    def token_created(self, token=None):
72
        return self._user_info(token)['auth_token_created'].strip()
73

  
74
    def token_expires(self, token=None):
75
        return self._user_info(token)['auth_token_expires'].strip()
76

  
77
    def email(self, token=None):
78
        return self._user_info(token)['email'].strip()
79

  
80
    def id(self, token=None):
81
        """Internal reference for Astakos objects (not a unique user id)
82
        For a unique identifier use uuid
83
        """
84
        return self._user_info(token)['id'].strip()
65
    def term(self, key, token=None):
66
        """Get (cached) term, from user credentials"""
67
        return self._user_info(token)[key]
b/kamaki/clients/tests/__init__.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from unittest import TestCase, TestSuite, makeSuite, TextTestRunner
34
import inspect
35
from unittest import TestCase, TestSuite, TextTestRunner
35 36
from argparse import ArgumentParser
36 37
from sys import stdout
37 38
from progress.bar import ShadyBar
......
45 46
        return foo(self, value)
46 47
    return wrap
47 48

  
49

  
48 50
class Generic(TestCase):
49 51

  
50 52
    _waits = []
......
128 130
                self.assertEqual(unicode(v), unicode(d2[k]))
129 131

  
130 132
    def test_000(self):
131
        import inspect
133
        print('')
132 134
        methods = [method for method in inspect.getmembers(
133 135
            self,
134 136
            predicate=inspect.ismethod)\
......
177 179
        suiteFew.addTest(Image(test_method, config))
178 180
    if len(argv) == 0 or argv[0] == 'astakos':
179 181
        from kamaki.clients.tests.astakos import Astakos
180
        if len(argv) == 1:
181
            suiteFew.addTest(makeSuite(Astakos, config))
182
        else:
183
            suiteFew.addTest(Astakos('test_' + argv[1], config))
182
        test_method = 'test_%s' % (argv[1] if len(argv) > 1 else '000')
183
        suiteFew.addTest(Astakos(test_method, config))
184 184

  
185 185
    TextTestRunner(verbosity=2).run(suiteFew)
186 186

  
......
188 188
    parser = init_parser()
189 189
    args, argv = parser.parse_known_args()
190 190
    if len(argv) > 2 or getattr(args, 'help') or len(argv) < 1:
191
        raise Exception('\tusage: tests.py <group> [command]')
191
        raise Exception('\tusage: tests <group> [command]')
192 192
    main(argv)
b/kamaki/clients/tests/astakos.py
42 42
            self['astakos', 'token'])
43 43

  
44 44
    def test_authenticate(self):
45
        self._test_authenticate()
46

  
47
    def _test_authenticate(self):
45 48
        r = self.client.authenticate()
46 49
        for term in (
50
            'name',
47 51
            'username',
48 52
            'auth_token_expires',
49
            'auth_token',
50 53
            'auth_token_created',
51
            'groups',
52
            'uniq',
53
            'has_credits',
54
            'has_signed_terms'):
54
            'uuid',
55
            'id',
56
            'email'):
55 57
            self.assertTrue(term in r)
58

  
59
    def test_get(self):
60
        self._test_get()
61

  
62
    def _test_get(self):
63
        for term in (
64
            'uuid',
65
            'name',
66
            'username'):
67
            self.assertEqual(self.client.term(term), self['astakos', term])
68
        self.assertTrue(self['astakos', 'email'] in self.client.term('email'))

Also available in: Unified diff