summaryrefslogtreecommitdiff
path: root/tests/test_client.py
blob: 43d0d8d93ca0c5a09d3b4939d39d24b8f4678173 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import httplib2
import json
import mock

from keystoneclient.v2_0 import client
from tests import client_fixtures
from tests import utils


fake_response = httplib2.Response({"status": 200})
fake_body = json.dumps(client_fixtures.PROJECT_SCOPED_TOKEN)
mock_request = mock.Mock(return_value=(fake_response, fake_body))


class KeystoneclientTest(utils.TestCase):

    def test_scoped_init(self):
        with mock.patch.object(httplib2.Http, "request", mock_request):
            cl = client.Client(username='exampleuser',
                               password='password',
                               auth_url='http://somewhere/')
            self.assertIsNotNone(cl.auth_ref)
            self.assertTrue(cl.auth_ref.scoped)

    def test_auth_ref_load(self):
        with mock.patch.object(httplib2.Http, "request", mock_request):
            cl = client.Client(username='exampleuser',
                               password='password',
                               auth_url='http://somewhere/')
            cache = json.dumps(cl.auth_ref)
            new_client = client.Client(auth_ref=json.loads(cache))
            self.assertIsNotNone(new_client.auth_ref)
            self.assertTrue(new_client.auth_ref.scoped)
            self.assertEquals(new_client.username, 'exampleuser')
            self.assertIsNone(new_client.password)
            self.assertEqual(new_client.management_url,
                             'http://admin:35357/v2.0')