diff --git a/nailgun/entities.py b/nailgun/entities.py index dc1c90c5..f4b3783e 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -1854,7 +1854,12 @@ def create_missing(self): ) -class Location(Entity, EntityCreateMixin, EntityDeleteMixin, EntityReadMixin): +class Location( + Entity, + EntityCreateMixin, + EntityDeleteMixin, + EntityReadMixin, + EntityUpdateMixin): """A representation of a Location entity.""" def __init__(self, server_config=None, **kwargs): @@ -1919,6 +1924,23 @@ def read(self, entity=None, attrs=None, ignore=('realm',)): """ return super(Location, self).read(entity, attrs, ignore) + def update(self, fields=None): + """Fetch a complete set of attributes for this entity. + + Beware of `Bugzilla #1236008 + `_: + "Cannot use HTTP PUT to associate location with media" + + """ + self.update_json(fields) + return self.read() + + def update_payload(self, fields=None): + """Wrap submitted data within an extra dict.""" + return { + u'location': super(Location, self).update_payload(fields) + } + class Media( Entity, EntityCreateMixin, EntityDeleteMixin, EntityReadMixin): diff --git a/tests/test_entities.py b/tests/test_entities.py index d4ed50d9..8e9f022d 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -842,6 +842,7 @@ def test_generic(self): entities.ConfigTemplate(self.cfg), entities.Domain(self.cfg), entities.Host(self.cfg), + entities.Location(self.cfg), entities.Organization(self.cfg), entities.User(self.cfg), ) @@ -884,6 +885,7 @@ def setUpClass(cls): def test_generic(self): """Instantiate a variety of entities and call ``create_payload``.""" class_response = [ + (entities.Location, {'location': {}}), (entities.Organization, {'organization': {}}), (entities.User, {'user': {}}), ]