def pytest_generate_tests(metafunc): argnames, argvalues, idlist = testgen.providers_by_class( metafunc, [VMwareProvider]) argnames = argnames + ["_host_provider"] new_idlist = [] new_argvalues = [] for i, argvalue_tuple in enumerate(argvalues): args = dict(zip(argnames, argvalue_tuple)) # TODO # All this should be replaced with a proper ProviderFilter passed to testgen.providers() if args['provider'].type != "virtualcenter": continue hosts = args['provider'].data.get("hosts", []) if not hosts: continue version = args['provider'].data.get("version") if version is None: # No version, no test continue if Version(version) < "5.0": # Ignore lesser than 5 continue host = hosts[0] ip_address = resolve_hostname(host["name"]) endpoint = VirtualCenterEndpoint( credentials=host["credentials"]["default"], hostname=host["name"], ip_address=ip_address) # Mock provider data provider_data = {} provider_data.update(args['provider'].data) provider_data["name"] = host["name"] provider_data["hostname"] = host["name"] provider_data["ipaddress"] = ip_address provider_data.pop("host_provisioning", None) provider_data["hosts"] = [host] provider_data["discovery_range"] = {} provider_data["discovery_range"]["start"] = ip_address provider_data["discovery_range"]["end"] = ip_address appliance = find_appliance(metafunc, require=False) host_provider = appliance.collections.infra_providers.instantiate( prov_class=VMwareProvider, name=host["name"], endpoints=endpoint, provider_data=provider_data) argvalues[i].append(host_provider) idlist[i] = "{}/{}".format(args['provider'].key, host["name"]) new_idlist.append(idlist[i]) new_argvalues.append(argvalues[i]) testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
def test_host_name_max_character_validation_infra(): """Test to validate max character for host name field""" endpoint = VirtualCenterEndpoint(hostname=fauxfactory.gen_alphanumeric(256)) prov = VMwareProvider(name=fauxfactory.gen_alphanumeric(5), endpoints=endpoint) try: prov.create() except AssertionError: view = prov.create_view(prov.endpoints_form) assert view.hostname.value == prov.hostname[0:255]
def test_name_required_validation_infra(): """Tests to validate the name while adding a provider""" endpoint = VirtualCenterEndpoint(hostname=fauxfactory.gen_alphanumeric(5)) prov = VMwareProvider(name=None, endpoints=endpoint) with pytest.raises(AssertionError): prov.create() view = prov.create_view(InfraProviderAddView) assert view.name.help_block == "Required" assert not view.add.active
def test_name_required_validation_infra(appliance): """Tests to validate the name while adding a provider""" collections = appliance.collections.infra_providers endpoint = VirtualCenterEndpoint(hostname=fauxfactory.gen_alphanumeric(5)) with pytest.raises(AssertionError): collections.create(prov_class=VMwareProvider, name=None, endpoints=endpoint) view = appliance.browser.create_view(InfraProviderAddView) assert view.name.help_block == "Required" assert not view.add.active
def test_host_name_max_character_validation_infra(appliance): """Test to validate max character for host name field""" endpoint = VirtualCenterEndpoint(hostname=fauxfactory.gen_alphanumeric(256)) collections = appliance.collections.infra_providers prov = collections.instantiate(prov_class=VMwareProvider, name=fauxfactory.gen_alphanumeric(5), endpoints=endpoint) try: prov.create() except AssertionError: view = appliance.browser.create_view(prov.endpoints_form) assert view.hostname.value == prov.hostname[0:255]
def test_infrastructure_add_provider_trailing_whitespaces(): """Test to validate the hostname and username should be without whitespaces""" credentials = Credential(principal="test test", secret=fauxfactory.gen_alphanumeric(5)) endpoint = VirtualCenterEndpoint(hostname="test test", credentials=credentials) prov = VMwareProvider(name=fauxfactory.gen_alphanumeric(5), endpoints=endpoint) with pytest.raises(AssertionError): prov.create() view = prov.create_view(prov.endpoints_form) assert view.hostname.help_block == "Spaces are prohibited" assert view.username.help_block == "Spaces are prohibited" view = prov.create_view(InfraProviderAddView) assert not view.add.active
def test_host_name_required_validation(): """Test to validate the hostname while adding a provider""" endpoint = VirtualCenterEndpoint(hostname=None) prov = VMwareProvider(name=fauxfactory.gen_alphanumeric(5), endpoints=endpoint) err = FlashMessageException with error.expected(err): prov.create() view = prov.create_view(prov.endpoints_form) assert view.hostname.help_block == "Required" view = prov.create_view(ProviderAddView) assert not view.add.active
def test_name_required_validation(): """Tests to validate the name while adding a provider""" endpoint = VirtualCenterEndpoint(hostname=fauxfactory.gen_alphanumeric(5)) prov = VMwareProvider(name=None, endpoints=endpoint) err = version.pick({ version.LOWEST: "Name can't be blank", '5.6': FlashMessageException }) with error.expected(err): prov.create() view = prov.create_view(ProviderAddView) assert view.name.help_block == "Required" assert not view.add.active
def test_host_name_required_validation_infra(appliance): """Test to validate the hostname while adding a provider Polarion: assignee: pvala initialEstimate: 1/15h """ endpoint = VirtualCenterEndpoint(hostname=None) collections = appliance.collections.infra_providers prov = collections.instantiate(prov_class=VMwareProvider, name=fauxfactory.gen_alphanumeric(5), endpoints=endpoint) with pytest.raises(AssertionError): prov.create() view = appliance.browser.create_view(prov.endpoints_form) assert view.hostname.help_block == "Required" view = appliance.browser.create_view(InfraProviderAddView) assert not view.add.active
def test_infrastructure_add_provider_trailing_whitespaces(appliance): """Test to validate the hostname and username should be without whitespaces Polarion: assignee: mmojzis casecomponent: Infra caseimportance: low initialEstimate: 1/8h """ collections = appliance.collections.infra_providers credentials = Credential(principal="test test", secret=fauxfactory.gen_alphanumeric(5)) endpoint = VirtualCenterEndpoint(hostname="test test", credentials=credentials) prov = collections.instantiate(prov_class=VMwareProvider, name=fauxfactory.gen_alphanumeric(5), endpoints=endpoint) with pytest.raises(AssertionError): prov.create() view = appliance.browser.create_view(prov.endpoints_form) assert view.hostname.help_block == "Spaces are prohibited" assert view.username.help_block == "Spaces are prohibited" view = appliance.browser.create_view(InfraProviderAddView) assert not view.add.active