<s> import unittest <EOL> from mock import Mock , create_autospec <EOL> from arbalest . core import PipelineException <EOL> from arbalest . redshift import S3BulkCopyPipeline , TargetTable <EOL> from arbalest . redshift . schema import JsonObject , Property <EOL> from arbalest . redshift . step import BulkCopyFromS3JsonStep , SqlStep <EOL> from arbalest . sql import Database <EOL> from test import AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY , TABLE_NAME <EOL> class S3BulkCopyPipelineShould ( unittest . TestCase ) : <EOL> def test_throw_pipeline_exception_when_no_steps_on_run ( self ) : <EOL> self . assertRaises ( PipelineException , <EOL> S3BulkCopyPipeline ( AWS_ACCESS_KEY_ID , <EOL> AWS_SECRET_ACCESS_KEY , Mock ( ) , <EOL> Mock ( ) ) . run ) <EOL> def test_throw_pipeline_exception_when_no_steps_on_validate ( self ) : <EOL> self . assertRaises ( PipelineException , <EOL> S3BulkCopyPipeline ( AWS_ACCESS_KEY_ID , <EOL> AWS_SECRET_ACCESS_KEY , Mock ( ) , <EOL> Mock ( ) ) . validate ) <EOL> def test_add_step ( self ) : <EOL> schema = JsonObject ( TABLE_NAME , Property ( '<STR_LIT:id>' , '<STR_LIT>' ) ) <EOL> bucket = Mock ( ) <EOL> database = create_autospec ( Database ) <EOL> expected = BulkCopyFromS3JsonStep ( metadata = '<STR_LIT>' , <EOL> source = '<STR_LIT>' , <EOL> schema = schema , <EOL> aws_access_key_id = AWS_ACCESS_KEY_ID , <EOL> aws_secret_access_key = AWS_SECRET_ACCESS_KEY , <EOL> bucket = bucket , <EOL> table = TargetTable ( schema , <EOL> database ) ) <EOL> pipeline = S3BulkCopyPipeline ( AWS_ACCESS_KEY_ID , <EOL> AWS_SECRET_ACCESS_KEY , bucket , <EOL> database ) <EOL> pipeline . step ( metadata = '<STR_LIT>' , <EOL> source = '<STR_LIT>' , <EOL> schema = schema ) <EOL> step = pipeline . steps ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( expected . metadata , step . metadata ) <EOL> self . assertEqual ( expected . source , step . source ) <EOL> self . assertEqual ( expected . schema , step . schema ) <EOL> self . assertEqual ( expected . aws_access_key_id , step . aws_access_key_id ) <EOL> self . assertEqual ( expected . aws_secret_access_key , <EOL> step . aws_secret_access_key ) <EOL> self . assertEqual ( expected . bucket , step . bucket ) <EOL> self . assertEqual ( expected . table . schema , step . table . schema ) <EOL> self . assertEqual ( expected . table . database , step . table . database ) <EOL> def test_add_sql ( self ) : <EOL> bucket = Mock ( ) <EOL> database = create_autospec ( Database ) <EOL> expected = SqlStep ( database , <EOL> ( "<STR_LIT>" , TABLE_NAME , <NUM_LIT:1> ) , <EOL> ( "<STR_LIT>" , TABLE_NAME , <NUM_LIT:2> ) , <EOL> ( "<STR_LIT>" . format ( <EOL> TABLE_NAME ) ) ) <EOL> pipeline = S3BulkCopyPipeline ( AWS_ACCESS_KEY_ID , <EOL> AWS_SECRET_ACCESS_KEY , bucket , <EOL> database ) <EOL> pipeline . sql ( ( "<STR_LIT>" , TABLE_NAME , <NUM_LIT:1> ) , <EOL> ( "<STR_LIT>" , TABLE_NAME , <NUM_LIT:2> ) , <EOL> ( "<STR_LIT>" . format ( <EOL> TABLE_NAME ) ) ) <EOL> step = pipeline . steps ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( expected . statements , step . statements ) </s>
