예제 #1
0
def test_env_accessors_no_env():
    """Sould all raise an exception."""
    with pytest.raises(EnvError):
        delenv()
    with pytest.raises(EnvError):
        setenv()
    with pytest.raises(EnvError):
        getenv()
예제 #2
0
def test_aws_unsigned_subenv(gdalenv):
    """Create an Env with no AWS signing."""
    with rasterio.Env(
            aws_access_key_id='id', aws_secret_access_key='key',
            aws_session_token='token', region_name='null-island-1'):
        with rasterio.env.Env(aws_unsigned=True):
            assert getenv()['AWS_NO_SIGN_REQUEST'] == 'YES'
            assert getenv().get('AWS_ACCESS_KEY_ID') is None
예제 #3
0
def test_env_accessors_no_env():
    """Sould all raise an exception."""
    with pytest.raises(EnvError):
        delenv()
    with pytest.raises(EnvError):
        setenv()
    with pytest.raises(EnvError):
        getenv()
예제 #4
0
def test_azure_session_credentials(gdalenv):
    """Create an Env with azure session."""
    azure_session = AzureSession(azure_storage_account='foo',
                                 azure_storage_access_key='bar')
    with rasterio.env.Env(session=azure_session) as s:
        s.credentialize()
        assert getenv()['AZURE_STORAGE_ACCOUNT'] == 'foo'
        assert getenv()['AZURE_STORAGE_ACCESS_KEY'] == 'bar'
예제 #5
0
def test_swift_session_credentials(gdalenv):
    """Create an Env with a oss session."""
    swift_session = SwiftSession(swift_storage_url='foo',
                                 swift_auth_token='bar')
    with rasterio.env.Env(session=swift_session) as s:
        s.credentialize()
        assert getenv()['SWIFT_STORAGE_URL'] == 'foo'
        assert getenv()['SWIFT_AUTH_TOKEN'] == 'bar'
예제 #6
0
def test_env_options(gdalenv):
    """Test env options."""
    env = rasterio.Env(foo='x')
    assert env.options == {'foo': 'x'}
    assert not env.previous_options
    assert getenv() == rasterio.env._env.options == {}
    with env:
        assert getenv() == rasterio.env._env.options == {'foo': 'x'}
    assert getenv() == rasterio.env._env.options == {}
예제 #7
0
def test_oss_session_credentials(gdalenv):
    """Create an Env with a oss session."""
    oss_session = OSSSession(oss_access_key_id='id',
                             oss_secret_access_key='key',
                             oss_endpoint='null-island-1')
    with rasterio.env.Env(session=oss_session):
        assert getenv()['OSS_ACCESS_KEY_ID'] == 'id'
        assert getenv()['OSS_SECRET_ACCESS_KEY'] == 'key'
        assert getenv()['OSS_ENDPOINT'] == 'null-island-1'
예제 #8
0
def test_swift_session_credentials(gdalenv):
    """Create an Env with a oss session."""
    swift_session = SwiftSession(
        swift_storage_url='foo',
        swift_auth_token='bar')
    with rasterio.env.Env(session=swift_session) as s:
        s.credentialize()
        assert getenv()['SWIFT_STORAGE_URL'] == 'foo'
        assert getenv()['SWIFT_AUTH_TOKEN'] == 'bar'
예제 #9
0
def test_aws_unsigned_subenv(gdalenv):
    """Create an Env with no AWS signing."""
    with rasterio.Env(
            aws_access_key_id='id', aws_secret_access_key='key',
            aws_session_token='token', region_name='null-island-1'):
        with rasterio.env.Env(aws_unsigned=True) as inner:
            inner.credentialize()
            assert getenv()['AWS_NO_SIGN_REQUEST'] == 'YES'
            assert getenv().get('AWS_ACCESS_KEY_ID') is None
예제 #10
0
def test_env_options(gdalenv):
    """Test env options."""
    env = Env(foo='x')
    assert env.options == {'foo': 'x'}
    assert not env.previous_options
    assert getenv() == rasterio.env._env.options == {}
    with env:
        assert getenv() == rasterio.env._env.options == {'foo': 'x'}
    assert getenv() == rasterio.env._env.options == {}
예제 #11
0
def test_with_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    with Env(aws_access_key_id='id', aws_secret_access_key='key',
             aws_session_token='token', region_name='null-island-1') as s:
        assert getenv() == rasterio.env._env.options == {}
        s.get_aws_credentials()
        assert getenv() == rasterio.env._env.options == {
            'aws_access_key_id': 'id', 'aws_region': 'null-island-1',
            'aws_secret_access_key': 'key', 'aws_session_token': 'token'}
