Skip to content

Commit

Permalink
Add entities.Location.update()
Browse files Browse the repository at this point in the history
Added entities.Location.update(), as it's needed for
SatelliteQE/robottelo/#2427 .
Also updated tests and submitted BZ1236008.
  • Loading branch information
Andrii Balakhtar committed Jun 26, 2015
1 parent 4c7a9e7 commit b9c3958
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 23 additions & 1 deletion nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
<https://bugzilla.redhat.com/show_bug.cgi?id=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):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down Expand Up @@ -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': {}}),
]
Expand Down

0 comments on commit b9c3958

Please sign in to comment.