Merge "Missing defaults in the create() method in the v2 ServiceManager"

This commit is contained in:
Jenkins
2016-01-27 23:06:43 +00:00
committed by Gerrit Code Review
2 changed files with 33 additions and 2 deletions

View File

@@ -42,7 +42,7 @@ class ServiceTests(utils.ClientTestCase):
}, },
} }
def test_create(self): def test_create_with_description(self):
req_body = { req_body = {
"OS-KSADM:service": { "OS-KSADM:service": {
"name": "swift", "name": "swift",
@@ -68,6 +68,37 @@ class ServiceTests(utils.ClientTestCase):
self.assertIsInstance(service, services.Service) self.assertIsInstance(service, services.Service)
self.assertEqual(service.id, service_id) self.assertEqual(service.id, service_id)
self.assertEqual(service.name, req_body['OS-KSADM:service']['name']) self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
self.assertEqual(service.description,
req_body['OS-KSADM:service']['description'])
self.assertRequestBodyIs(json=req_body)
def test_create_without_description(self):
req_body = {
"OS-KSADM:service": {
"name": "swift",
"type": "object-store",
"description": None,
}
}
service_id = uuid.uuid4().hex
resp_body = {
"OS-KSADM:service": {
"name": "swift",
"type": "object-store",
"id": service_id,
"description": None,
}
}
self.stub_url('POST', ['OS-KSADM', 'services'], json=resp_body)
service = self.client.services.create(
req_body['OS-KSADM:service']['name'],
req_body['OS-KSADM:service']['type'],
req_body['OS-KSADM:service']['description'])
self.assertIsInstance(service, services.Service)
self.assertEqual(service.id, service_id)
self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
self.assertEqual(service.description, None)
self.assertRequestBodyIs(json=req_body) self.assertRequestBodyIs(json=req_body)
def test_delete(self): def test_delete(self):

View File

@@ -35,7 +35,7 @@ class ServiceManager(base.ManagerWithFind):
"""Retrieve a service by id.""" """Retrieve a service by id."""
return self._get("/OS-KSADM/services/%s" % id, "OS-KSADM:service") return self._get("/OS-KSADM/services/%s" % id, "OS-KSADM:service")
def create(self, name, service_type, description): def create(self, name, service_type, description=None):
"""Create a new service.""" """Create a new service."""
body = {"OS-KSADM:service": {'name': name, body = {"OS-KSADM:service": {'name': name,
'type': service_type, 'type': service_type,