예제 #12
0
def test_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    aws_session = boto3.Session(
        aws_access_key_id='id', aws_secret_access_key='key',
        aws_session_token='token', region_name='null-island-1')
    with rasterio.env.Env(session=aws_session):
        assert getenv()['AWS_ACCESS_KEY_ID'] == 'id'
        assert getenv()['AWS_REGION'] == 'null-island-1'
        assert getenv()['AWS_SECRET_ACCESS_KEY'] == 'key'
        assert getenv()['AWS_SESSION_TOKEN'] == 'token'
예제 #13
0
def test_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    aws_session = boto3.Session(
        aws_access_key_id='id', aws_secret_access_key='key',
        aws_session_token='token', region_name='null-island-1')
    with rasterio.env.Env(aws_session=aws_session) as s:
        s.get_aws_credentials()
        assert getenv()['aws_access_key_id'] == 'id'
        assert getenv()['aws_region'] == 'null-island-1'
        assert getenv()['aws_secret_access_key'] == 'key'
        assert getenv()['aws_session_token'] == 'token'
예제 #14
0
def test_oss_session_credentials(gdalenv):
    """Create an Env with a oss session."""
    oss_session = OSSSession(
        oss_access_key_id='id',
        oss_secret_access_key='key',
        oss_endpoint='null-island-1')
    with rasterio.env.Env(session=oss_session) as s:
        s.credentialize()
        assert getenv()['OSS_ACCESS_KEY_ID'] == 'id'
        assert getenv()['OSS_SECRET_ACCESS_KEY'] == 'key'
        assert getenv()['OSS_ENDPOINT'] == 'null-island-1'
예제 #15
0
def test_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    aws_session = boto3.Session(
        aws_access_key_id='id', aws_secret_access_key='key',
        aws_session_token='token', region_name='null-island-1')
    with rasterio.env.Env(aws_session=aws_session) as s:
        s.get_aws_credentials()
        assert getenv()['aws_access_key_id'] == 'id'
        assert getenv()['aws_region'] == 'null-island-1'
        assert getenv()['aws_secret_access_key'] == 'key'
        assert getenv()['aws_session_token'] == 'token'
예제 #16
0
def test_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    aws_session = boto3.Session(
        aws_access_key_id='id', aws_secret_access_key='key',
        aws_session_token='token', region_name='null-island-1')
    with rasterio.env.Env(session=aws_session) as s:
        s.credentialize()
        assert getenv()['AWS_ACCESS_KEY_ID'] == 'id'
        assert getenv()['AWS_REGION'] == 'null-island-1'
        assert getenv()['AWS_SECRET_ACCESS_KEY'] == 'key'
        assert getenv()['AWS_SESSION_TOKEN'] == 'token'
예제 #17
0
def test_with_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    with rasterio.Env(
            aws_access_key_id='id', aws_secret_access_key='key',
            aws_session_token='token', region_name='null-island-1') as s:
        expected = default_options.copy()
        assert getenv() == rasterio.env._env.options == expected
        s.get_aws_credentials()
        expected.update({
            'aws_access_key_id': 'id', 'aws_region': 'null-island-1',
            'aws_secret_access_key': 'key', 'aws_session_token': 'token'})
        assert getenv() == rasterio.env._env.options == expected
예제 #18
0
def test_with_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    with rasterio.Env(
            aws_access_key_id='id', aws_secret_access_key='key',
            aws_session_token='token', region_name='null-island-1') as s:
        expected = default_options.copy()
        assert getenv() == rasterio.env.local._env.options == expected
        s.get_aws_credentials()
        expected.update({
            'aws_access_key_id': 'id', 'aws_region': 'null-island-1',
            'aws_secret_access_key': 'key', 'aws_session_token': 'token'})
        assert getenv() == rasterio.env.local._env.options == expected
예제 #19
0
def test_env_options(gdalenv):
    """Test env options."""
    env = rasterio.Env(foo='x')
    assert env.options == {'foo': 'x'}
    assert not env.previous_options
    expected = default_options.copy()
    assert getenv() == rasterio.env._env.options == expected
    expected.update({'foo': 'x'})
    with env:
        assert getenv() == rasterio.env._env.options == expected
    del expected['foo']
    assert getenv() == rasterio.env._env.options == expected
