<s> import pygit2 <EOL> from groundstation . utils import oid2hex <EOL> from support . handler_fixture import StationHandlerTestCase , MockRequest <EOL> from groundstation . proto . git_object_pb2 import GitObject <EOL> from groundstation . transfer . response_handlers import handle_transfer <EOL> from groundstation . transfer . response_handlers . transfer import UnsolicitedTransfer <EOL> class TestHandlerTransfer ( StationHandlerTestCase ) : <EOL> def test_transfer_object ( self ) : <EOL> self . station . set_real_id ( True ) <EOL> object_body = "<STR_LIT>" <EOL> oid = pygit2 . hash ( object_body ) <EOL> req = MockRequest ( self . station . id ) <EOL> req . payload = oid2hex ( oid ) <EOL> self . station . station . registry . register ( req ) <EOL> git_pb = GitObject ( ) <EOL> git_pb . data = object_body <EOL> git_pb . type = pygit2 . GIT_OBJ_BLOB <EOL> self . station . payload = git_pb . SerializeToString ( ) <EOL> handle_transfer ( self . station ) <EOL> self . assertTrue ( self . station . station [ oid2hex ( oid ) ] , object_body ) <EOL> def test_rejects_invalid_transfers ( self ) : <EOL> self . station . set_real_id ( True ) <EOL> object_body = "<STR_LIT>" <EOL> req = MockRequest ( self . station . id ) <EOL> req . payload = "<STR_LIT>" <EOL> self . station . station . registry . register ( req ) <EOL> git_pb = GitObject ( ) <EOL> git_pb . data = object_body <EOL> git_pb . type = pygit2 . GIT_OBJ_BLOB <EOL> self . station . payload = git_pb . SerializeToString ( ) <EOL> self . assertRaises ( AssertionError , handle_transfer , self . station ) <EOL> def test_rejects_unsolicited_transfers ( self ) : <EOL> self . station . set_real_id ( True ) <EOL> object_body = "<STR_LIT>" <EOL> git_pb = GitObject ( ) <EOL> git_pb . data = object_body <EOL> git_pb . type = pygit2 . GIT_OBJ_BLOB <EOL> self . station . payload = git_pb . SerializeToString ( ) <EOL> self . assertRaises ( UnsolicitedTransfer , handle_transfer , self . station ) </s>
