def test_negative_list_with_non_existing_org_and_loc_by_name(self): """Test Environment List filtering parameters validation. :id: 38cb48e3-a836-47d0-b8a8-9acd33a30546 :expectedresults: Server returns empty result as there is no environment associated with location :CaseLevel: Integration :BZ: 1337947 """ # Create env with specified organization and location org = make_org() loc = make_location() make_environment({ 'organizations': org['name'], 'locations': loc['name'], }) # Filter by non-existing location and existing organization with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization': org['name'], 'location': gen_string('alpha') }) # Filter by non-existing organization and existing location with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization': gen_string('alpha'), 'location': loc['name'] })
def test_negative_list_with_parameters(self): """Test Environment List filtering parameters validation. :id: 97872953-e1aa-44bd-9ce0-a04bccbc9e94 :expectedresults: Server returns empty result as there is no environment associated with location :CaseLevel: Integration :BZ: 1337947 """ make_environment({ 'organization-ids': self.org.id, 'location-ids': self.loc.id, }) # Filter by non-existing location and existing organization with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization-id': self.org.id, 'location-id': gen_string('numeric') }) # Filter by non-existing organization and existing location with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization-id': gen_string('numeric'), 'location-id': self.loc.id }) # Filter by another location results = Environment.list({ 'organization': self.org.name, 'location': self.loc2.name }) self.assertEqual(len(results), 0)
def test_negative_list_with_non_existing_org_and_loc_by_id(self): """Test Environment List filtering parameters validation. :id: 97872953-e1aa-44bd-9ce0-a04bccbc9e94 :expectedresults: Server returns empty result as there is no environment associated with location :CaseLevel: Integration :BZ: 1337947 """ # Create env with specified organization and location org = make_org() loc = make_location() make_environment({ 'organization-ids': org['id'], 'location-ids': loc['id'], }) # Filter by non-existing location and existing organization with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization-id': org['id'], 'location-id': gen_string('numeric') }) # Filter by non-existing organization and existing location with self.assertRaises(CLIReturnCodeError): Environment.list({ 'organization-id': gen_string('numeric'), 'location-id': loc['id'] })
def test_update_organization(self): """@Test: Update environment organization with new value @Feature: Environment - Update @Assert: Environment Update finished and new organization is assigned """ try: old_org = make_org() new_org = make_org() env_name = gen_string('alphanumeric', 10) make_environment({ 'name': env_name, 'organization-ids': old_org['id'], }) except CLIFactoryError as err: self.fail(err) result = Environment.info({'name': env_name}) self.assertIn(old_org['name'], result.stdout['organizations']) result = Environment.update({ 'name': env_name, 'organization-ids': new_org['id'] }) self.assertEqual(result.return_code, 0) result = Environment.info({'name': env_name}) self.assertIn(new_org['name'], result.stdout['organizations']) self.assertNotIn(old_org['name'], result.stdout['organizations'])
def test_negative_list_with_org_and_loc_by_id(self): """Test Environment List filtering. :id: b1659c48-302b-4fe3-a38b-cd34c0fd4878 :expectedresults: Server returns empty result as there is no environment associated with location or organization :CaseLevel: Integration :BZ: 1337947 """ # Create env with specified organization and location org = make_org() locs = [make_location() for _ in range(2)] make_environment({ 'organization-ids': org['id'], 'location-ids': locs[0]['id'], }) # But filter by another location results = Environment.list({ 'organization-id': org['id'], 'location-id': locs[1]['id'], }) self.assertEqual(len(results), 0)
def test_negative_list_with_org_and_loc_by_name(self): """Test Environment List filtering. :id: b8382ebb-ffa3-4637-b3b4-444af6c2fe9b :expectedresults: Server returns empty result as there is no environment associated with location or organization :CaseLevel: Integration :BZ: 1337947 """ # Create env with specified organization and location org = make_org() locs = [make_location() for _ in range(2)] make_environment({ 'organizations': org['name'], 'locations': locs[0]['name'], }) # But filter by another location results = Environment.list({ 'organization': org['name'], 'location': locs[1]['name'], }) self.assertEqual(len(results), 0)
def test_delete(self): """@Test: Delete the environment @Feature: Environment - Delete @Assert: Environment Delete is displayed """ name = gen_string("alphanumeric", 10) try: make_environment({'name': name}) except CLIFactoryError as err: self.fail(err) result = Environment().delete({'name': name}) self.assertEqual(result.return_code, 0, "Deletion failed") self.assertEqual( len(result.stderr), 0, "There should not be an error here") result = Environment().info({'name': name}) self.assertNotEqual( result.return_code, 0, "Environment should be deleted") self.assertGreater(len(result.stderr), 0, "There should be an exception here")
def test_update(self, test_data): """@Test: Update the environment @Feature: Environment - Update @Assert: Environment Update is displayed """ orig_dict, updates_dict = test_data try: make_environment({'name': orig_dict['name']}) except CLIFactoryError as err: self.fail(err) result = Environment.update({ 'name': orig_dict['name'], 'new-name': updates_dict['new-name'] }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) result = Environment.info({'name': updates_dict['new-name']}) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) self.assertEqual(result.stdout['name'], updates_dict['new-name'])
def test_delete(self): """@Test: Delete the environment @Feature: Environment - Delete @Assert: Environment Delete is displayed """ name = gen_string('alphanumeric', 10) make_environment({'name': name}) Environment().delete({'name': name}) with self.assertRaises(CLIReturnCodeError): Environment().info({'name': name})
def test_positive_list_with_org_and_loc_by_name(self): """Test Environment List filtering. :id: 962c6750-f203-4478-8827-651db208ff92 :expectedresults: Results that match both organization and location are returned :CaseLevel: Integration :BZ: 1337947 """ # Create 2 envs with the same organization but different locations org = make_org() locs = [make_location() for _ in range(2)] envs = [ make_environment({ 'organizations': org['name'], 'locations': loc['name'], }) for loc in locs ] results = Environment.list({'organization': org['name']}) # List environments for the whole organization self.assertEqual(len(results), 2) self.assertEqual({env['name'] for env in envs}, {result['name'] for result in results}) # List environments with additional location filtering results = Environment.list({ 'organization': org['name'], 'location': locs[0]['name'], }) self.assertEqual(len(results), 1) self.assertEqual(results[0]['name'], envs[0]['name'])
def test_positive_update_org(self): """Update environment organization with new value :id: 2c40caf9-95a0-4b87-bd97-0a4448746052 :expectedresults: Environment Update finished and new organization is assigned :CaseImportance: Critical """ old_org = make_org() new_org = make_org() env_name = gen_string('alphanumeric', 10) env = make_environment({ 'name': env_name, 'organization-ids': old_org['id'], }) self.assertIn(old_org['name'], env['organizations']) Environment.update({ 'name': env_name, 'organization-ids': new_org['id'] }) env = Environment.info({'name': env_name}) self.assertIn(new_org['name'], env['organizations']) self.assertNotIn(old_org['name'], env['organizations'])
def test_positive_list_with_org_and_loc_by_id(self): """Test Environment List filtering. :id: 643f7cb5-0817-4b0a-ba5e-434df2033a40 :expectedresults: Results that match both organization and location are returned :CaseLevel: Integration :BZ: 1337947 """ # Create 2 envs with the same organization but different locations org = make_org() locs = [make_location() for _ in range(2)] envs = [make_environment({ 'organization-ids': org['id'], 'location-ids': loc['id'], }) for loc in locs] results = Environment.list({'organization-id': org['id']}) # List environments for the whole organization self.assertEqual(len(results), 2) self.assertEqual( {env['id'] for env in envs}, {result['id'] for result in results} ) # List environments with additional location filtering results = Environment.list({ 'organization-id': org['id'], 'location-id': locs[0]['id'], }) self.assertEqual(len(results), 1) self.assertEqual(results[0]['id'], envs[0]['id'])
def test_update_negative(self, test_data): """@Test: Update the environment with invalid values @Feature: Environment - Update @Assert: Environment is not updated """ orig_dict, updates_dict = test_data try: env = make_environment({'name': orig_dict['name']}) except CLIFactoryError as err: self.fail(err) result = Environment.update({ 'name': orig_dict['name'], 'new-name': updates_dict['new-name'] }) self.assertNotEqual(result.return_code, 0) self.assertNotEqual(len(result.stderr), 0) result = Environment.info({'id': env['id']}) # Verify that value is not updated and left as it was before update # command was executed self.assertEqual(result.stdout['name'], orig_dict['name']) self.assertNotEqual(result.stdout['name'], updates_dict['new-name'])
def test_update(self, new_name): """@Test: Update the environment @Feature: Environment - Update @Assert: Environment Update is displayed """ name = gen_string('alphanumeric') make_environment({'name': name}) Environment.update({ 'name': name, 'new-name': new_name, }) env = Environment.info({'name': new_name}) self.assertEqual(env['name'], new_name)
def test_positive_list_with_org_and_loc_by_id(self): """Test Environment List filtering. :id: 643f7cb5-0817-4b0a-ba5e-434df2033a40 :expectedresults: Results that match both organization and location are returned :CaseLevel: Integration :BZ: 1337947 """ # Create 2 envs with the same organization but different locations org = make_org() locs = [make_location() for _ in range(2)] envs = [ make_environment({ 'organization-ids': org['id'], 'location-ids': loc['id'], }) for loc in locs ] results = Environment.list({'organization-id': org['id']}) # List environments for the whole organization self.assertEqual(len(results), 2) self.assertEqual({env['id'] for env in envs}, {result['id'] for result in results}) # List environments with additional location filtering results = Environment.list({ 'organization-id': org['id'], 'location-id': locs[0]['id'], }) self.assertEqual(len(results), 1) self.assertEqual(results[0]['id'], envs[0]['id'])
def test_positive_list_with_org_and_loc_by_name(self): """Test Environment List filtering. :id: 962c6750-f203-4478-8827-651db208ff92 :expectedresults: Results that match both organization and location are returned :CaseLevel: Integration :BZ: 1337947 """ # Create 2 envs with the same organization but different locations org = make_org() locs = [make_location() for _ in range(2)] envs = [make_environment({ 'organizations': org['name'], 'locations': loc['name'], }) for loc in locs] results = Environment.list({'organization': org['name']}) # List environments for the whole organization self.assertEqual(len(results), 2) self.assertEqual( {env['name'] for env in envs}, {result['name'] for result in results} ) # List environments with additional location filtering results = Environment.list({ 'organization': org['name'], 'location': locs[0]['name'], }) self.assertEqual(len(results), 1) self.assertEqual(results[0]['name'], envs[0]['name'])
def test_positive_CRUD_with_attributes(module_org, module_locs): """Check if Environment with attributes can be created, updated and removed :id: d2187971-86b2-40c9-a93c-66f37691ae2b :BZ: 1337947 :expectedresults: 1. Environment is created and has parameters assigned 2. Environment can be listed by parameters 3. Environment can be updated 4. Environment can be removed :CaseImportance: Critical """ # Create with attributes env_name = gen_string('alpha') environment = make_environment( {'location-ids': module_locs[0].id, 'organization-ids': module_org.id, 'name': env_name} ) assert module_locs[0].name in environment['locations'] assert module_org.name in environment['organizations'] assert env_name == environment['name'] # List by name result = Environment.list({'search': f'name={env_name}'}) assert len(result) == 1 assert result[0]['name'] == env_name # List by org loc id results = Environment.list({'organization-id': module_org.id, 'location-id': module_locs[0].id}) assert env_name in [res['name'] for res in results] # List by org loc name results = Environment.list({'organization': module_org.name, 'location': module_locs[0].name}) assert env_name in [res['name'] for res in results] # Update org and loc new_org = entities.Organization().create() Environment.update( { 'location-ids': module_locs[1].id, 'organization-ids': new_org.id, 'name': environment['name'], } ) env_info = Environment.info({'name': environment['name']}) assert module_locs[1].name in env_info['locations'] assert module_locs[0].name not in env_info['locations'] assert new_org.name in env_info['organizations'] assert module_org.name not in env_info['organizations'] # Update name new_env_name = gen_string('alpha') Environment.update({'id': environment['id'], 'new-name': new_env_name}) env_info = Environment.info({'id': environment['id']}) assert env_info['name'] == new_env_name # Delete Environment.delete({'id': environment['id']}) with pytest.raises(CLIReturnCodeError): Environment.info({'id': environment['id']})
def _environment(request): environment = make_environment() @request.addfinalizer def _cleanup(): if Environment.exists(search=('name', environment['name'])): Environment.delete(options={'id': environment['id']}) return environment
def test_add_environment(self): "Adds an environment to an org" org_result = make_org() env_result = make_environment() return_value = Org().add_environment({ 'name': org_result['name'], 'environment': env_result['name']}) self.assertTrue(return_value.return_code, 0) self.assertFalse(return_value.stderr)
def test_positive_delete_by_name(self): """Delete the environment by its name. @id: 48765173-6086-4b91-9da7-594135f68751 @Assert: Environment is deleted. """ environment = make_environment() Environment.delete({'name': environment['name']}) with self.assertRaises(CLIReturnCodeError): Environment.info({'name': environment['name']})
def test_positive_sc_params_by_name(self): """Check if environment sc-param subcommand works passing an environment name @id: e2fdd262-9b09-4252-8a5a-4e578e3b8547 @Assert: The command runs without raising an error """ environment = make_environment() Environment.sc_params({'environment': environment['name']})
def test_positive_sc_params_by_id(self): """Check if environment sc-param subcommand works passing an environment id @id: 32de4f0e-7b52-411c-a111-9ed472c3fc34 @Assert: The command runs without raising an error """ environment = make_environment() Environment.sc_params({'environment-id': environment['id']})
def test_positive_create_with_env(self): """Check if hostgroup with environment can be created @id: f1bfb333-90cf-4a9f-b183-cf77c1773247 @Assert: Hostgroup is created and has new environment assigned """ environment = make_environment() hostgroup = make_hostgroup({'environment-id': environment['id']}) self.assertEqual(environment['name'], hostgroup['environment'])
def test_positive_create_with_name(self): """Successfully creates an Environment. @id: 3b22f035-ee3a-489e-89c5-e54571584af1 @Assert: Environment is created. """ for name in valid_environments_list(): with self.subTest(name): environment = make_environment({'name': name}) self.assertEqual(environment['name'], name)
def test_positive_create_with_name(self): """Successfully creates an Environment. @Feature: Environment @Assert: Environment is created. """ for name in valid_environments_list(): with self.subTest(name): environment = make_environment({'name': name}) self.assertEqual(environment['name'], name)
def test_positive_create_with_env(self): """Check if hostgroup with environment can be created @Feature: Hostgroup - Positive create @Assert: Hostgroup is created and has new environment assigned """ environment = make_environment() hostgroup = make_hostgroup({'environment-id': environment['id']}) self.assertEqual(environment['name'], hostgroup['environment'])
def test_positive_sc_params_by_name(self): """Check if environment sc-param subcommand works passing an environment name @Feature: Environment @Assert: The command runs without raising an error """ environment = make_environment() Environment.sc_params({'environment': environment['name']})
def test_positive_delete_by_name(self): """Delete the environment by its name. @Feature: Environment @Assert: Environment is deleted. """ environment = make_environment() Environment.delete({'name': environment['name']}) with self.assertRaises(CLIReturnCodeError): Environment.info({'name': environment['name']})
def test_create_hostgroup_with_environment(self): """@Test: Check if hostgroup with environment can be created @Feature: Hostgroup - Positive create @Assert: Hostgroup is created and has new environment assigned """ environment = make_environment() hostgroup = make_hostgroup({'environment-id': environment['id']}) self.assertEqual(environment['name'], hostgroup['environment'])
def test_info(self): """@Test: Test Environment Info @Feature: Environment - Info @Assert: Environment Info is displayed """ name = gen_string('alpha', 10) env = make_environment({'name': name}) self.assertEquals(env['name'], name)
def test_positive_create_with_env(self): """Check if hostgroup with environment can be created :id: f1bfb333-90cf-4a9f-b183-cf77c1773247 :expectedresults: Hostgroup is created and has new environment assigned :CaseLevel: Integration """ environment = make_environment() hostgroup = make_hostgroup({'environment-id': environment['id']}) self.assertEqual(environment['name'], hostgroup['puppet-environment'])
def test_positive_delete_by_name(self): """Delete the environment by its name. :id: 48765173-6086-4b91-9da7-594135f68751 :expectedresults: Environment is deleted. :CaseImportance: Critical """ environment = make_environment() Environment.delete({'name': environment['name']}) with self.assertRaises(CLIReturnCodeError): Environment.info({'name': environment['name']})
def test_create_location_with_environment_by_name(self): """@Test: Create new location with assigned environment to it. Use environment name as a parameter @Feature: Location @Assert: Location created successfully and has correct and expected environment assigned to it """ env = make_environment() loc = make_location({'environments': env['name']}) self.assertEqual(loc['environments'][0], env['name'])
def test_positive_create_with_name(self): """Successfully creates an Environment. :id: 3b22f035-ee3a-489e-89c5-e54571584af1 :expectedresults: Environment is created. :CaseImportance: Critical """ for name in valid_environments_list(): with self.subTest(name): environment = make_environment({'name': name}) self.assertEqual(environment['name'], name)
def test_positive_create_with_environment_by_name(self): """Create new location with assigned environment to it. Use environment name as a parameter @Feature: Location @Assert: Location created successfully and has correct and expected environment assigned to it """ env = make_environment() loc = make_location({'environments': env['name']}) self.assertEqual(loc['environments'][0], env['name'])
def test_positive_create_with_environment_by_id(self): """Create new location with assigned environment to it. Use environment id as a parameter @id: cd38b895-57f7-4d07-aa4b-7299a69ec203 @Assert: Location created successfully and has correct and expected environment assigned to it """ env = make_environment() loc = make_location({'environment-ids': env['id']}) self.assertEqual(loc['environments'][0], env['name'])
def test_positive_create_with_env(self): """Check if hostgroup with environment can be created :id: f1bfb333-90cf-4a9f-b183-cf77c1773247 :expectedresults: Hostgroup is created and has new environment assigned :CaseImportance: Critical """ environment = make_environment() hostgroup = make_hostgroup({'environment-id': environment['id']}) self.assertEqual(environment['name'], hostgroup['puppet-environment'])
def test_positive_create_with_environment_by_name(self): """Create new location with assigned environment to it. Use environment name as a parameter @id: 3c9a47b5-798b-4f41-a9dc-219ad43b6fdf @Assert: Location created successfully and has correct and expected environment assigned to it """ env = make_environment() loc = make_location({'environments': env['name']}) self.assertEqual(loc['environments'][0], env['name'])
def test_positive_create_with_org(self): """Check if Environment with Organization can be created @id: 9fd9d2d5-db46-40a7-b341-41cdbde4356a @Assert: Environment is created and has new Organization assigned """ new_org = make_org() new_environment = make_environment({ 'name': gen_string('alpha'), 'organization-ids': new_org['id'], }) self.assertIn(new_org['name'], new_environment['organizations'])
def test_positive_create_with_environment_by_name(self): """Create new location with assigned environment to it. Use environment name as a parameter :id: 3c9a47b5-798b-4f41-a9dc-219ad43b6fdf :expectedresults: Location created successfully and has correct and expected environment assigned to it :CaseImportance: Critical """ env = make_environment() loc = make_location({'environments': env['name']}) self.assertEqual(loc['environments'][0], env['name'])
def test_positive_delete_by_id(self): """Create Environment with valid values then delete it by ID @feature: Environment @assert: Environment is deleted """ for name in valid_environments_list(): with self.subTest(name): environment = make_environment({'name': name}) Environment.delete({'id': environment['id']}) with self.assertRaises(CLIReturnCodeError): Environment.info({'id': environment['id']})
def test_positive_create_with_loc(self): """Check if Environment with Location can be created @Feature: Environment - Create @Assert: Environment is created and has new Location assigned """ new_loc = make_location() new_environment = make_environment({ 'location-ids': new_loc['id'], 'name': gen_string('alpha'), }) self.assertIn(new_loc['name'], new_environment['locations'])
def test_positive_create_with_org(self): """Check if Environment with Organization can be created @Feature: Environment - Create @Assert: Environment is created and has new Organization assigned """ new_org = make_org() new_environment = make_environment({ 'name': gen_string('alpha'), 'organization-ids': new_org['id'], }) self.assertIn(new_org['name'], new_environment['organizations'])