Skip to content

Commit

Permalink
CR @njgheorghita, updated params and console output
Browse files Browse the repository at this point in the history
  • Loading branch information
corydickson committed Mar 28, 2020
1 parent cf86df3 commit 2b660af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
14 changes: 7 additions & 7 deletions ethpm_cli/commands/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from eth_utils.toolz import assoc, assoc_in, dissoc
from ethpm.backends.registry import is_valid_registry_uri, parse_registry_uri
from ethpm.constants import SUPPORTED_CHAIN_IDS
from web3 import Web3

from ethpm_cli._utils.filesystem import atomic_replace
from ethpm_cli._utils.logger import cli_logger
Expand Down Expand Up @@ -117,7 +118,7 @@ def explore_registry(uri_or_alias: str, config: Config) -> None:
parsed_registry_uri = parse_registry_uri(registry.uri)
config.w3.pm.set_registry(parsed_registry_uri.address)
package_names = config.w3.pm.get_all_package_names()
display_packages(package_names, config)
display_packages(package_names, config.w3)


def resolve_uri_or_alias(uri_or_alias: str, store_path: Path) -> StoredRegistry:
Expand Down Expand Up @@ -218,13 +219,12 @@ def generate_registry_store_data(
}


def display_packages(all_package_names: Iterable[str], config: Config) -> None:
def display_packages(all_package_names: Iterable[str], w3: Web3) -> None:
cli_logger.info(f"Packages in the registry: {w3.pm.get_package_count()}\n")
for package_name in all_package_names:
all_releases = config.w3.pm.get_all_package_releases(package_name)
cli_logger.info(f"Retrieving all releases for {bold_blue(package_name)}: \n")
all_releases = w3.pm.get_all_package_releases(package_name)
for version, manifest_uri in all_releases:
cli_logger.info(f"{bold_green(version)} --- ({bold_white(manifest_uri)})")
cli_logger.info(
f"Total releases: {config.w3.pm.get_release_count(package_name)}\n"
)
cli_logger.info(f"Packages in the registry: {config.w3.pm.get_package_count()}\n")

cli_logger.info(f"Total releases: {len(all_releases)}\n")
41 changes: 18 additions & 23 deletions tests/core/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,11 @@ def test_unable_to_activate_nonexistent_aliased_registry(config):


@pytest.mark.parametrize(
"uri,alias,valid,expected",
"uri,alias,expected",
(
(
URI_1,
"home",
True,
{
"uri": "erc1319://0x1230000000000000000000000000000000000000:1",
"alias": "home",
Expand All @@ -159,33 +158,29 @@ def test_unable_to_activate_nonexistent_aliased_registry(config):
(
URI_2,
"owned",
True,
{
"uri": "erc1319://0xabc0000000000000000000000000000000000000:1",
"alias": "owned",
},
),
(
URI_1,
"fake",
False,
{
"uri": "erc1319://0x1230000000000000000000000000000000000000:1",
"alias": "fake",
},
),
),
)
def test_resolve_uri_or_alias_raises_error(config, uri, alias, valid, expected):
def test_resolve_uri_or_alias(config, uri, alias, expected):
store_path = config.xdg_ethpmcli_root / REGISTRY_STORE
add_registry(uri, alias, config)
if valid:
registry = resolve_uri_or_alias(alias, store_path)
assert registry.alias == expected["alias"]
registry = resolve_uri_or_alias(uri, store_path)
assert registry.uri == expected["uri"]
else:
with pytest.raises(InstallError):
resolve_uri_or_alias("other", store_path)
with pytest.raises(InstallError):
resolve_uri_or_alias(URI_2, store_path)
registry = resolve_uri_or_alias(alias, store_path)
assert registry.alias == expected["alias"]
registry = resolve_uri_or_alias(uri, store_path)
assert registry.uri == expected["uri"]


@pytest.mark.parametrize(
"uri,alias", ((URI_1, "home",), (URI_2, "owned",),),
)
def test_resolve_uri_or_alias_raises_install_error(config, uri, alias):
store_path = config.xdg_ethpmcli_root / REGISTRY_STORE
add_registry(uri, alias, config)
with pytest.raises(InstallError):
resolve_uri_or_alias("other", store_path)
with pytest.raises(InstallError):
resolve_uri_or_alias("foo://", store_path)

0 comments on commit 2b660af

Please sign in to comment.