예제 #20
0
def test_with_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    with rasterio.Env(aws_access_key_id='id',
                      aws_secret_access_key='key',
                      aws_session_token='token',
                      region_name='null-island-1') as s:
        assert getenv() == rasterio.env._env.options == {}
        s.get_aws_credentials()
        assert getenv() == rasterio.env._env.options == {
            'aws_access_key_id': 'id',
            'aws_region': 'null-island-1',
            'aws_secret_access_key': 'key',
            'aws_session_token': 'token'
        }
예제 #21
0
def test_env_accessors(gdalenv):
    """High level GDAL env access."""
    defenv()
    setenv(foo='1', bar='2')
    expected = default_options.copy()
    expected.update({'foo': '1', 'bar': '2'})
    assert getenv() == rasterio.env._env.options
    assert getenv() == expected
    assert get_gdal_config('foo') == '1'
    assert get_gdal_config('bar') == '2'
    delenv()
    with pytest.raises(EnvError):
        getenv()
    assert get_gdal_config('foo') is None
    assert get_gdal_config('bar') is None
예제 #22
0
def test_session_env_lazy(monkeypatch, gdalenv):
    """Create an Env with AWS env vars."""
    monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'id')
    monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'key')
    monkeypatch.setenv('AWS_SESSION_TOKEN', 'token')
    with rasterio.Env():
        assert getenv() == rasterio.env.local._env.options
        expected = {
            'AWS_ACCESS_KEY_ID': 'id',
            'AWS_SECRET_ACCESS_KEY': 'key',
            'AWS_SESSION_TOKEN': 'token'}
        for k, v in expected.items():
            assert getenv()[k] == v

    monkeypatch.undo()
예제 #23
0
def test_env_accessors(gdalenv):
    """High level GDAL env access."""
    defenv()
    setenv(foo='1', bar='2')
    expected = default_options.copy()
    expected.update({'foo': '1', 'bar': '2'})
    assert getenv() == rasterio.env.local._env.options
    assert getenv() == expected
    assert get_gdal_config('foo') == 1
    assert get_gdal_config('bar') == 2
    delenv()
    with pytest.raises(EnvError):
        getenv()
    assert get_gdal_config('foo') is None
    assert get_gdal_config('bar') is None
예제 #24
0
def test_swift_session_by_user_key():
    def mock_init(self, session=None, 
                swift_storage_url=None, swift_auth_token=None, 
                swift_auth_v1_url=None, swift_user=None, swift_key=None):
        self._creds = {'SWIFT_STORAGE_URL':'foo',
                       'SWIFT_AUTH_TOKEN':'bar'}

    with mock.patch('rasterio.session.SwiftSession.__init__', new=mock_init):
        swift_session = SwiftSession(
            swift_auth_v1_url='foo',
            swift_user='******',
            swift_key='key')
        with rasterio.env.Env(session=swift_session) as s:
            s.credentialize()
            assert getenv()['SWIFT_STORAGE_URL'] == 'foo'
            assert getenv()['SWIFT_AUTH_TOKEN'] == 'bar'
예제 #25
0
def test_ensure_env_decorator(gdalenv):
    def f():
        return getenv()['WITH_RASTERIO_ENV']

    wrapper = ensure_env(f)
    assert wrapper() is True
    assert 'WITH_RASTERIO_ENV' not in getenv()
예제 #26
0
def test_session_env_lazy(monkeypatch, gdalenv):
    """Create an Env with AWS env vars."""
    monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'id')
    monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'key')
    monkeypatch.setenv('AWS_SESSION_TOKEN', 'token')
    with Env() as s:
        s.get_aws_credentials()
        assert getenv() == rasterio.env._env.options
        expected = {
            'aws_access_key_id': 'id',
            'aws_secret_access_key': 'key',
            'aws_session_token': 'token'}
        for k, v in expected.items():
            assert getenv()[k] == v

    monkeypatch.undo()
예제 #27
0
def test_session_env_lazy(monkeypatch, gdalenv):
    """Create an Env with AWS env vars."""
    monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'id')
    monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'key')
    monkeypatch.setenv('AWS_SESSION_TOKEN', 'token')
    with rasterio.Env() as s:
        s.get_aws_credentials()
        assert getenv() == rasterio.env._env.options
        expected = {
            'aws_access_key_id': 'id',
            'aws_secret_access_key': 'key',
            'aws_session_token': 'token'}
        for k, v in expected.items():
            assert getenv()[k] == v

    monkeypatch.undo()
