Skip to content

Commit

Permalink
flake8 fixes, PR comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
lhellebr authored and JacobCallahan committed Oct 26, 2020
1 parent b2a64ee commit 24b389a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nailgun/entity_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ class EntityUpdateMixin(object):
:meth:`update_payload`
Assemble a payload of data that can be encoded and sent to the
server.
Set self.updatable_fields (list of strings) to limit the fields that can be updated.
:meth:`update_raw`
Make an HTTP PUT request to the server, including the payload.
:meth:`update_json`
Expand All @@ -979,8 +980,7 @@ def update_payload(self, fields=None):
"""
values = self.get_values()
updatable_fields =( self.updatable_fields if hasattr(self, 'updatable_fields') else
values.keys() )
updatable_fields = getattr(self, 'updatable_fields', None) or list(values.keys())
values = {field: value for field, value in values.items() if field in updatable_fields}
if fields is not None:
values = {field: values[field] for field in fields}
Expand Down
11 changes: 11 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,17 @@ def test_media_path(self):
self.assertNotIn('path_', payload['medium'])
self.assertIn('path', payload['medium'])

def test_hostcollection_updatable_fields(self):
org1 = entities.Organization(self.cfg, name='org1')
org2 = entities.Organization(self.cfg, name='org2')
host_collection = entities.HostCollection(self.cfg, name='oldname', organization=org1)
host_collection.name = 'newname'
host_collection.organization_id = org2
payload = host_collection.update_payload()
self.assertEquals(payload['name'], 'newname')
self.assertNotIn('organization', payload.keys()) # organization NOT changed
self.assertNotIn('organization_id', payload.keys()) # organization NOT changed

def test_job_template(self):
"""Create a :class:`nailgun.entities.JobTemplate`."""
payload = entities.JobTemplate(
Expand Down

0 comments on commit 24b389a

Please sign in to comment.