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

« back to all changes in this revision

Viewing changes to keystoneclient/tests/v2_0/test_services.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
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
#    not use this file except in compliance with the License. You may obtain
 
5
#    a copy of the License at
 
6
#
 
7
#         http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
#    Unless required by applicable law or agreed to in writing, software
 
10
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
#    License for the specific language governing permissions and limitations
 
13
#    under the License.
 
14
 
 
15
import httpretty
 
16
 
 
17
from keystoneclient.tests.v2_0 import utils
 
18
from keystoneclient.v2_0 import services
 
19
 
 
20
 
 
21
class ServiceTests(utils.TestCase):
 
22
    def setUp(self):
 
23
        super(ServiceTests, self).setUp()
 
24
        self.TEST_SERVICES = {
 
25
            "OS-KSADM:services": {
 
26
                "values": [
 
27
                    {
 
28
                        "name": "nova",
 
29
                        "type": "compute",
 
30
                        "description": "Nova-compatible service.",
 
31
                        "id": 1
 
32
                    },
 
33
                    {
 
34
                        "name": "keystone",
 
35
                        "type": "identity",
 
36
                        "description": "Keystone-compatible service.",
 
37
                        "id": 2
 
38
                    },
 
39
                ],
 
40
            },
 
41
        }
 
42
 
 
43
    @httpretty.activate
 
44
    def test_create(self):
 
45
        req_body = {
 
46
            "OS-KSADM:service": {
 
47
                "name": "swift",
 
48
                "type": "object-store",
 
49
                "description": "Swift-compatible service.",
 
50
            }
 
51
        }
 
52
        resp_body = {
 
53
            "OS-KSADM:service": {
 
54
                "name": "swift",
 
55
                "type": "object-store",
 
56
                "description": "Swift-compatible service.",
 
57
                "id": 3,
 
58
            }
 
59
        }
 
60
        self.stub_url(httpretty.POST, ['OS-KSADM', 'services'], json=resp_body)
 
61
 
 
62
        service = self.client.services.create(
 
63
            req_body['OS-KSADM:service']['name'],
 
64
            req_body['OS-KSADM:service']['type'],
 
65
            req_body['OS-KSADM:service']['description'])
 
66
        self.assertTrue(isinstance(service, services.Service))
 
67
        self.assertEqual(service.id, 3)
 
68
        self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
 
69
        self.assertRequestBodyIs(json=req_body)
 
70
 
 
71
    @httpretty.activate
 
72
    def test_delete(self):
 
73
        self.stub_url(httpretty.DELETE, ['OS-KSADM', 'services', '1'],
 
74
                      status=204)
 
75
 
 
76
        self.client.services.delete(1)
 
77
 
 
78
    @httpretty.activate
 
79
    def test_get(self):
 
80
        test_services = self.TEST_SERVICES['OS-KSADM:services']['values'][0]
 
81
 
 
82
        self.stub_url(httpretty.GET, ['OS-KSADM', 'services', '1'],
 
83
                      json={'OS-KSADM:service': test_services})
 
84
 
 
85
        service = self.client.services.get(1)
 
86
        self.assertTrue(isinstance(service, services.Service))
 
87
        self.assertEqual(service.id, 1)
 
88
        self.assertEqual(service.name, 'nova')
 
89
        self.assertEqual(service.type, 'compute')
 
90
 
 
91
    @httpretty.activate
 
92
    def test_list(self):
 
93
        self.stub_url(httpretty.GET, ['OS-KSADM', 'services'],
 
94
                      json=self.TEST_SERVICES)
 
95
 
 
96
        service_list = self.client.services.list()
 
97
        [self.assertTrue(isinstance(r, services.Service))
 
98
         for r in service_list]