예제 #28
0
def test_session_env_lazy(monkeypatch, gdalenv):
    """Create an Env with AWS env vars."""
    monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'id')
    monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'key')
    monkeypatch.setenv('AWS_SESSION_TOKEN', 'token')
    with rasterio.Env() as s:
        s.credentialize()
        assert getenv() == rasterio.env.local._env.options
        expected = {
            'AWS_ACCESS_KEY_ID': 'id',
            'AWS_SECRET_ACCESS_KEY': 'key',
            'AWS_SESSION_TOKEN': 'token'}
        for k, v in expected.items():
            assert getenv()[k] == v

    monkeypatch.undo()
예제 #29
0
def test_nested_credentials(monkeypatch):
    """Check that rasterio.open() doesn't wipe out surrounding credentials"""
    @ensure_env_credentialled
    def fake_opener(path):
        return getenv()

    with rasterio.Env(session=AWSSession(aws_access_key_id='foo',
                                         aws_secret_access_key='bar')):
        assert getenv()['AWS_ACCESS_KEY_ID'] == 'foo'
        assert getenv()['AWS_SECRET_ACCESS_KEY'] == 'bar'

        monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'lol')
        monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'wut')

        gdalenv = fake_opener('s3://foo/bar')
        assert gdalenv['AWS_ACCESS_KEY_ID'] == 'foo'
        assert gdalenv['AWS_SECRET_ACCESS_KEY'] == 'bar'
예제 #30
0
def test_env_accessors(gdalenv):
    """High level GDAL env access."""
    defenv()
    setenv(foo='1', bar='2')
    expected = {'foo': '1', 'bar': '2'}
    items = getenv()
    assert items == rasterio.env.local._env.options
    # Comparison below requires removal of GDAL_DATA.
    items.pop('GDAL_DATA', None)
    assert items == expected
    assert get_gdal_config('foo') == 1
    assert get_gdal_config('bar') == 2
    delenv()
    with pytest.raises(EnvError):
        getenv()
    assert get_gdal_config('foo') is None
    assert get_gdal_config('bar') is None
예제 #31
0
def test_nested_credentials(monkeypatch):
    """Check that rasterio.open() doesn't wipe out surrounding credentials"""

    @ensure_env_credentialled
    def fake_opener(path):
        return getenv()

    with rasterio.Env(session=AWSSession(aws_access_key_id='foo', aws_secret_access_key='bar')):
        assert getenv()['AWS_ACCESS_KEY_ID'] == 'foo'
        assert getenv()['AWS_SECRET_ACCESS_KEY'] == 'bar'

        monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'lol')
        monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'wut')

        gdalenv = fake_opener('s3://foo/bar')
        assert gdalenv['AWS_ACCESS_KEY_ID'] == 'foo'
        assert gdalenv['AWS_SECRET_ACCESS_KEY'] == 'bar'
예제 #32
0
def test_azure_session_credentials_connection_string(gdalenv):
    """Create an Env with azure session."""
    azure_session = AzureSession(
        azure_storage_connection_string='AccountName=myaccount;AccountKey=MY_ACCOUNT_KEY',
    )
    with rasterio.env.Env(session=azure_session) as s:
        s.credentialize()
        assert getenv()['AZURE_STORAGE_CONNECTION_STRING'] == 'AccountName=myaccount;AccountKey=MY_ACCOUNT_KEY'
예제 #33
0
def test_env_accessors(gdalenv):
    """High level GDAL env access."""
    defenv()
    setenv(foo='1', bar='2')
    expected = {'foo': '1', 'bar': '2'}
    items = getenv()
    assert items == rasterio.env.local._env.options
    # Comparison below requires removal of GDAL_DATA.
    items.pop('GDAL_DATA', None)
    assert items == expected
    assert get_gdal_config('foo') == 1
    assert get_gdal_config('bar') == 2
    delenv()
    with pytest.raises(EnvError):
        getenv()
    assert get_gdal_config('foo') is None
    assert get_gdal_config('bar') is None
예제 #34
0
def test_env_accessors(gdalenv):
    """High level GDAL env access."""
    defenv()
    setenv(foo='1', bar='2')
    assert getenv() == rasterio.env._env.options == {'foo': '1', 'bar': '2'}
    assert get_gdal_config('foo') == '1'
    assert get_gdal_config('bar') == '2'
    delenv()
    assert getenv() == rasterio.env._env.options == {}
    assert get_gdal_config('foo') is None
    assert get_gdal_config('bar') is None
    rasterio.env._env = None
    with pytest.raises(EnvError):
        delenv()
    with pytest.raises(EnvError):
        setenv()
    with pytest.raises(EnvError):
        getenv()
