<s> import json <EOL> from tornado import testing <EOL> from waterbutler . core . path import WaterButlerPath <EOL> from tests import utils <EOL> class TestCopyHandler ( utils . MultiProviderHandlerTestCase ) : <EOL> HOOK_PATH = '<STR_LIT>' <EOL> @ testing . gen_test <EOL> def test_calls_copy ( self ) : <EOL> self . source_provider . copy = utils . MockCoroutine ( <EOL> return_value = ( utils . MockFileMetadata ( ) , False ) <EOL> ) <EOL> yield self . http_client . fetch ( <EOL> self . get_url ( '<STR_LIT>' ) , <EOL> method = '<STR_LIT:POST>' , <EOL> body = json . dumps ( self . payload ( ) ) <EOL> ) <EOL> assert self . source_provider . copy . called <EOL> self . source_provider . copy . assert_called_once_with ( <EOL> self . destination_provider , <EOL> WaterButlerPath ( self . payload ( ) [ '<STR_LIT:source>' ] [ '<STR_LIT:path>' ] ) , <EOL> WaterButlerPath ( self . payload ( ) [ '<STR_LIT>' ] [ '<STR_LIT:path>' ] ) , <EOL> rename = None , <EOL> conflict = '<STR_LIT:replace>' <EOL> ) <EOL> @ testing . gen_test <EOL> def test_conflict ( self ) : <EOL> self . source_provider . copy = utils . MockCoroutine ( <EOL> return_value = ( utils . MockFileMetadata ( ) , True ) <EOL> ) <EOL> payload = self . payload ( ) <EOL> payload [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> resp = yield self . http_client . fetch ( <EOL> self . get_url ( '<STR_LIT>' ) , <EOL> method = '<STR_LIT:POST>' , <EOL> body = json . dumps ( payload ) <EOL> ) <EOL> assert resp . code == <NUM_LIT> <EOL> assert self . source_provider . copy . called <EOL> self . source_provider . copy . assert_called_once_with ( <EOL> self . destination_provider , <EOL> WaterButlerPath ( payload [ '<STR_LIT:source>' ] [ '<STR_LIT:path>' ] ) , <EOL> WaterButlerPath ( payload [ '<STR_LIT>' ] [ '<STR_LIT:path>' ] ) , <EOL> rename = None , <EOL> conflict = '<STR_LIT>' <EOL> ) <EOL> @ testing . gen_test <EOL> def test_rename ( self ) : <EOL> metadata = utils . MockFileMetadata ( ) <EOL> self . source_provider . copy = utils . MockCoroutine ( <EOL> return_value = ( metadata , False ) <EOL> ) <EOL> payload = self . payload ( ) <EOL> payload [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> resp = yield self . http_client . fetch ( <EOL> self . get_url ( '<STR_LIT>' ) , <EOL> method = '<STR_LIT:POST>' , <EOL> body = json . dumps ( payload ) <EOL> ) <EOL> assert resp . code == <NUM_LIT:200> <EOL> assert json . loads ( resp . body . decode ( ) ) == metadata . serialized ( ) <EOL> assert self . source_provider . copy . called <EOL> self . source_provider . copy . assert_called_once_with ( <EOL> self . destination_provider , <EOL> WaterButlerPath ( payload [ '<STR_LIT:source>' ] [ '<STR_LIT:path>' ] ) , <EOL> WaterButlerPath ( payload [ '<STR_LIT>' ] [ '<STR_LIT:path>' ] ) , <EOL> rename = '<STR_LIT>' , <EOL> conflict = '<STR_LIT:replace>' <EOL> ) <EOL> @ testing . gen_test <EOL> def test_intra_makes_callback ( self ) : <EOL> self . source_provider . copy = utils . MockCoroutine ( <EOL> return_value = ( utils . MockFileMetadata ( ) , False ) <EOL> ) <EOL> yield self . http_client . fetch ( <EOL> self . get_url ( '<STR_LIT>' ) , <EOL> method = '<STR_LIT:POST>' , <EOL> body = json . dumps ( self . payload ( ) ) <EOL> ) <EOL> self . mock_send_hook . assert_called_once_with ( <EOL> '<STR_LIT>' , <EOL> utils . MockFileMetadata ( ) . serialized ( ) <EOL> ) </s>
