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

« back to all changes in this revision

Viewing changes to tests/v2_0/test_ec2.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2013-11-14 10:51:32 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20131114105132-p1o428l7fclasv9e
Tags: 1:0.4.1-0ubuntu1
[ Adam Gandelman ]
* debian/patches: Refreshed.
* debian/patches/use-mox-dependency.patch: Use mox instead of mox3
  dependency.

[ Chuck Short ]
* New upstream release.
* debian/control:
  - open icehouse release.
  - Dropped python-d2to1 and python-httplib2 dependency.
* debian/patches/skip-tests-ubuntu.patch: Dropped no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import copy
2
 
import json
3
 
import urlparse
4
 
 
5
 
import requests
6
 
 
7
 
from keystoneclient.v2_0 import ec2
8
 
from tests import utils
9
 
 
10
 
 
11
 
class EC2Tests(utils.TestCase):
12
 
    def setUp(self):
13
 
        super(EC2Tests, self).setUp()
14
 
        self.TEST_REQUEST_HEADERS = {
15
 
            'X-Auth-Token': 'aToken',
16
 
            'User-Agent': 'python-keystoneclient',
17
 
        }
18
 
        self.TEST_POST_HEADERS = {
19
 
            'Content-Type': 'application/json',
20
 
            'X-Auth-Token': 'aToken',
21
 
            'User-Agent': 'python-keystoneclient',
22
 
        }
23
 
 
24
 
    def test_create(self):
25
 
        user_id = 'usr'
26
 
        tenant_id = 'tnt'
27
 
        req_body = {
28
 
            "tenant_id": tenant_id,
29
 
        }
30
 
        resp_body = {
31
 
            "credential": {
32
 
                "access": "access",
33
 
                "secret": "secret",
34
 
                "tenant_id": tenant_id,
35
 
                "created": "12/12/12",
36
 
                "enabled": True,
37
 
            }
38
 
        }
39
 
        resp = utils.TestResponse({
40
 
            "status_code": 200,
41
 
            "text": json.dumps(resp_body),
42
 
        })
43
 
 
44
 
        url = urlparse.urljoin(self.TEST_URL,
45
 
                               'v2.0/users/%s/credentials/OS-EC2' % user_id)
46
 
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
47
 
        kwargs['headers'] = self.TEST_POST_HEADERS
48
 
        kwargs['data'] = json.dumps(req_body)
49
 
        requests.request('POST',
50
 
                         url,
51
 
                         **kwargs).AndReturn((resp))
52
 
        self.mox.ReplayAll()
53
 
 
54
 
        cred = self.client.ec2.create(user_id, tenant_id)
55
 
        self.assertTrue(isinstance(cred, ec2.EC2))
56
 
        self.assertEqual(cred.tenant_id, tenant_id)
57
 
        self.assertEqual(cred.enabled, True)
58
 
        self.assertEqual(cred.access, 'access')
59
 
        self.assertEqual(cred.secret, 'secret')
60
 
 
61
 
    def test_get(self):
62
 
        user_id = 'usr'
63
 
        tenant_id = 'tnt'
64
 
        resp_body = {
65
 
            "credential": {
66
 
                "access": "access",
67
 
                "secret": "secret",
68
 
                "tenant_id": tenant_id,
69
 
                "created": "12/12/12",
70
 
                "enabled": True,
71
 
            }
72
 
        }
73
 
        resp = utils.TestResponse({
74
 
            "status_code": 200,
75
 
            "text": json.dumps(resp_body),
76
 
        })
77
 
 
78
 
        url = urlparse.urljoin(self.TEST_URL,
79
 
                               'v2.0/users/%s/credentials/OS-EC2/%s' %
80
 
                               (user_id, 'access'))
81
 
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
82
 
        kwargs['headers'] = self.TEST_REQUEST_HEADERS
83
 
        requests.request('GET',
84
 
                         url,
85
 
                         **kwargs).AndReturn((resp))
86
 
        self.mox.ReplayAll()
87
 
 
88
 
        cred = self.client.ec2.get(user_id, 'access')
89
 
        self.assertTrue(isinstance(cred, ec2.EC2))
90
 
        self.assertEqual(cred.tenant_id, tenant_id)
91
 
        self.assertEqual(cred.enabled, True)
92
 
        self.assertEqual(cred.access, 'access')
93
 
        self.assertEqual(cred.secret, 'secret')
94
 
 
95
 
    def test_list(self):
96
 
        user_id = 'usr'
97
 
        tenant_id = 'tnt'
98
 
        resp_body = {
99
 
            "credentials": {
100
 
                "values": [
101
 
                    {
102
 
                        "access": "access",
103
 
                        "secret": "secret",
104
 
                        "tenant_id": tenant_id,
105
 
                        "created": "12/12/12",
106
 
                        "enabled": True,
107
 
                    },
108
 
                    {
109
 
                        "access": "another",
110
 
                        "secret": "key",
111
 
                        "tenant_id": tenant_id,
112
 
                        "created": "12/12/31",
113
 
                        "enabled": True,
114
 
                    }
115
 
                ]
116
 
            }
117
 
        }
118
 
 
119
 
        resp = utils.TestResponse({
120
 
            "status_code": 200,
121
 
            "text": json.dumps(resp_body),
122
 
        })
123
 
 
124
 
        url = urlparse.urljoin(self.TEST_URL,
125
 
                               'v2.0/users/%s/credentials/OS-EC2' % user_id)
126
 
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
127
 
        kwargs['headers'] = self.TEST_REQUEST_HEADERS
128
 
        requests.request('GET',
129
 
                         url,
130
 
                         **kwargs).AndReturn((resp))
131
 
        self.mox.ReplayAll()
132
 
 
133
 
        creds = self.client.ec2.list(user_id)
134
 
        self.assertTrue(len(creds), 2)
135
 
        cred = creds[0]
136
 
        self.assertTrue(isinstance(cred, ec2.EC2))
137
 
        self.assertEqual(cred.tenant_id, tenant_id)
138
 
        self.assertEqual(cred.enabled, True)
139
 
        self.assertEqual(cred.access, 'access')
140
 
        self.assertEqual(cred.secret, 'secret')
141
 
 
142
 
    def test_delete(self):
143
 
        user_id = 'usr'
144
 
        access = 'access'
145
 
        resp = utils.TestResponse({
146
 
            "status_code": 204,
147
 
            "text": "",
148
 
        })
149
 
 
150
 
        url = urlparse.urljoin(self.TEST_URL,
151
 
                               'v2.0/users/%s/credentials/OS-EC2/%s' %
152
 
                               (user_id, access))
153
 
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
154
 
        kwargs['headers'] = self.TEST_REQUEST_HEADERS
155
 
        requests.request('DELETE',
156
 
                         url,
157
 
                         **kwargs).AndReturn((resp))
158
 
        self.mox.ReplayAll()
159
 
 
160
 
        self.client.ec2.delete(user_id, access)