def test_gcpconfig_from_configparser(): """Test GCPConfig initialized from a ConfigParser object""" PROJECT = 'test-project' REGION = 'test-region' ZONE = 'test-zone' NETWORK = 'network' SUBNET = 'subnet' confpars = configparser.ConfigParser() confpars[CFG_CLOUD_PROVIDER] = { CFG_CP_GCP_PROJECT: PROJECT, CFG_CP_GCP_REGION: REGION, CFG_CP_GCP_ZONE: ZONE, CFG_CP_GCP_NETWORK: NETWORK, CFG_CP_GCP_SUBNETWORK: SUBNET } cfg = GCPConfig.create_from_cfg(confpars) assert cfg.cloud == CSP.GCP assert cfg.project == PROJECT assert cfg.region == REGION assert cfg.zone == ZONE assert cfg.network == NETWORK assert cfg.subnet == SUBNET errors = [] cfg.validate(errors, ElbCommand.SUBMIT) assert not errors
def test_gcpconfig_from_configparser_missing(): """Test missing required parameters are reported when initializing GCPConfig from a ConfigParser object""" REQUIRED_PARAMS = [CFG_CP_GCP_PROJECT, CFG_CP_GCP_REGION, CFG_CP_GCP_ZONE] with pytest.raises(ValueError) as err: cfg = GCPConfig.create_from_cfg(configparser.ConfigParser()) for param in REQUIRED_PARAMS: assert 'Missing ' + param in str(err.value)
def test_gcpconfig_from_configparser_errors(): """Test that incorrect parameter values in ConfigParser are properly reported""" confpars = configparser.ConfigParser() confpars[CFG_CLOUD_PROVIDER] = { CFG_CP_GCP_PROJECT: 'inval!d-PROJECT', CFG_CP_GCP_REGION: 'invalie-rEg!on', CFG_CP_GCP_ZONE: 'inavlid-zone-@#$' } with pytest.raises(ValueError) as err: cfg = GCPConfig.create_from_cfg(confpars) # test that each invalid parameter value is reported errors = str(err.value).split('\n') for key in confpars[CFG_CLOUD_PROVIDER]: assert [ message for message in errors if key in message and 'invalid value' in message and confpars[CFG_CLOUD_PROVIDER][key] in message ]