Revision 409371de

b/kamaki/clients/astakos.py
43 43
        super(AstakosClient, self).__init__(base_url, token)
44 44

  
45 45
    def authenticate(self, token=None):
46
        """
46
        """Get authentication information and store it in this client
47
        As long as the AstakosClient instance is alive, the latest
48
        authentication information for this token will be available
49

  
47 50
        :param token: (str) custom token to authenticate
48 51

  
49 52
        :returns: (dict) authentication information
50 53
        """
51 54
        self.token = token or self.token
52
        self._cache[token] = self.get('/im/authenticate').json
53
        return self._cache[token]
55
        self._cache[self.token] = self.get('/im/authenticate').json
56
        return self._cache[self.token]
54 57

  
55 58
    def list(self):
56 59
        """list cached user information"""
57 60
        return self._cache.values()
58 61

  
59 62
    def _user_info(self, token=None):
63
        token_bu = self.token
60 64
        token = token or self.token
61 65
        try:
62
            return self._cache[token]
66
            r = self._cache[token]
63 67
        except KeyError:
64
            return self.authenticate(token)
68
            r = self.authenticate(token)
69
        self.token = token_bu
70
        return r
65 71

  
66 72
    def term(self, key, token=None):
67 73
        """Get (cached) term, from user credentials"""
b/kamaki/clients/tests/astakos.py
42 42
            self['astakos', 'token'])
43 43

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

  
47
    def _test_authenticate(self):
47
    def _test_0010_authenticate(self):
48 48
        r = self.client.authenticate()
49 49
        for term in (
50 50
            'name',
......
57 57
            self.assertTrue(term in r)
58 58

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

  
62
    def _test_get(self):
62
    def _test_0020_get(self):
63 63
        for term in (
64 64
            'uuid',
65 65
            'name',
......
69 69

  
70 70
    def test_list(self):
71 71
        self.client.authenticate()
72
        self._test_list()
72
        self._test_0020_list()
73 73

  
74
    def _test_list(self):
74
    def _test_0020_list(self):
75 75
        terms = set(['name', 'username', 'uuid', 'email'])
76 76
        uuid = 0
77 77
        for r in self.client.list():
78
            print('Hum?')
79 78
            self.assertTrue(terms.issubset(r.keys()))
80 79
            self.assertTrue(uuid != r['uuid'] if uuid else True)
81 80
            uuid = r['uuid']

Also available in: Unified diff