def test_cache_file_from_s3_step_four(snapshot):
    s3_session = S3FakeSession({'source-bucket': {'source-file': b'foo'}})
    s3_file_cache_session = S3FakeSession()

    solid_result = execute_solid(
        cache_file_from_s3,
        unittest_for_aws_mode_def(s3_file_cache_session, s3_session),
        input_values={
            's3_coord': {
                'bucket': 'source-bucket',
                'key': 'source-file'
            }
        },
    )

    assert solid_result.output_value(
    ).path_desc == 's3://file-cache-bucket/file-cache/source-file'

    file_cache_obj = s3_file_cache_session.get_object(
        Bucket='file-cache-bucket', Key='file-cache/source-file')

    assert file_cache_obj['Body'].read() == b'foo'

    # just perform a snapshot of the bucket structure as well
    snapshot.assert_match(s3_file_cache_session.buckets)
Ejemplo n.º 2
0
def test_cache_file_from_s3_step_three_fake(snapshot):
    s3_session = S3FakeSession({'some-bucket': {'some-key': b'foo'}})

    with get_temp_dir() as temp_dir:
        execute_solid(
            cache_file_from_s3,
            unittest_for_local_mode_def(temp_dir, s3_session),
            input_values={
                's3_coord': {
                    'bucket': 'some-bucket',
                    'key': 'some-key'
                }
            },
        )

        target_file = os.path.join(temp_dir, 'some-key')
        assert os.path.exists(target_file)

        with open(target_file, 'rb') as ff:
            assert ff.read() == b'foo'

        snapshot.assert_match(s3_session.buckets)