Skip to content

Commit

Permalink
Consolidate package.from_uri tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Aug 29, 2019
1 parent d16a44f commit 8989750
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 59 deletions.
2 changes: 1 addition & 1 deletion docs/ethpm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Properties
Each ``Package`` exposes the following properties.

.. autoclass:: ethpm.Package
:members: name, version, manifest_version, uri, __repr__, build_dependencies, deployments
:members: name, version, manifest_version, uri, __repr__, contract_types, build_dependencies, deployments

.. py:attribute:: Package.w3
Expand Down
5 changes: 2 additions & 3 deletions ethpm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Any,
Dict,
Generator,
List,
Optional,
Tuple,
Union,
Expand Down Expand Up @@ -175,7 +176,6 @@ def uri(self) -> Optional[str]:
The uri (local file_path / content-addressed URI) of a ``Package``'s manifest.
"""
return self._uri


@property
def contract_types(self) -> List[str]:
Expand All @@ -187,7 +187,6 @@ def contract_types(self) -> List[str]:
else:
return ValueError("No contract types found in manifest; {self.__repr__()}.")


@classmethod
def from_file(cls, file_path: Path, w3: Web3) -> "Package":
"""
Expand All @@ -214,7 +213,7 @@ def from_uri(cls, uri: URI, w3: Web3) -> "Package":
URI schemes supported:
- IPFS `ipfs://Qm...`
- HTTP `https://api.github.com/repos/:owner/:repo/git/blobs/:file_sha`
- Registry `ercXXX://registry.eth/greeter?version=1.0.0`
- Registry `erc1319://registry.eth:1/greeter?version=1.0.0`
.. code:: python
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1440.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``contract_types`` property to ``Package`` class.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Package,
)
from ethpm.exceptions import (
CannotHandleURI,
EthPMValidationError,
)

Expand Down Expand Up @@ -95,3 +96,36 @@ def test_from_file_succeeds_with_valid_manifest(valid_manifest_from_path, w3):
def test_from_file_raises_type_error_with_invalid_param_type():
with pytest.raises(TypeError):
Package.from_file(1)


#
# From URI
#

VALID_IPFS_PKG = "ipfs://QmeD2s7KaBUoGYTP1eutHBmBkMMMoycdfiyGMx2DKrWXyV"


def test_package_from_uri_with_valid_uri(dummy_ipfs_backend, w3):
package = Package.from_uri(VALID_IPFS_PKG, w3)
assert package.name == "safe-math-lib"
assert isinstance(package, Package)


@pytest.mark.parametrize(
"uri",
(
# Invalid
"123",
b"123",
"ipfs://",
"http://QmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/readme",
"ipfsQmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/readme/",
# Unsupported
"erc111://packages.zeppelin.os/owned",
"bzz://da6adeeb4589d8652bbe5679aae6b6409ec85a20e92a8823c7c99e25dba9493d",
),
)
@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable')
def test_package_from_uri_rejects_invalid_ipfs_uri(uri, w3):
with pytest.raises(CannotHandleURI):
Package.from_uri(uri, w3)
22 changes: 0 additions & 22 deletions tests/ethpm/test_package_init_from_registry_uri.py

This file was deleted.

33 changes: 0 additions & 33 deletions tests/ethpm/test_package_init_from_uri.py

This file was deleted.

0 comments on commit 8989750

Please sign in to comment.