Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #708 from pilou-/handle_admin_roles_with_space
Browse files Browse the repository at this point in the history
grant role to user: handle admin roles with space
  • Loading branch information
AlanCoding authored Jun 26, 2019
2 parents a2b151f + 059c195 commit fa54024
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/test_resources_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ def test_data_endpoint_inventory_ignore(self):
self.assertIn('members__in', data)
self.assertEqual(endpoint, '/roles/')

def test_data_endpoint_inventory_admin(self):
"""Translation of input args to lookup args, space in type"""
kwargs = {'user': 2, 'type': 'Inventory Admin', 'inventory': 5}
data, endpoint = Role.data_endpoint(kwargs, ignore=['res'])
self.assertIn('members__in', data)
self.assertEqual(endpoint, '/roles/')
self.assertIn('role_field', data)
self.assertEqual(data['role_field'], 'inventory_admin_role')


class RoleMethodTests(unittest.TestCase):
"""Test role commands."""
Expand Down
2 changes: 1 addition & 1 deletion tower_cli/resources/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def data_endpoint(cls, in_data, ignore=[]):
else:
endpoint = '/roles/'
if in_data.get('type', False):
data['role_field'] = '%s_role' % in_data['type'].lower()
data['role_field'] = '%s_role' % in_data['type'].replace(' ', '_').lower()
# Add back fields unrelated to role lookup, such as all_pages
for key, value in in_data.items():
if key not in RESOURCE_FIELDS and key not in ['type', 'user', 'team']:
Expand Down

0 comments on commit fa54024

Please sign in to comment.