示例#1
0
def test_aws_s3_s3uri_bad_pattern():
    with pytest.raises(AssertionError):
        S3Uri(f' s3://{TEST_BUCKET_NAME}/')
    with pytest.raises(AssertionError):
        S3Uri(f'h3://{TEST_BUCKET_NAME}/')
    with pytest.raises(AssertionError):
        S3Uri(f's3:/{TEST_BUCKET_NAME}/')
示例#2
0
def test_aws_s3_s3uri_add_to_path():
    base = S3Uri(f's3://{TEST_BUCKET_NAME}/')
    assert f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}' == str(base + TEST_KEY_NAME)
    assert f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}' == str(base.add_suffix(TEST_KEY_NAME))
    with pytest.raises(TypeError):
        S3Uri(f's3://{TEST_BUCKET_NAME}') + 2
    with pytest.raises(TypeError):
        S3Uri(f's3://{TEST_BUCKET_NAME}').add_suffix(2)
示例#3
0
def test_aws_s3_s3uri_key():
    assert TEST_KEY_NAME == S3Uri(f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}').key
    assert f'{TEST_KEY_NAME}/' == S3Uri(f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}/').key
    assert '' == S3Uri(f's3://{TEST_BUCKET_NAME}').key
    assert '' == S3Uri(f's3://{TEST_BUCKET_NAME}/').key
    assert '' == S3Uri(f's3://').key

    key = 'mykey/with/many/delimiters'
    assert key == S3Uri(f's3://{TEST_BUCKET_NAME}/{key}').key
    key = 'mykey/with/many/delimiters/'
    assert key == S3Uri(f's3://{TEST_BUCKET_NAME}/{key}').key
示例#4
0
def test_aws_s3_s3uri_fancy_division():
    assert f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}' == str(
        S3Uri(f's3://{TEST_BUCKET_NAME}/') / TEST_KEY_NAME
    )
    assert f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}' == str(
        S3Uri(f's3://{TEST_BUCKET_NAME}') / TEST_KEY_NAME
    )
    assert f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}' == str(
        S3Uri(f's3://{TEST_BUCKET_NAME}/') // TEST_KEY_NAME
    )
    assert f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}' == str(
        S3Uri(f's3://{TEST_BUCKET_NAME}') // TEST_KEY_NAME
    )

    with pytest.raises(TypeError):
        S3Uri(f's3://{TEST_BUCKET_NAME}') / 2
    with pytest.raises(TypeError):
        S3Uri(f's3://{TEST_BUCKET_NAME}') // 2
    with pytest.raises(TypeError):
        S3Uri(f's3://{TEST_BUCKET_NAME}') / 2.0
    with pytest.raises(TypeError):
        S3Uri(f's3://{TEST_BUCKET_NAME}') // 2.0
示例#5
0
def test_s3_uri():
    return S3Uri(f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}')
示例#6
0
def test_aws_s3_s3uri_str():
    base = S3Uri(f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}')
    assert f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}' == str(base)
    assert f'S3Uri(\'s3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}\')' == repr(base)
示例#7
0
def test_aws_s3_s3uri_bucket():
    assert TEST_BUCKET_NAME == S3Uri(f's3://{TEST_BUCKET_NAME}/').bucket
示例#8
0
def test_aws_s3_s3uri_scheme():
    assert 's3://' == S3Uri(f's3://{TEST_BUCKET_NAME}/').scheme
示例#9
0
def test_aws_s3_s3uri_object_exists(test_bucket):
    assert not S3Uri(f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}').object_exists()
    test_bucket.put_object(Key=TEST_KEY_NAME, Body=TEST_BODY)
    assert S3Uri(f's3://{TEST_BUCKET_NAME}/{TEST_KEY_NAME}').object_exists()