예제 #35
0
def test_env_accessors(gdalenv):
    """High level GDAL env access"""
    defenv()
    setenv(foo='1', bar='2')
    assert getenv() == rasterio.env._env.options == {'foo': '1', 'bar': '2'}
    assert get_gdal_config('foo') == '1'
    assert get_gdal_config('bar') == '2'
    delenv()
    assert getenv() == rasterio.env._env.options == {}
    assert get_gdal_config('foo') is None
    assert get_gdal_config('bar') is None
    rasterio.env._env = None
    with pytest.raises(EnvError):
        delenv()
    with pytest.raises(EnvError):
        setenv()
    with pytest.raises(EnvError):
        getenv()
예제 #36
0
def test_with_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    env = rasterio.Env(
        aws_access_key_id='id', aws_secret_access_key='key',
        aws_session_token='token', region_name='null-island-1')
    expected = default_options.copy()
    with env:
        expected.update({
            'AWS_ACCESS_KEY_ID': 'id', 'AWS_REGION': 'null-island-1',
            'AWS_SECRET_ACCESS_KEY': 'key', 'AWS_SESSION_TOKEN': 'token'})
        assert getenv() == expected
예제 #37
0
def test_with_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    env = rasterio.Env(
        aws_access_key_id='id', aws_secret_access_key='key',
        aws_session_token='token', region_name='null-island-1')
    with env:
        expected = {
            'AWS_ACCESS_KEY_ID': 'id', 'AWS_REGION': 'null-island-1',
            'AWS_SECRET_ACCESS_KEY': 'key', 'AWS_SESSION_TOKEN': 'token'}
        items = getenv()
        # Comparison below requires removal of GDAL_DATA.
        items.pop('GDAL_DATA', None)
        assert items == expected
예제 #38
0
def test_with_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    env = rasterio.Env(
        aws_access_key_id='id', aws_secret_access_key='key',
        aws_session_token='token', region_name='null-island-1')
    with env:
        expected = {
            'AWS_ACCESS_KEY_ID': 'id', 'AWS_REGION': 'null-island-1',
            'AWS_SECRET_ACCESS_KEY': 'key', 'AWS_SESSION_TOKEN': 'token'}
        items = getenv()
        # Comparison below requires removal of GDAL_DATA.
        items.pop('GDAL_DATA', None)
        assert items == expected
예제 #39
0
def test_with_aws_session_credentials(gdalenv):
    """Create an Env with a boto3 session."""
    env = rasterio.Env(aws_access_key_id='id',
                       aws_secret_access_key='key',
                       aws_session_token='token',
                       region_name='null-island-1')
    expected = default_options.copy()
    with env:
        expected.update({
            'AWS_ACCESS_KEY_ID': 'id',
            'AWS_REGION': 'null-island-1',
            'AWS_SECRET_ACCESS_KEY': 'key',
            'AWS_SESSION_TOKEN': 'token'
        })
        assert getenv() == expected
예제 #40
0
 def f():
     return getenv()['GDAL_DATA']
예제 #41
0
 def f():
     return getenv()['WITH_RASTERIO_ENV']
예제 #42
0
def test_aws_unsigned(gdalenv):
    """Create an Env with no AWS signing."""
    with rasterio.env.Env(aws_unsigned=True) as s:
        s.credentialize()
        assert getenv()['AWS_NO_SIGN_REQUEST'] == 'YES'
        assert getenv().get('AWS_ACCESS_KEY_ID') is None
예제 #43
0
def test_aws_unsigned(gdalenv):
    """Create an Env with no AWS signing."""
    with rasterio.env.Env(aws_unsigned=True) as s:
        s.credentialize()
        assert getenv()['AWS_NO_SIGN_REQUEST'] == 'YES'
        assert getenv().get('AWS_ACCESS_KEY_ID') is None
예제 #44
0
def test_ensure_env_decorator(gdalenv):
    def f():
        return getenv()['WITH_RASTERIO_ENV']
    wrapper = ensure_env(f)
    assert wrapper() is True
    assert 'WITH_RASTERIO_ENV' not in getenv()
예제 #45
0
 def f():
     return getenv()['RASTERIO_ENV']
예제 #46
0
 def f(path):
     return getenv()
예제 #47
0
 def fake_opener(path):
     return getenv()
예제 #48
0
 def fake_opener(path):
     return getenv()
예제 #49
0
 def f():
     return getenv()['WITH_RASTERIO_ENV']
예제 #50
0
 def f():
     return getenv()['GDAL_DATA']
예제 #51
0
 def f(fp):
     return getenv()
예제 #52
0
 def f():
     return getenv()['RASTERIO_ENV']
예제 #53
0
 def f(path):
     return getenv()