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_organizations(self):
with self.recorder:
self.assertIsInstance(self.tower.organizations, EntityManager)
default_org = self.tower.get_organization_by_name('Default')
self.assertIsInstance(default_org, Organization)
self.assertTrue(default_org.name == self.tower.get_organization_by_id(default_org.id).name)
def test_organization_lifecycle(self):
with self.recorder:
org = self.tower.create_organization('Test_Org', 'Test Org description')
self.assertIsInstance(org, Organization)
self.assertIsNone(self.tower.create_organization('Test_Org', 'Test Org description'))
self.assertTrue(self.tower.delete_organization('Test_Org'))
with self.assertRaises(InvalidOrganization):
self.assertFalse(self.tower.delete_organization('Test_Org'))
assert InvalidGroup
assert InvalidHost
assert InvalidProject
assert InvalidCredentialType
assert InvalidPlaybook
assert InvalidInstanceGroup
assert InvalidJobType
assert InvalidVerbosity
assert InvalidJobTemplate
assert PermissionNotFound
assert InvalidValue
assert InvalidRole
# assert objects
assert Tower
assert Organization
assert User
assert Role
assert Team
assert Project
assert Group
assert Inventory
assert Host
assert Instance
assert InstanceGroup
assert CredentialType
assert Credential
assert InventorySource
Args:
name: The name of the organization to create.
description: The description of the organization to create.
Returns:
Organization: The organization on success, None otherwise.
"""
url = '{api}/organizations/'.format(api=self.api)
payload = {'name': name,
'description': description}
response = self.session.post(url, json=payload)
if not response.ok:
self._logger.error('Error creating organization, response was: "%s"', response.text)
return Organization(self, response.json()) if response.ok 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)
user = self.create_user(username,
password,
first_name=first_name,
last_name=last_name,
email=email)
if not user:
return False
user.associate_with_organization_role(organization, Organization.DEFAULT_MEMBER_ROLE)
return user