How to use ipfshttpclient - 10 common examples

To help you get started, we’ve selected a few ipfshttpclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs / py-ipfs-http-client / test / functional / test_pin.py View on Github external
def is_pinned(client, path):
	error_msg = None
	try:
	    resp = client.pin.ls(path)
	    assert path.split("/")[-1] in resp["Keys"]
	except ipfshttpclient.exceptions.ErrorResponse as exc:
		error_msg = exc.args[0]
		if "not pinned" in error_msg:
		    return False
		raise
	return True
github ipfs / py-ipfs-http-client / test / unit / test_utils.py View on Github external
def test_return_field_init(self):
		"""Tests utils.return_field.__init__()."""
		return_field = utils.return_field('Hash')
		assert return_field.field == 'Hash'
github ipfs / py-ipfs-http-client / test / unit / test_http.py View on Github external
def test_failed_download(http_client, http_server):
	"""Tests that a failed download raises an HTTPError."""
	http_server.serve_content("fail", 500)
	
	with pytest.raises(ipfshttpclient.exceptions.StatusError):
		http_client.download("/fail")
github ipfs / py-ipfs-http-client / test / functional / tests.py View on Github external
def is_available():
    """
    Return whether the IPFS daemon is reachable or not
    """
    global __is_available

    if not isinstance(__is_available, bool):
        try:
            ipfshttpclient.connect()
        except ipfshttpclient.exceptions.Error as error:
            __is_available = False

            # Make sure version incompatiblity is displayed to the user
            if isinstance(error, ipfshttpclient.exceptions.VersionMismatch):
                raise
        else:
            __is_available = True

    return __is_available
github AuHau / ipfs-publish / tests / unit / test_publishing.py View on Github external
def test_publish_repo_basic(self, mocker):
        mocker.patch.object(git.Repo, 'clone_from')
        mocker.patch.object(shutil, 'rmtree')

        ipfs_client_mock = mocker.Mock(spec=ipfshttpclient.Client)
        ipfs_client_mock.add.return_value = [{'Hash': 'some-hash'}]

        mocker.patch.object(ipfshttpclient, 'connect')
        ipfshttpclient.connect.return_value = ipfs_client_mock

        repo: publishing.GenericRepo = factories.RepoFactory()
        repo.publish_repo()

        ipfs_client_mock.add.assert_called_once_with(mocker.ANY, recursive=True, pin=True)
        ipfs_client_mock.pin.rm.assert_not_called()
        assert repo.last_ipfs_addr == '/ipfs/some-hash/'
github ipfs / py-ipfs-http-client / test / unit / test_multipart.py View on Github external
test/functional/fake_dir
		Changing that directory or its contents could break the test.
		"""
		# Get OS-agnostic path to test files
		path = os.path.join(os.path.dirname(os.path.dirname(__file__)),
		                    "functional", "fake_dir")
		# Collect absolute paths to all test files
		filenames_list = []
		for (dirpath, _, filenames) in os.walk(path):
			temp_list = [os.path.join(dirpath, name) for name in filenames]
			filenames_list.extend(temp_list)
		# Convert absolute paths to relative
		relative_paths_list = [os.path.relpath(cur_path, os.getcwd())
		                       for cur_path in filenames_list]

		instance = ipfshttpclient.multipart.FilesStream(relative_paths_list)

		expected = "(--\S+\r\nContent-Disposition: file; filename=\"\S+\""\
			+ "\r\nContent-Type: application/\S+\r\n"\
			+ "\r\n(.|\n)*\r\n)+--\S+--\r\n"
		actual = ""
		for i in instance.body():
			if type(i) is not str and type(i) is not memoryview:
				i = i.decode()
			elif six.PY3 and type(i) is memoryview:
				i = i.tobytes().decode()
			actual += i
		assert re.search(expected, actual)
github ipfs / py-ipfs-http-client / test / unit / test_multipart.py View on Github external
def test_body(self):
		"""Check the multipart HTTP body for the streamed directory."""
		# Get OS-agnostic path to test files
		path = os.path.join(os.path.dirname(os.path.dirname(__file__)),
		                    "functional", "fake_dir")
		instance = ipfshttpclient.multipart.DirectoryStream(path)
		expected = b"^(--\S+\r\nContent-Disposition: file; filename=\"\S+\""\
			+ b"\r\nContent-Type: application/\S+\r\n\r\n(.|\n)*"\
			+ b"\r\n)+--\S+--\r\n$"
		actual = b"".join(instance.body())
		assert re.search(expected, actual)
github ipfs / py-ipfs-http-client / test / unit / test_multipart.py View on Github external
def test_body(self):
		"""Check the multipart HTTP body for the streamed directory."""
		# Get OS-agnostic path to test files
		text = b"Here is some text for this test."
		instance = ipfshttpclient.multipart.BytesFileStream(text)
		expected = b"(--\S+\r\nContent-Disposition: file; filename=\"\S+\""\
			+ b"\r\nContent-Type: application/\S+\r\n"\
			+ b"\r\n(.|\n)*\r\n)+--\S+--\r\n"
		actual = b"".join(instance.body())
		assert re.search(expected, actual)
github ipfs / py-ipfs-http-client / test / functional / tests.py View on Github external
def setUp(self):
        self.http_client = ipfshttpclient.Client()
        self._olddir = os.getcwd()
        os.chdir(HERE)
github ipfs / py-ipfs-http-client / test / functional / tests.py View on Github external
def test_assert_version(self):
        # Minimum required version
        ipfshttpclient.assert_version("0.1.0", "0.1.0", "0.2.0")

        # Too high version
        with self.assertRaises(ipfshttpclient.exceptions.VersionMismatch):
            ipfshttpclient.assert_version("0.2.0", "0.1.0", "0.2.0")

        # Too low version
        with self.assertRaises(ipfshttpclient.exceptions.VersionMismatch):
            ipfshttpclient.assert_version("0.0.5", "0.1.0", "0.2.0")

@skipIfOffline()
class IpfsHttpClientTest(unittest.TestCase):

    http_client = ipfshttpclient.Client()

    fake = [{'Hash': u'QmQcCtMgLVwvMQGu6mvsRYLjwqrZJcYtH4mboM9urWW9vX',
             'Name': 'fake_dir/fsdfgh'},
            {'Hash': u'QmYAhvKYu46rh5NcHzeu6Bhc7NG9SqkF9wySj2jvB74Rkv',
             'Name': 'fake_dir/popoiopiu'},
            {'Hash': u'QmeMbJSHNCesAh7EeopackUdjutTJznum1Fn7knPm873Fe',
             'Name': 'fake_dir/test3/ppppoooooooooo'},
            {'Hash': u'QmRphRr6ULDEj7YnXpLdnxhnPiVjv5RDtGX3er94Ec6v4Q',
             'Name': 'fake_dir/test3'},
            {'Hash': u'QmNuvmuFeeWWpxjCQwLkHshr8iqhGLWXFzSGzafBeawTTZ',
             'Name': 'fake_dir/test2/llllg'},
            {'Hash': u'Qmb1NPqPzdHCMvHRfCkk6TWLcnpGJ71KnafacCMm6TKLcD',
             'Name': 'fake_dir/test2/fssdf'},
            {'Hash': u'QmX1dd5DtkgoiYRKaPQPTCtXArUu4jEZ62rJBUcd5WhxAZ',
             'Name': 'fake_dir/test2'},
            {'Hash': u'QmRphRr6ULDEj7YnXpLdnxhnPiVjv5RDtGX3er94Ec6v4Q',