Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_mutating_roles(self):
with self.recorder:
self.assertIsInstance(self.user.roles, EntityManager)
with self.assertRaises(InvalidOrganization):
self.user.associate_with_organization_role('DefaultBroken', 'Read')
with self.assertRaises(InvalidRole):
self.user.associate_with_organization_role('Default', 'ReadBroken')
self.user.associate_with_organization_role('Default', 'Read')
self.assertTrue('Read' in [role.name for role in self.user.roles])
with self.assertRaises(InvalidOrganization):
self.user.disassociate_from_organization_role('DefaultBroken', 'Read')
with self.assertRaises(InvalidRole):
self.user.disassociate_from_organization_role('Default', 'ReadBroken')
self.user.disassociate_from_organization_role('Default', 'Read')
self.assertTrue('Read' not in [role.name for role in self.user.roles])
def test_mutating_organization(self):
with self.recorder:
original_organization = self.team.organization
with self.assertRaises(InvalidOrganization):
self.team.organization = 'NoOrgBroken'
self.team.organization = 'Default'
self.assertEqual(self.team.organization.name, 'Default')
self.team.organization = original_organization.name
self.assertEqual(self.team.organization.name, original_organization.name)
"""Retrieves an inventory by name from an organization.
Args:
organization: The name of the organization to retrieve the inventory from.
name: The name of the inventory to retrieve.
Returns:
Inventory: The inventory if a match is found else None.
Raises:
InvalidOrganization: The organization provided as argument does not exist.
"""
organization_ = self.get_organization_by_name(organization)
if not organization_:
raise InvalidOrganization(organization)
return organization_.get_inventory_by_name(name)
__author__ = '''Costas Tyfoxylos '''
__docformat__ = '''google'''
__date__ = '''2018-01-02'''
__copyright__ = '''Copyright 2018, Costas Tyfoxylos'''
__license__ = '''MIT'''
__maintainer__ = '''Costas Tyfoxylos'''
__email__ = ''''''
__status__ = '''Development''' # "Prototype", "Development", "Production".
# This is to 'use' the module(s), so lint doesn't complain
assert __version__
# assert exceptions
assert AuthFailed
assert InvalidUserLevel
assert InvalidOrganization
assert InvalidVariables
assert InvalidInventory
assert InvalidUser
assert InvalidTeam
assert InvalidCredential
assert InvalidGroup
assert InvalidHost
assert InvalidProject
assert InvalidCredentialType
assert InvalidPlaybook
assert InvalidInstanceGroup
assert InvalidJobType
assert InvalidVerbosity
assert InvalidJobTemplate
assert PermissionNotFound
assert InvalidValue
Args:
organization: The name of the organization the inventory belongs to.
inventory: The inventory to retrieve the group from.
name: The name of the group to retrieve.
Returns:
Group: The group if a match is found else None.
Raises:
InvalidOrganization: The organisation provided as an argument does not exist.
InvalidInventory: The inventory name provided as an argument does not exist.
"""
organization_ = self.get_organization_by_name(organization)
if not organization_:
raise InvalidOrganization(organization_)
inventory_ = organization_.get_inventory_by_name(inventory)
if not inventory_:
raise InvalidInventory(inventory_)
return inventory_.get_group_by_name(name)
Args:
organization (str): The organization that owns the credential.
name (str): The name of the credential(s) to retrieve.
credential_type_id (int): The integer of the type of the credential.
Returns:
Credential: A credential if found else None.
Raises:
InvalidOrganization: The Organization given was not found.
"""
# return self.credentials.filter({'name__iexact': name})
organization_ = self.get_organization_by_name(organization)
if not organization_:
raise InvalidOrganization(organization)
return next(self.credentials.filter({'organization': organization_.id,
'name__iexact': name,
'credential_type': credential_type_id}), None)
def organization(self, value):
"""Update the organization of the team.
Returns:
None:
"""
organization = self._tower.get_organization_by_name(value)
if not organization:
raise InvalidOrganization(value)
self._update_values('organization', organization.id)
script):
"""Creates a custom inventory script.
Args:
organization: The organization the inventory script is part of.
name: Name of the inventory script.
description: The description of the inventory script.
script: The script of the inventory script.
Returns:
Inventory_script: The created inventory script is successful, None otherwise.
"""
organization_ = self.get_organization_by_name(organization)
if not organization_:
raise InvalidOrganization(organization)
return organization_.create_inventory_script(name, description, script)
def organization(self, value):
"""Update the organization of the inventory.
Returns:
None:
"""
organization = self._tower.get_organization_by_name(value)
if not organization:
raise InvalidOrganization(value)
self._update_values('organization', organization.id)