~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/v2_0/test_discovery.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-18 07:44:54 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20130118074454-g7w5blpynohn1s48
Tags: 1:0.2.2-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import httplib2
 
1
import copy
2
2
import json
 
3
import requests
3
4
 
4
5
from keystoneclient.generic import client
5
6
from tests import utils
6
7
 
7
8
 
8
 
def to_http_response(resp_dict):
9
 
    """
10
 
    Utility function to convert a python dictionary
11
 
    (e.g. {'status':status, 'body': body, 'headers':headers}
12
 
    to an httplib2 response.
13
 
    """
14
 
    resp = httplib2.Response(resp_dict)
15
 
    for k, v in resp_dict['headers'].items():
16
 
        resp[k] = v
17
 
    return resp
18
 
 
19
 
 
20
9
class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
21
10
    def setUp(self):
22
11
        super(DiscoverKeystoneTests, self).setUp()
58
47
        }
59
48
 
60
49
    def test_get_versions(self):
61
 
        resp = httplib2.Response({
62
 
            "status": 200,
63
 
            "body": json.dumps(self.TEST_RESPONSE_DICT),
 
50
        resp = utils.TestResponse({
 
51
            "status_code": 200,
 
52
            "text": json.dumps(self.TEST_RESPONSE_DICT),
64
53
        })
65
54
 
66
 
        httplib2.Http.request(self.TEST_ROOT_URL,
67
 
                              'GET',
68
 
                              headers=self.TEST_REQUEST_HEADERS) \
69
 
            .AndReturn((resp, resp['body']))
 
55
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
 
56
        kwargs['headers'] = self.TEST_REQUEST_HEADERS
 
57
        requests.request('GET',
 
58
                         self.TEST_ROOT_URL,
 
59
                         **kwargs).AndReturn((resp))
70
60
        self.mox.ReplayAll()
71
61
 
72
62
        cs = client.Client()
80
70
            ['href'])
81
71
 
82
72
    def test_get_version_local(self):
83
 
        resp = httplib2.Response({
84
 
            "status": 200,
85
 
            "body": json.dumps(self.TEST_RESPONSE_DICT),
 
73
        resp = utils.TestResponse({
 
74
            "status_code": 200,
 
75
            "text": json.dumps(self.TEST_RESPONSE_DICT),
86
76
        })
87
 
 
88
 
        httplib2.Http.request("http://localhost:35357",
89
 
                              'GET',
90
 
                              headers=self.TEST_REQUEST_HEADERS) \
91
 
            .AndReturn((resp, resp['body']))
 
77
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
 
78
        kwargs['headers'] = self.TEST_REQUEST_HEADERS
 
79
        requests.request('GET',
 
80
                         "http://localhost:35357",
 
81
                         **kwargs).AndReturn((resp))
92
82
        self.mox.ReplayAll()
93
83
 
94
84
        cs = client.Client()