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)
def test_mutating_name(self):
with self.recorder:
with self.assertRaises(InvalidValue):
self.team.name = 'a' * 513
original_name = self.team.name
self.team.name = 'valid_name'
self.assertEqual(self.team.name, 'valid_name')
self.team.name = original_name
self.assertEqual(self.team.name, original_name)
def test_hosts(self):
with self.recorder:
self.assertIsInstance(self.tower.hosts, EntityManager)
host_generator = self.tower.get_hosts_by_name('example.com')
host = list(host_generator)[0]
self.assertIsInstance(host, Host)
self.assertTrue(host.name == self.tower.get_host_by_id(host.id).name)
other_host = self.tower.get_inventory_host_by_name('workflow', 'Test Inventory', 'example.com')
self.assertTrue(host.name == other_host.name)
with self.assertRaises(InvalidInventory):
self.tower.get_inventory_host_by_name('workflow', 'Test Inventory Broken', 'example.com')
def test_roles(self):
with self.recorder:
self.assertIsInstance(self.team.roles, EntityManager)
def test_credentials(self):
with self.recorder:
self.assertIsInstance(self.user.credentials, EntityManager)
def test_organizations(self):
with self.recorder:
self.assertIsInstance(self.user.organizations, EntityManager)
def test_mutating_credential_permission(self):
with self.recorder:
credential = 'Test Credential'
credential_type = 'Source Control'
credential_broken = 'Test CredentialBroken'
with self.assertRaises(InvalidCredential):
self.team.add_credential_permission_admin(credential_broken, credential_type)
self.assertTrue(self.team.add_credential_permission_admin(credential, credential_type))
with self.assertRaises(InvalidCredential):
self.team.remove_credential_permission_admin(credential_broken, credential_type)
self.assertTrue(self.team.remove_credential_permission_admin(credential, credential_type))
with self.assertRaises(InvalidCredential):
self.team.add_credential_permission_use(credential_broken, credential_type)
self.assertTrue(self.team.add_credential_permission_use(credential, credential_type))
with self.assertRaises(InvalidCredential):
self.team.remove_credential_permission_use(credential_broken, credential_type)
self.assertTrue(self.team.remove_credential_permission_use(credential, credential_type))
'https://github.com/ansible/ansible-tower-samples')
self.assertIsInstance(project, Project)
url = 'https://github.com/ansible/ansible-tower-samples'
duplicate_project = self.tower.create_project_in_organization('Default',
'Project_name',
'description',
'Test Credential',
url)
self.assertFalse(duplicate_project)
with self.assertRaises(InvalidOrganization):
self.tower.create_project_in_organization('NoOrg',
'name',
'description',
'Test Credential',
'https://github.com/ansible/ansible-tower-samples')
with self.assertRaises(InvalidCredential):
self.tower.create_project_in_organization('Default',
'name',
'description',
'No Credential',
'https://github.com/ansible/ansible-tower-samples')
with Timeout(TIMEOUT_IN_SECONDS) as timeout:
while project.status != 'successful':
if timeout.reached:
raise TimeoutError
time.sleep(1)
self.assertTrue(self.tower.delete_organization_project('Default', 'Project_name'))
with self.assertRaises(InvalidOrganization):
self.tower.delete_organization_project('DefaultBroken', 'Project_name')
with self.assertRaises(InvalidProject):
self.tower.delete_organization_project('Default', 'Project_name')
self.assertIsNone(self.tower.create_credential_in_organization_with_type_id('workflow',
'CredName2',
'CredDescription',
'workflow_admin',
'workflow_team',
'2',
'{}'))
with self.assertRaises(InvalidOrganization):
self.tower.delete_organization_credential_by_name('workflowBroken',
'CredName',
'Source Control')
with self.assertRaises(InvalidCredentialType):
self.tower.delete_organization_credential_by_name('workflow',
'CredName',
'Source ControlBroken')
with self.assertRaises(InvalidCredential):
self.tower.delete_organization_credential_by_name('workflow',
'CredNameBroken',
'Source Control')
self.assertTrue(self.tower.delete_organization_credential_by_name('workflow',
'CredName',
'Source Control'))
with self.assertRaises(InvalidOrganization):
self.tower.delete_organization_credential_by_name_with_type_id('workflowBroken',
'CredName2',
'2')
with self.assertRaises(InvalidCredential):
self.tower.delete_organization_credential_by_name_with_type_id('workflow',
'CredNameBroken',
'2')
self.assertTrue(self.tower.delete_organization_credential_by_name_with_type_id('workflow',
'CredName2',