def test_settings_from_config__cmdline_acl(config_file): """Ensure the command line acl overrides whatever is in the config.""" mock_options = mock.Mock() mock_options.acl = ["override-acl"] mock_options.config = [config_file] with open(config_file, "w") as openconf: openconf.write("\n".join([ "[pypicloud]", "repository:http://test-server/pypi", "username:test-username", "password:test-password", "extravals:are-ignored", "bucket:bucket-name", "access:access-key", "secret:secret-key", "acl:test-acl", ])) expected_s3 = pypicloud_tools.S3Config( "bucket-name", "access-key", "secret-key", "override-acl" ) expected_pypi = pypicloud_tools.PyPIConfig( "http://test-server/pypi", "test-username", "test-password" ) s3, pypi = pypicloud_tools.settings_from_config(mock_options) assert s3 == expected_s3 assert pypi == expected_pypi
def test_settings_from_config(config_file): """Ensure that the settings are correctly being read from config.""" mock_options = mock.Mock() del mock_options.acl # unset acl from command line mock_options.config = [config_file] with open(config_file, "w") as openconf: openconf.write("\n".join([ "[pypicloud]", "repository:http://test-server/pypi", "username:test-username", "password:test-password", "bucket:test-bucket-name", "access:test-access-key", "secret:test-secret-key", "acl:test-acl", ])) expected_s3 = pypicloud_tools.S3Config( "test-bucket-name", "test-access-key", "test-secret-key", "test-acl" ) expected_pypi = pypicloud_tools.PyPIConfig( "http://test-server/pypi", "test-username", "test-password" ) s3, pypi = pypicloud_tools.settings_from_config(mock_options) assert s3 == expected_s3 assert pypi == expected_pypi
def test_settings_from_config__no_acl(config_file): """Ensure the acl is None when no acl is configured.""" mock_options = mock.Mock() del mock_options.acl mock_options.config = [config_file] with open(config_file, "w") as openconf: openconf.write("\n".join([ "[pypicloud]", "repository:http://test-server/pypi", "username:test-username", "password:test-password", "extravals:are-ignored", "bucket:bucket-name", "access:access-key", "secret:secret-key", ])) expected_s3 = pypicloud_tools.S3Config( "bucket-name", "access-key", "secret-key", None, ) expected_pypi = pypicloud_tools.PyPIConfig( "http://test-server/pypi", "test-username", "test-password" ) s3, pypi = pypicloud_tools.settings_from_config(mock_options) assert s3 == expected_s3 assert pypi == expected_pypi
def test_settings_from_config__read_errors(config_file, capfd): """Ensure behaviour if/when there's an error reading the config file.""" mock_options = mock.Mock() mock_options.config = config_file with open(config_file, "w") as openconf: openconf.write("[malform[ed]]\n**&&&$$$$----\nyes=yes\n") assert pypicloud_tools.settings_from_config(mock_options) == (None, None) out, err = capfd.readouterr() assert "contains parsing errors:" in err assert not out
def test_settings_from_config__no_key(config_file): """If there is no [pypicloud] key, we should receive None, None.""" mock_options = mock.Mock() mock_options.config = config_file with open(config_file, "w") as openconf: openconf.writelines("\n".join([ "[something]", "repository:http://fake.com/pypi", "username:joe", "password:hunter7", ])) assert pypicloud_tools.settings_from_config(mock_options) == (None, None)