def test_connect_sign(self): self.client.msg = 'test message' self.client.sig = 'HyzVUenXXo4pa+kgm1vS8PNJM83eIXFC5r0q86FGbqFcdla6rcw' '72/ciXiEPfjli3ENfwWuESHhv6K9esI0dl5I=' self.client.address = '19qVgG8C6eXwKMMyvVegsi3xCsKyk3Z3jV' self.client.token = None with mock.patch('downstream_farmer.client.requests.post') as patch: patch.return_value.json.return_value = MockValues.connect_response self.client.connect() patch.assert_called_with('{0}/new/{1}'.format(self.server_url .strip('/') + self .api_path, self .client.address), data=json.dumps({ "message": self.client.msg, "signature": self.client.sig }), headers={ 'Content-Type': 'application/json' }, verify=None) self.assertEqual( self.client.token, MockValues.connect_response['token']) self.assertEqual(self.client.heartbeat, Heartbeat.fromdict(MockValues .connect_response['heartbeat']))
def setUp(self): self.challenge = Heartbeat.challenge_type().\ fromdict( MockValues .get_challenges_response['challenges'][0]['challenge']) self.heartbeat = Heartbeat.fromdict( MockValues.connect_response['heartbeat']) self.tag = Heartbeat.tag_type().fromdict( MockValues.get_chunks_response['chunks'][0]['tag']) self.expiration = datetime.utcnow( ) + timedelta(int(MockValues.get_chunks_response['chunks'][0]['due'])) self.client = mock.MagicMock() self.manager = ThreadManager() self.test_hash = 'hash' self.test_size = 100 self.test_seed = 'seed' self.contract = DownstreamContract(self.client, self.test_hash, self.test_seed, self.test_size, self.challenge, self.expiration, self.tag, self.manager, os.path.join('data', 'chunks')) self.contract.generate_data()
def test_connect_working(self): with mock.patch('downstream_farmer.client.requests.get') as patch: inst = patch.return_value inst.json.return_value = MockValues.connect_response self.client.connect(self.server_url) self.assertEqual(self.client.token,MockValues.connect_response['token']) self.assertEqual(self.client.heartbeat, Heartbeat.fromdict(MockValues.connect_response['heartbeat']))
def test_connect_working(self): self.client.session.get.return_value.json.return_value \ = MockValues.connect_response self.client.connect() self.client.session.get.assert_called_with('{0}/heartbeat/{1}'.format( self.server_url.strip('/') + self.api_path, self.token), verify=None) self.assertEqual(self.client.token, MockValues.connect_response['token']) self.assertEqual( self.client.heartbeat, Heartbeat.fromdict(MockValues.connect_response['heartbeat']))
def test_connect_working(self): with mock.patch('downstream_farmer.client.requests.get') as patch: patch.return_value.json.return_value = MockValues.connect_response self.client.connect() patch.assert_called_with('{0}/heartbeat/{1}'.format( self.server_url.strip('/') + self.api_path, self.token), verify=None) self.assertEqual(self.client.token, MockValues.connect_response['token']) self.assertEqual( self.client.heartbeat, Heartbeat.fromdict(MockValues.connect_response['heartbeat']))
def setUp(self): self.server_url = 'https://test.url/' self.address = base58.b58encode_check(b'\x00'+os.urandom(20)) self.client = DownstreamClient(self.address) self.test_contract = Contract(MockValues.get_chunk_response['file_hash'], MockValues.get_chunk_response['seed'], MockValues.get_chunk_response['size'], Heartbeat.challenge_type().fromdict( MockValues.get_chunk_response['challenge']), datetime.strptime( MockValues.get_chunk_response['expiration'], '%Y-%m-%dT%H:%M:%S'), Heartbeat.tag_type().fromdict( MockValues.get_chunk_response['tag'])) self.test_heartbeat = Heartbeat.fromdict(MockValues.connect_response['heartbeat'])
def setUp(self): self.server_url = 'https://test.url/' self.api_path = '/api/downstream/v1' self.size = 100 self.address = base58.b58encode_check(b'\x00' + os.urandom(20)) self.token = binascii.hexlify(os.urandom(16)).decode('ascii') self.msg = '' self.sig = '' self.thread_manager = ShellApplication() self.contract_thread = ManagedThread() self.chunk_dir = os.path.join('data', 'chunks') self.client = DownstreamClient(self.server_url, self.token, self.address, self.size, self.msg, self.sig, self.thread_manager, self.chunk_dir) self.client.session = mock.MagicMock() self.test_contract = \ DownstreamContract(self.client, MockValues.get_chunks_response[ 'chunks'][0]['file_hash'], MockValues.get_chunks_response[ 'chunks'][0]['seed'], MockValues.get_chunks_response[ 'chunks'][0]['size'], Heartbeat.challenge_type().fromdict( MockValues .get_chunks_response ['chunks'][0]['challenge']), datetime.utcnow() + timedelta( seconds=int( MockValues .get_chunks_response ['chunks'][0]['due'])), Heartbeat.tag_type().fromdict( MockValues .get_chunks_response ['chunks'][0]['tag']), self.thread_manager, self.chunk_dir) self.test_heartbeat = Heartbeat.fromdict( MockValues.connect_response['heartbeat'])
def setUp(self): self.challenge = Heartbeat.challenge_type().\ fromdict(MockValues.get_challenge_response['challenge']) self.heartbeat = Heartbeat.fromdict( MockValues.connect_response['heartbeat']) self.tag = Heartbeat.tag_type().fromdict( MockValues.get_chunk_response['tag']) self.expiration = datetime.utcnow( ) + timedelta(int(MockValues.get_chunk_response['due'])) self.client = mock.MagicMock() self.api = API() self.contract = DownstreamContract(self.client, 'hash', 'seed', 100, self.challenge, self.expiration, self.tag, self.api)
def setUp(self): self.server_url = 'https://test.url/' self.api_path = '/api/downstream/v1' self.size = 100 self.address = base58.b58encode_check(b'\x00' + os.urandom(20)) self.token = binascii.hexlify(os.urandom(16)).decode('ascii') self.msg = '' self.sig = '' self.api = API() self.client = DownstreamClient(self.server_url, self.token, self.address, self.size, self.msg, self.sig, self.api) self.test_contract = DownstreamContract(self.client, MockValues.get_chunk_response[ 'file_hash'], MockValues.get_chunk_response[ 'seed'], MockValues.get_chunk_response[ 'size'], Heartbeat.challenge_type() .fromdict( MockValues. get_chunk_response['challe' 'nge']), datetime.utcnow() + timedelta( seconds=int( MockValues. get_chunk_response['du' 'e'] )), Heartbeat.tag_type().fromdict( MockValues .get_chunk_response['ta' 'g'], ), self.api) self.test_heartbeat = Heartbeat.fromdict( MockValues.connect_response['heartbeat'])
def setUp(self): self.challenge = Heartbeat.challenge_type().\ fromdict( MockValues .get_challenges_response['challenges'][0]['challenge']) self.heartbeat = Heartbeat.fromdict( MockValues.connect_response['heartbeat']) self.tag = Heartbeat.tag_type().fromdict( MockValues.get_chunks_response['chunks'][0]['tag']) self.expiration = datetime.utcnow() + timedelta( int(MockValues.get_chunks_response['chunks'][0]['due'])) self.client = mock.MagicMock() self.manager = ThreadManager() self.test_hash = 'hash' self.test_size = 100 self.test_seed = 'seed' self.contract = DownstreamContract(self.client, self.test_hash, self.test_seed, self.test_size, self.challenge, self.expiration, self.tag, self.manager, os.path.join('data', 'chunks')) self.contract.generate_data()