def test_get_remote_file_content(self): content = str(self.script.read()) pkhash = compute_hash(content) remote_file = { 'storageAddress': 'localhost', 'hash': pkhash, 'owner': 'external_node_id', } with mock.patch('substrapp.utils.get_owner') as get_owner,\ mock.patch('substrapp.utils.requests.get') as request_get: get_owner.return_value = 'external_node_id' request_get.return_value = FakeRequest(content=content, status=status.HTTP_200_OK) content_remote = get_remote_file_content(remote_file, 'external_node_id', pkhash) self.assertEqual(content_remote, content) with mock.patch('substrapp.utils.get_owner') as get_owner,\ mock.patch('substrapp.utils.requests.get') as request_get: get_owner.return_value = 'external_node_id' request_get.return_value = FakeRequest(content=content, status=status.HTTP_200_OK) with self.assertRaises(Exception): # contents (by pkhash) are different get_remote_file_content(remote_file, 'external_node_id', 'fake_pkhash')
def get_remote_asset(channel_name, url, node_id, content_checksum, salt=None): auth = authenticate_outgoing_request(node_id) return get_remote_file_content(channel_name, url, auth, content_checksum, salt=salt)
def get_asset_content(channel_name, url, node_id, content_checksum, salt=None): return get_remote_file_content(channel_name, url, authenticate_worker(node_id), content_checksum, salt=salt)
def get_asset_content(url, node_id, content_hash, salt=None): return get_remote_file_content(url, authenticate_worker(node_id), content_hash, salt=salt)
def get_remote_asset(url, node_id, content_hash, salt=None): auth = authenticate_outgoing_request(node_id) return get_remote_file_content(url, auth, content_hash, salt=salt)