def test_helper_configuration(manager_with_spec, tempdir, monkeypatch): ''' Test writing an api with required user config to a config file and then running configure user_config with the flag --helper ''' # Create an insufficiently specified API api = DataAPI(username='******') # Attach a manager which requires username, contact api.attach_manager(manager_with_spec) # Export the API to a file config_file = os.path.join(tempdir, '.datafs.yml') to_config_file(api=api, config_file=config_file, profile='conftest') assert 'contact' not in api.user_config runner = CliRunner() prefix = ['--config-file', config_file, '--profile', 'conftest'] def get_user_email(*args, **kwargs): return "*****@*****.**" # override click.prompt monkeypatch.setattr('click.prompt', get_user_email) # Test the helper with the appropriate input stream result = runner.invoke(cli, prefix + ['configure', '--helper']) assert result.exit_code == 0 api2 = get_api(config_file=config_file, profile='conftest') assert api2.user_config['contact'] == "*****@*****.**"
def test_manual_configuration(manager_with_spec, tempdir): ''' Test writing an api with required user config to a config file and then running configure user_config specified as keyword arguments ''' # Create an insufficiently specified API api = DataAPI(username='******') # Attach a manager which requires username, contact api.attach_manager(manager_with_spec) # Export the API to a file config_file = os.path.join(tempdir, '.datafs.yml') to_config_file(api=api, config_file=config_file, profile='conftest') runner = CliRunner() prefix = ['--config-file', config_file, '--profile', 'conftest'] # Test the configuration and make sure an exception is raised result = runner.invoke( cli, prefix + ['configure', '--contact', '"*****@*****.**']) assert result.exit_code == 0
def test_sufficient_configuration(manager_with_spec, tempdir): ''' Test writing an api with required user config to a config file and then running configure. ''' # Create an appropriately specified API api = DataAPI(username='******', contact='*****@*****.**') # Attach a manager which requires username, contact api.attach_manager(manager_with_spec) # Export the API to a file config_file = os.path.join(tempdir, '.datafs.yml') to_config_file(api=api, config_file=config_file, profile='conftest') runner = CliRunner() prefix = ['--config-file', config_file, '--profile', 'conftest'] # Test the configuration result = runner.invoke(cli, prefix + ['configure']) if result.exit_code != 0: traceback.print_exception(*result.exc_info) raise OSError('Errors encountered during execution')
def test_config(api1_module, local_auth_module, temp_dir_mod): api1_module.attach_authority('local', local_auth_module) temp_file = os.path.join(temp_dir_mod, 'config.yml') to_config_file(api1_module, config_file=temp_file, profile='myapi') for i, j, k in itertools.product(*tuple([range(3) for _ in range(3)])): arch = 'team{}_archive{}_var{}'.format(i+1, j+1, k+1) api1_module.create( arch, tags=list(arch.split('_')), metadata={ 'description': 'archive_{}_{}_{} description'.format(i, j, k)}) yield 'myapi', temp_file