Change update/create method options
Rather than use booleans, switch to explicit definition of which method is used. This is useful because 'update' can when including Swift be 3 different methods, and that gets messy with booleans. An explicit definition works nicer and gives us more flexibility in future as well as a nicer pattern for similar method remappings. Depends-On: Icfa811571ec7c26617e0f8e9db086001fc0bc81f Change-Id: I7e231a8c89ffd74fdd63aabafb408fadfdb69c67
This commit is contained in:
parent
8daa33e384
commit
26732e8374
@ -26,7 +26,7 @@ class Chassis(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'fields'
|
'fields'
|
||||||
|
@ -26,7 +26,7 @@ class Node(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'associated', 'driver', 'fields', 'provision_state', 'resource_class',
|
'associated', 'driver', 'fields', 'provision_state', 'resource_class',
|
||||||
|
@ -26,7 +26,7 @@ class Port(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'fields'
|
'fields'
|
||||||
|
@ -26,7 +26,7 @@ class PortGroup(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'node', 'address', 'fields',
|
'node', 'address', 'fields',
|
||||||
|
@ -27,7 +27,7 @@ class Cluster(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'name', 'status', 'sort', 'global_project')
|
'name', 'status', 'sort', 'global_project')
|
||||||
|
@ -28,7 +28,7 @@ class Node(resource.Resource):
|
|||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
|
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'show_details', 'name', 'sort', 'global_project', 'cluster_id',
|
'show_details', 'name', 'sort', 'global_project', 'cluster_id',
|
||||||
|
@ -27,7 +27,7 @@ class Policy(resource.Resource):
|
|||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_update = True
|
allow_update = True
|
||||||
|
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'name', 'type', 'sort', 'global_project')
|
'name', 'type', 'sort', 'global_project')
|
||||||
@ -63,4 +63,4 @@ class PolicyValidate(Policy):
|
|||||||
allow_delete = False
|
allow_delete = False
|
||||||
allow_update = False
|
allow_update = False
|
||||||
|
|
||||||
patch_update = False
|
update_method = 'PUT'
|
||||||
|
@ -27,7 +27,7 @@ class Profile(resource.Resource):
|
|||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
|
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'sort', 'global_project', 'type', 'name')
|
'sort', 'global_project', 'type', 'name')
|
||||||
@ -61,4 +61,4 @@ class ProfileValidate(Profile):
|
|||||||
allow_delete = False
|
allow_delete = False
|
||||||
allow_list = False
|
allow_list = False
|
||||||
|
|
||||||
patch_update = False
|
update_method = 'PUT'
|
||||||
|
@ -27,7 +27,7 @@ class Receiver(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
|
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'name', 'type', 'cluster_id', 'action', 'sort', 'global_project',
|
'name', 'type', 'cluster_id', 'action', 'sort', 'global_project',
|
||||||
|
@ -26,7 +26,7 @@ class Credential(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'type', 'user_id',
|
'type', 'user_id',
|
||||||
|
@ -27,7 +27,7 @@ class Domain(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'name',
|
'name',
|
||||||
|
@ -26,7 +26,7 @@ class Endpoint(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'interface', 'service_id',
|
'interface', 'service_id',
|
||||||
|
@ -26,7 +26,7 @@ class Group(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'domain_id', 'name',
|
'domain_id', 'name',
|
||||||
|
@ -26,7 +26,7 @@ class Policy(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
# Properties
|
# Properties
|
||||||
#: The policy rule set itself, as a serialized blob. *Type: string*
|
#: The policy rule set itself, as a serialized blob. *Type: string*
|
||||||
|
@ -27,7 +27,7 @@ class Project(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'domain_id',
|
'domain_id',
|
||||||
|
@ -26,7 +26,7 @@ class Region(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'parent_region_id',
|
'parent_region_id',
|
||||||
|
@ -26,7 +26,7 @@ class Service(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'type',
|
'type',
|
||||||
|
@ -26,7 +26,7 @@ class User(resource.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
'domain_id',
|
'domain_id',
|
||||||
|
@ -34,7 +34,7 @@ class Image(resource2.Resource):
|
|||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
_query_mapping = resource2.QueryParameters("name", "visibility",
|
_query_mapping = resource2.QueryParameters("name", "visibility",
|
||||||
"member_status", "owner",
|
"member_status", "owner",
|
||||||
|
@ -31,7 +31,7 @@ class Claim(resource2.Resource):
|
|||||||
allow_get = True
|
allow_get = True
|
||||||
allow_update = True
|
allow_update = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
patch_update = True
|
update_method = 'PATCH'
|
||||||
|
|
||||||
# Properties
|
# Properties
|
||||||
#: The value in seconds indicating how long the claim has existed.
|
#: The value in seconds indicating how long the claim has existed.
|
||||||
|
@ -247,10 +247,11 @@ class Resource(object):
|
|||||||
allow_list = False
|
allow_list = False
|
||||||
#: Allow head operation for this resource.
|
#: Allow head operation for this resource.
|
||||||
allow_head = False
|
allow_head = False
|
||||||
#: Use PATCH for update operations on this resource.
|
|
||||||
patch_update = False
|
#: Method for udating a resource (PUT, PATCH, POST)
|
||||||
#: Use PUT for create operations on this resource.
|
update_method = "PUT"
|
||||||
put_create = False
|
#: Method for creating a resource (POST, PUT)
|
||||||
|
create_method = "POST"
|
||||||
|
|
||||||
def __init__(self, _synchronized=False, **attrs):
|
def __init__(self, _synchronized=False, **attrs):
|
||||||
"""The base resource
|
"""The base resource
|
||||||
@ -578,16 +579,19 @@ class Resource(object):
|
|||||||
if not self.allow_create:
|
if not self.allow_create:
|
||||||
raise exceptions.MethodNotSupported(self, "create")
|
raise exceptions.MethodNotSupported(self, "create")
|
||||||
|
|
||||||
if self.put_create:
|
if self.create_method == 'PUT':
|
||||||
request = self._prepare_request(requires_id=True,
|
request = self._prepare_request(requires_id=True,
|
||||||
prepend_key=prepend_key)
|
prepend_key=prepend_key)
|
||||||
response = session.put(request.url,
|
response = session.put(request.url,
|
||||||
json=request.body, headers=request.headers)
|
json=request.body, headers=request.headers)
|
||||||
else:
|
elif self.create_method == 'POST':
|
||||||
request = self._prepare_request(requires_id=False,
|
request = self._prepare_request(requires_id=False,
|
||||||
prepend_key=prepend_key)
|
prepend_key=prepend_key)
|
||||||
response = session.post(request.url,
|
response = session.post(request.url,
|
||||||
json=request.body, headers=request.headers)
|
json=request.body, headers=request.headers)
|
||||||
|
else:
|
||||||
|
raise exceptions.ResourceFailure(
|
||||||
|
msg="Invalid create method: %s" % self.create_method)
|
||||||
|
|
||||||
self._translate_response(response)
|
self._translate_response(response)
|
||||||
return self
|
return self
|
||||||
@ -661,13 +665,18 @@ class Resource(object):
|
|||||||
|
|
||||||
request = self._prepare_request(prepend_key=prepend_key)
|
request = self._prepare_request(prepend_key=prepend_key)
|
||||||
|
|
||||||
if self.patch_update:
|
if self.update_method == 'PATCH':
|
||||||
response = session.patch(request.url,
|
response = session.patch(
|
||||||
json=request.body,
|
request.url, json=request.body, headers=request.headers)
|
||||||
headers=request.headers)
|
elif self.update_method == 'POST':
|
||||||
|
response = session.post(
|
||||||
|
request.url, json=request.body, headers=request.headers)
|
||||||
|
elif self.update_method == 'PUT':
|
||||||
|
response = session.put(
|
||||||
|
request.url, json=request.body, headers=request.headers)
|
||||||
else:
|
else:
|
||||||
response = session.put(request.url,
|
raise exceptions.ResourceFailure(
|
||||||
json=request.body, headers=request.headers)
|
msg="Invalid update method: %s" % self.update_method)
|
||||||
|
|
||||||
self._translate_response(response, has_body=has_body)
|
self._translate_response(response, has_body=has_body)
|
||||||
return self
|
return self
|
||||||
|
@ -37,8 +37,8 @@ class TestVersion(testtools.TestCase):
|
|||||||
self.assertFalse(sot.allow_delete)
|
self.assertFalse(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertFalse(sot.allow_head)
|
self.assertFalse(sot.allow_head)
|
||||||
self.assertFalse(sot.patch_update)
|
self.assertEqual('PUT', sot.update_method)
|
||||||
self.assertFalse(sot.put_create)
|
self.assertEqual('POST', sot.create_method)
|
||||||
|
|
||||||
def test_make_it(self):
|
def test_make_it(self):
|
||||||
sot = version.Version(**EXAMPLE)
|
sot = version.Version(**EXAMPLE)
|
||||||
|
@ -56,7 +56,7 @@ class TestChassis(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
def test_instantiate(self):
|
def test_instantiate(self):
|
||||||
sot = chassis.Chassis(**FAKE)
|
sot = chassis.Chassis(**FAKE)
|
||||||
|
@ -104,7 +104,7 @@ class TestNode(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
def test_instantiate(self):
|
def test_instantiate(self):
|
||||||
sot = node.Node(**FAKE)
|
sot = node.Node(**FAKE)
|
||||||
|
@ -55,7 +55,7 @@ class TestPort(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
def test_instantiate(self):
|
def test_instantiate(self):
|
||||||
sot = port.PortDetail(**FAKE)
|
sot = port.PortDetail(**FAKE)
|
||||||
|
@ -60,7 +60,7 @@ class TestPortGroup(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
def test_instantiate(self):
|
def test_instantiate(self):
|
||||||
sot = port_group.PortGroup(**FAKE)
|
sot = port_group.PortGroup(**FAKE)
|
||||||
|
@ -57,7 +57,7 @@ class TestProfile(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
def test_instantiate(self):
|
def test_instantiate(self):
|
||||||
sot = profile.Profile(**FAKE)
|
sot = profile.Profile(**FAKE)
|
||||||
@ -89,4 +89,4 @@ class TestProfileValidate(testtools.TestCase):
|
|||||||
self.assertFalse(sot.allow_update)
|
self.assertFalse(sot.allow_update)
|
||||||
self.assertFalse(sot.allow_delete)
|
self.assertFalse(sot.allow_delete)
|
||||||
self.assertFalse(sot.allow_list)
|
self.assertFalse(sot.allow_list)
|
||||||
self.assertFalse(sot.patch_update)
|
self.assertEqual('PUT', sot.update_method)
|
||||||
|
@ -37,7 +37,7 @@ class TestCredential(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ class TestDomain(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ class TestEndpoint(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
{
|
{
|
||||||
'interface': 'interface',
|
'interface': 'interface',
|
||||||
|
@ -36,7 +36,7 @@ class TestGroup(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@ class TestPolicy(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
def test_make_it(self):
|
def test_make_it(self):
|
||||||
sot = policy.Policy(**EXAMPLE)
|
sot = policy.Policy(**EXAMPLE)
|
||||||
|
@ -39,7 +39,7 @@ class TestProject(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ class TestRegion(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@ class TestService(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,7 @@ class TestUser(testtools.TestCase):
|
|||||||
self.assertTrue(sot.allow_update)
|
self.assertTrue(sot.allow_update)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
self.assertTrue(sot.patch_update)
|
self.assertEqual('PATCH', sot.update_method)
|
||||||
|
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
{
|
{
|
||||||
|
@ -783,7 +783,7 @@ class ResourceTests(base.TestCase):
|
|||||||
def test_put_update(self):
|
def test_put_update(self):
|
||||||
class FakeResourcePut(FakeResource):
|
class FakeResourcePut(FakeResource):
|
||||||
# This is False by default, but explicit for this test.
|
# This is False by default, but explicit for this test.
|
||||||
patch_update = False
|
update_method = 'PUT'
|
||||||
|
|
||||||
resp = FakeResponse(fake_body, headers={'location': 'foo'})
|
resp = FakeResponse(fake_body, headers={'location': 'foo'})
|
||||||
self.session.put = mock.Mock(return_value=resp)
|
self.session.put = mock.Mock(return_value=resp)
|
||||||
|
@ -424,8 +424,8 @@ class TestResource(base.TestCase):
|
|||||||
self.assertFalse(sot.allow_delete)
|
self.assertFalse(sot.allow_delete)
|
||||||
self.assertFalse(sot.allow_list)
|
self.assertFalse(sot.allow_list)
|
||||||
self.assertFalse(sot.allow_head)
|
self.assertFalse(sot.allow_head)
|
||||||
self.assertFalse(sot.patch_update)
|
self.assertEqual('PUT', sot.update_method)
|
||||||
self.assertFalse(sot.put_create)
|
self.assertEqual('POST', sot.create_method)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
a = {"a": 1}
|
a = {"a": 1}
|
||||||
@ -995,7 +995,7 @@ class TestResourceActions(base.TestCase):
|
|||||||
service = self.service_name
|
service = self.service_name
|
||||||
base_path = self.base_path
|
base_path = self.base_path
|
||||||
allow_create = True
|
allow_create = True
|
||||||
put_create = True
|
create_method = 'PUT'
|
||||||
|
|
||||||
self._test_create(Test, requires_id=True, prepend_key=True)
|
self._test_create(Test, requires_id=True, prepend_key=True)
|
||||||
|
|
||||||
@ -1004,7 +1004,7 @@ class TestResourceActions(base.TestCase):
|
|||||||
service = self.service_name
|
service = self.service_name
|
||||||
base_path = self.base_path
|
base_path = self.base_path
|
||||||
allow_create = True
|
allow_create = True
|
||||||
put_create = False
|
create_method = 'POST'
|
||||||
|
|
||||||
self._test_create(Test, requires_id=False, prepend_key=True)
|
self._test_create(Test, requires_id=False, prepend_key=True)
|
||||||
|
|
||||||
@ -1039,9 +1039,9 @@ class TestResourceActions(base.TestCase):
|
|||||||
self.sot._translate_response.assert_called_once_with(self.response)
|
self.sot._translate_response.assert_called_once_with(self.response)
|
||||||
self.assertEqual(result, self.sot)
|
self.assertEqual(result, self.sot)
|
||||||
|
|
||||||
def _test_update(self, patch_update=False, prepend_key=True,
|
def _test_update(self, update_method='PUT', prepend_key=True,
|
||||||
has_body=True):
|
has_body=True):
|
||||||
self.sot.patch_update = patch_update
|
self.sot.update_method = update_method
|
||||||
|
|
||||||
# Need to make sot look dirty so we can attempt an update
|
# Need to make sot look dirty so we can attempt an update
|
||||||
self.sot._body = mock.Mock()
|
self.sot._body = mock.Mock()
|
||||||
@ -1053,11 +1053,15 @@ class TestResourceActions(base.TestCase):
|
|||||||
self.sot._prepare_request.assert_called_once_with(
|
self.sot._prepare_request.assert_called_once_with(
|
||||||
prepend_key=prepend_key)
|
prepend_key=prepend_key)
|
||||||
|
|
||||||
if patch_update:
|
if update_method == 'PATCH':
|
||||||
self.session.patch.assert_called_once_with(
|
self.session.patch.assert_called_once_with(
|
||||||
self.request.url,
|
self.request.url,
|
||||||
json=self.request.body, headers=self.request.headers)
|
json=self.request.body, headers=self.request.headers)
|
||||||
else:
|
elif update_method == 'POST':
|
||||||
|
self.session.post.assert_called_once_with(
|
||||||
|
self.request.url,
|
||||||
|
json=self.request.body, headers=self.request.headers)
|
||||||
|
elif update_method == 'PUT':
|
||||||
self.session.put.assert_called_once_with(
|
self.session.put.assert_called_once_with(
|
||||||
self.request.url,
|
self.request.url,
|
||||||
json=self.request.body, headers=self.request.headers)
|
json=self.request.body, headers=self.request.headers)
|
||||||
@ -1066,10 +1070,11 @@ class TestResourceActions(base.TestCase):
|
|||||||
self.response, has_body=has_body)
|
self.response, has_body=has_body)
|
||||||
|
|
||||||
def test_update_put(self):
|
def test_update_put(self):
|
||||||
self._test_update(patch_update=False, prepend_key=True, has_body=True)
|
self._test_update(update_method='PUT', prepend_key=True, has_body=True)
|
||||||
|
|
||||||
def test_update_patch(self):
|
def test_update_patch(self):
|
||||||
self._test_update(patch_update=True, prepend_key=False, has_body=False)
|
self._test_update(
|
||||||
|
update_method='PATCH', prepend_key=False, has_body=False)
|
||||||
|
|
||||||
def test_update_not_dirty(self):
|
def test_update_not_dirty(self):
|
||||||
self.sot._body = mock.Mock()
|
self.sot._body = mock.Mock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user