Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving unit tests for Aleph client commands #197

Draft
wants to merge 117 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
d80fd03
Moving fixture to a fixture folder.
danilo-silva-funttastic Jan 25, 2024
a81de1d
Splitting test_commands in different test files.
danilo-silva-funttastic Jan 25, 2024
120e20b
Improving test_utils.py test and applying simple best practices.
danilo-silva-funttastic Jan 25, 2024
7a39210
Improving test files and adding some more new tests.
danilo-silva-funttastic Jan 25, 2024
40f1ac8
Moving about tests.
danilo-silva-funttastic Jan 31, 2024
c2443b6
Adding unit tests for the domain command.
danilo-silva-funttastic Jan 31, 2024
0bb4df0
Adding unit tests for the aggregate command.
danilo-silva-funttastic Jan 31, 2024
c826674
Added a test for node compute
AlvaroEFMota Jan 31, 2024
97ab342
Adding unit tests for the program command (WIP).
danilo-silva-funttastic Jan 31, 2024
f15f6f2
Adding unit tests for the instance command.
darley-silva-funttastic Feb 1, 2024
3248923
Simple change.
danilo-silva-funttastic Feb 1, 2024
036fa4e
Merge branch 'aleph-master'
danilo-silva-funttastic Feb 5, 2024
3f03b50
Improving unit tests.
danilo-silva-funttastic Feb 6, 2024
a5b3138
Improving unittests at test_aggregate.py.
darley-silva-funttastic Feb 6, 2024
437ca61
Improving unit test
AlvaroEFMota Feb 6, 2024
9b11505
Solving conflicts.
danilo-silva-funttastic Feb 6, 2024
3c8eb94
Merge branch 'master' of github.com:FunttasticLabs/aleph-client
danilo-silva-funttastic Feb 6, 2024
8e95d7c
Improving unit test files.
danilo-silva-funttastic Feb 6, 2024
c1c857f
Updating unit tests from domain command.
danilo-silva-funttastic Feb 7, 2024
1351412
Improving unittests at test_help.py.
darley-silva-funttastic Feb 7, 2024
b4d19a7
Adding unit tests for the file command.
danilo-silva-funttastic Feb 7, 2024
9f9ab14
Updating unit tests from instance command.
AlvaroEFMota Feb 7, 2024
3ebbd32
Updating unit tests from instance command.
AlvaroEFMota Feb 7, 2024
bc19380
Adding unit tests for the node command.
danilo-silva-funttastic Feb 7, 2024
585a043
Merge branch 'master' of github.com:FunttasticLabs/aleph-client
danilo-silva-funttastic Feb 7, 2024
3bfed9b
Adding unit tests for the help command.
danilo-silva-funttastic Feb 7, 2024
cdee544
Improving unittests at test_message.py (wip).
darley-silva-funttastic Feb 7, 2024
3888b87
Updating unit tests from program command.
AlvaroEFMota Feb 7, 2024
e1c5815
Added tests on test_program.py
alvaro-mota-funttastic Feb 21, 2024
abadc53
Improving and fixing unit tests.
danilo-silva-funttastic Feb 21, 2024
2045fd9
Enabling unit test.
danilo-silva-funttastic Feb 21, 2024
af991d6
Fixing and improving account unit tests.
danilo-silva-funttastic Feb 26, 2024
5510fe9
Fixing and improving aggregate unit tests.
danilo-silva-funttastic Feb 26, 2024
74fd658
aleph test upload program passing
alvaro-mota-funttastic Feb 26, 2024
8ce325a
Structuring tests for ‘messages’ command.
darley-silva-funttastic Feb 26, 2024
270ae07
Restructuring tests for ‘domain’ command.
darley-silva-funttastic Mar 1, 2024
999e605
Adding new test aggreate comparing the full output.
danilo-silva-funttastic Mar 1, 2024
dddc37a
Working with the aggregate tests.
danilo-silva-funttastic Mar 1, 2024
2898693
Using fixture to get the item_hash
alvaro-mota-funttastic Mar 1, 2024
8a2b772
Working on tests for the "domain" command (wip).
darley-silva-funttastic Mar 1, 2024
dadae47
Merge branch 'master' into feature/commands-unit-tests
danilo-silva-funttastic Mar 11, 2024
aedf474
Fixed a bug on calling a asybc function withou await, working on prog…
alvaro-mota-funttastic Mar 11, 2024
3eeedd1
Fixed file upload test
alvaro-mota-funttastic Mar 11, 2024
cd72f3c
Cleaning up some tests
alvaro-mota-funttastic Mar 11, 2024
a6356bc
Cleaning up some tests
alvaro-mota-funttastic Mar 11, 2024
9f40c8b
Cleaning up some tests
alvaro-mota-funttastic Mar 11, 2024
5c84189
Removing some warnings
alvaro-mota-funttastic Mar 11, 2024
e4c6eaf
Possible fix to the aggregate command (needs to be reviewed).
danilo-silva-funttastic Mar 11, 2024
a7e6b26
Fixing test_aggregate.py unit tests. Some aspects needs review.
danilo-silva-funttastic Mar 11, 2024
2089896
test message post is passing
alvaro-mota-funttastic Mar 11, 2024
bfdba9e
Improving and fixing test_node.py unit tests.
danilo-silva-funttastic Mar 11, 2024
73958d3
Adding example ssh keys.
danilo-silva-funttastic Mar 20, 2024
7bae3a6
Adding new fixture.
danilo-silva-funttastic Mar 20, 2024
613b52a
Working with the instance command unit tests.
danilo-silva-funttastic Mar 20, 2024
a0fcaf5
Adding a dump function to the utils files.
danilo-silva-funttastic Apr 10, 2024
2208dc9
Moving fixture to a fixture folder.
danilo-silva-funttastic Jan 25, 2024
383d069
Splitting test_commands in different test files.
danilo-silva-funttastic Jan 25, 2024
6b1969e
Improving test_utils.py test and applying simple best practices.
danilo-silva-funttastic Jan 25, 2024
511fe1a
Improving test files and adding some more new tests.
danilo-silva-funttastic Jan 25, 2024
d087786
Moving about tests.
danilo-silva-funttastic Jan 31, 2024
a4b87dc
Adding unit tests for the domain command.
danilo-silva-funttastic Jan 31, 2024
e56facb
Adding unit tests for the aggregate command.
danilo-silva-funttastic Jan 31, 2024
2417b4c
Added a test for node compute
AlvaroEFMota Jan 31, 2024
191835e
Adding unit tests for the program command (WIP).
danilo-silva-funttastic Jan 31, 2024
54e04bc
Adding unit tests for the instance command.
darley-silva-funttastic Feb 1, 2024
6a66099
Simple change.
danilo-silva-funttastic Feb 1, 2024
84c6162
Improving unit tests.
danilo-silva-funttastic Feb 6, 2024
3f17b90
Improving unittests at test_aggregate.py.
darley-silva-funttastic Feb 6, 2024
aaab1c2
Improving unit test
AlvaroEFMota Feb 6, 2024
73112bb
Improving unit test files.
danilo-silva-funttastic Feb 6, 2024
921d95c
Updating unit tests from domain command.
danilo-silva-funttastic Feb 7, 2024
6f06f0f
Improving unittests at test_help.py.
darley-silva-funttastic Feb 7, 2024
66d0949
Adding unit tests for the file command.
danilo-silva-funttastic Feb 7, 2024
25c98b9
Adding unit tests for the node command.
danilo-silva-funttastic Feb 7, 2024
c34a803
Updating unit tests from instance command.
AlvaroEFMota Feb 7, 2024
ed64d9f
Updating unit tests from instance command.
AlvaroEFMota Feb 7, 2024
82ed621
Adding unit tests for the help command.
danilo-silva-funttastic Feb 7, 2024
7596582
Improving unittests at test_message.py (wip).
darley-silva-funttastic Feb 7, 2024
fb21fd3
Updating unit tests from program command.
AlvaroEFMota Feb 7, 2024
103f474
Added tests on test_program.py
alvaro-mota-funttastic Feb 21, 2024
7764296
Improving and fixing unit tests.
danilo-silva-funttastic Feb 21, 2024
35741ff
Enabling unit test.
danilo-silva-funttastic Feb 21, 2024
43f89fc
Fixing and improving account unit tests.
danilo-silva-funttastic Feb 26, 2024
d377560
Fixing and improving aggregate unit tests.
danilo-silva-funttastic Feb 26, 2024
74fdf60
aleph test upload program passing
alvaro-mota-funttastic Feb 26, 2024
bdc3032
Structuring tests for ‘messages’ command.
darley-silva-funttastic Feb 26, 2024
c628cf5
Restructuring tests for ‘domain’ command.
darley-silva-funttastic Mar 1, 2024
c174c9d
Adding new test aggreate comparing the full output.
danilo-silva-funttastic Mar 1, 2024
2fb4849
Working with the aggregate tests.
danilo-silva-funttastic Mar 1, 2024
372332a
Using fixture to get the item_hash
alvaro-mota-funttastic Mar 1, 2024
4d487e9
Working on tests for the "domain" command (wip).
darley-silva-funttastic Mar 1, 2024
6b00a46
Fixed a bug on calling a asybc function withou await, working on prog…
alvaro-mota-funttastic Mar 11, 2024
8507bb0
Fixed file upload test
alvaro-mota-funttastic Mar 11, 2024
399530f
Cleaning up some tests
alvaro-mota-funttastic Mar 11, 2024
8d92a33
Cleaning up some tests
alvaro-mota-funttastic Mar 11, 2024
85658f8
Cleaning up some tests
alvaro-mota-funttastic Mar 11, 2024
3bf9a5b
Removing some warnings
alvaro-mota-funttastic Mar 11, 2024
650e04a
Possible fix to the aggregate command (needs to be reviewed).
danilo-silva-funttastic Mar 11, 2024
eda6418
Fixing test_aggregate.py unit tests. Some aspects needs review.
danilo-silva-funttastic Mar 11, 2024
232558c
test message post is passing
alvaro-mota-funttastic Mar 11, 2024
a1fb18e
Improving and fixing test_node.py unit tests.
danilo-silva-funttastic Mar 11, 2024
dcc69c8
Adding example ssh keys.
danilo-silva-funttastic Mar 20, 2024
4c1236b
Adding new fixture.
danilo-silva-funttastic Mar 20, 2024
43e5bee
Working with the instance command unit tests.
danilo-silva-funttastic Mar 20, 2024
9705e05
Merge remote-tracking branch 'funttastic/feature/commands-unit-tests'…
MHHukiewitz Apr 29, 2024
0337fc1
Merge branch 'refs/heads/master' into feature/commands-unit-tests
MHHukiewitz Apr 29, 2024
a427835
WIP instance tests
MHHukiewitz Apr 29, 2024
5c57584
Fix tests, add specific exit codes and exit message function
MHHukiewitz Apr 29, 2024
f1b47d0
Fix exit_with_error_message
MHHukiewitz May 2, 2024
bfb346f
Fix message amend and add content property for non-interactive mode
MHHukiewitz May 2, 2024
e460689
Fix test_instance_delete
MHHukiewitz May 2, 2024
f7b43d9
Fix test_message_forget
MHHukiewitz May 2, 2024
4785527
Fix update program command
MHHukiewitz May 2, 2024
ff078e8
Fix create instance command
MHHukiewitz May 2, 2024
cae2c93
Remove unnecessary account path test
MHHukiewitz May 2, 2024
941c3e8
Allow -2 as SIGINT exit code because GH action!?
MHHukiewitz May 2, 2024
1a1f4e3
Fix mypy issues
MHHukiewitz May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ __pycache__/*
.pydevproject
.settings
.idea
*.iml
tags

# Package files
Expand Down
4 changes: 3 additions & 1 deletion src/aleph_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@

def __getattr__(name):
if name in moved_types:
raise ImportError(f"The 'aleph_client.{name}' type is deprecated and has been removed from aleph_client. Please use `aleph.sdk.{name}` instead.")
raise ImportError(
f"The 'aleph_client.{name}' type is deprecated and has been removed from aleph_client. Please use `aleph.sdk.{name}` instead."
)
14 changes: 2 additions & 12 deletions src/aleph_client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@
Aleph Client command-line interface.
"""

from aleph_client.commands import (about, account, aggregate, domain, files,
instance, message, node, program)
from aleph_client.utils import AsyncTyper

from aleph_client.commands import (
about,
account,
aggregate,
domain,
files,
instance,
message,
node,
program,
)

app = AsyncTyper(no_args_is_help=True)

app.add_typer(account.app, name="account", help="Manage account")
Expand Down
2 changes: 1 addition & 1 deletion src/aleph_client/commands/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_version(value: bool):
__version__ = get_distribution(dist_name).version
finally:
typer.echo(f"Aleph CLI Version: {__version__}")
raise typer.Exit(1)
raise typer.Exit()


@app.command()
Expand Down
28 changes: 15 additions & 13 deletions src/aleph_client/commands/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import base64
import json
import logging
import os
import sys
from pathlib import Path
from typing import Optional
Expand All @@ -14,10 +15,10 @@
from aleph.sdk.conf import settings as sdk_settings
from aleph.sdk.types import AccountFromPrivateKey
from aleph.sdk.utils import extended_json_encoder
from typer.colors import RED

from aleph_client.commands import help_strings
from aleph_client.commands.utils import setup_logging
from aleph_client.exit_codes import exit_with_error_message
from aleph_client.utils import AsyncTyper

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -45,9 +46,9 @@ def create(
)

if private_key_file.exists() and not replace:
typer.secho(f"Error: key already exists: '{private_key_file}'", fg=RED)

raise typer.Exit(1)
exit_with_error_message(
os.EX_CANTCREAT, f"key already exists: '{private_key_file}'"
)

private_key_bytes: bytes
if private_key is not None:
Expand All @@ -58,12 +59,11 @@ def create(
private_key_bytes = generate_key()

if not private_key_bytes:
typer.secho("An unexpected error occurred!", fg=RED)
raise typer.Exit(2)
exit_with_error_message(os.EX_DATAERR, "Failed to load private key")

private_key_file.parent.mkdir(parents=True, exist_ok=True)
private_key_file.write_bytes(private_key_bytes)
typer.secho(f"Private key stored in {private_key_file}", fg=RED)
typer.echo(f"Private key stored in {private_key_file}")


@app.command()
Expand All @@ -82,8 +82,7 @@ def address(
if private_key is not None:
private_key_file = None
elif private_key_file and not private_key_file.exists():
typer.secho("No private key available", fg=RED)
raise typer.Exit(code=1)
exit_with_error_message(os.EX_NOINPUT, "No private key provided")

account: AccountFromPrivateKey = _load_account(private_key, private_key_file)
typer.echo(account.get_address())
Expand All @@ -105,15 +104,16 @@ def export_private_key(
if private_key is not None:
private_key_file = None
elif private_key_file and not private_key_file.exists():
typer.secho("No private key available", fg=RED)
raise typer.Exit(code=1)
exit_with_error_message(os.EX_NOINPUT, "No private key provided")

account: AccountFromPrivateKey = _load_account(private_key, private_key_file)
if hasattr(account, "private_key"):
private_key_hex: str = base64.b16encode(account.private_key).decode().lower()
typer.echo(f"0x{private_key_hex}")
else:
typer.secho(f"Private key cannot be read for {account}", fg=RED)
exit_with_error_message(
os.EX_DATAERR, f"Private key cannot be read for {account}"
)


@app.command()
Expand Down Expand Up @@ -170,7 +170,9 @@ async def balance(
response = await session.get(uri)
if response.status == 200:
balance_data = await response.json()
formatted_balance_data = json.dumps(balance_data, indent=4, default=extended_json_encoder)
formatted_balance_data = json.dumps(
balance_data, indent=4, default=extended_json_encoder
)
typer.echo(formatted_balance_data)
else:
typer.echo(
Expand Down
20 changes: 14 additions & 6 deletions src/aleph_client/commands/aggregate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from pathlib import Path
from typing import Optional

Expand All @@ -13,6 +14,7 @@

from aleph_client.commands import help_strings
from aleph_client.commands.utils import setup_logging
from aleph_client.exit_codes import exit_with_error_message
from aleph_client.utils import AsyncTyper

app = AsyncTyper(no_args_is_help=True)
Expand Down Expand Up @@ -45,13 +47,16 @@ async def forget(
message_response = await client.get_messages(
message_filter=MessageFilter(
addresses=[account.get_address()],
message_types=[MessageType.aggregate.value],
MHHukiewitz marked this conversation as resolved.
Show resolved Hide resolved
message_types=[MessageType.aggregate],
content_keys=[key],
)
)
hash_list = [message["item_hash"] for message in message_response.messages]

await client.forget(hashes=hash_list, reason=reason, channel=channel)
hash_list = [message.item_hash for message in message_response.messages]

typer.echo(
await client.forget(hashes=hash_list, reason=reason, channel=channel)
)


@app.command()
Expand Down Expand Up @@ -81,8 +86,9 @@ async def post(
try:
content_dict = json.loads(content)
except json.JSONDecodeError:
typer.echo("Invalid JSON for content. Please provide valid JSON.")
raise typer.Exit(1)
exit_with_error_message(
os.EX_DATAERR, "Invalid JSON for content. Please provide valid JSON."
)

async with AuthenticatedAlephHttpClient(
account=account, api_server=sdk_settings.API_HOST
Expand All @@ -95,7 +101,9 @@ async def post(
inline=inline,
address=address,
)
log_message = json.dumps(message.dict(), indent=4, default=extended_json_encoder)
log_message = json.dumps(
message.dict(), indent=4, default=extended_json_encoder
)
typer.echo(log_message)


Expand Down
29 changes: 18 additions & 11 deletions src/aleph_client/commands/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
from aleph.sdk.account import _load_account
from aleph.sdk.client import AlephHttpClient, AuthenticatedAlephHttpClient
from aleph.sdk.conf import settings as sdk_settings
from aleph.sdk.domain import (
DomainValidator,
Hostname,
TargetType,
get_target_type,
hostname_from_url,
)
from aleph.sdk.domain import (DomainValidator, Hostname, TargetType,
get_target_type, hostname_from_url)
from aleph.sdk.exceptions import DomainConfigurationError
from aleph.sdk.query.filters import MessageFilter
from aleph.sdk.types import AccountFromPrivateKey
Expand Down Expand Up @@ -74,7 +69,9 @@ async def attach_resource(
item_hash = Prompt.ask("Enter Hash reference of the resource to attach")

while not spa:
is_spa: str = Prompt.ask("It is an SPA application?", choices=["y", "n"], default="n")
is_spa: str = Prompt.ask(
"It is an SPA application?", choices=["y", "n"], default="n"
)
spa = True if is_spa == "y" else False

table = Table(title=f"Attach resource to: {fqdn}")
Expand Down Expand Up @@ -281,7 +278,11 @@ async def attach(
account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

await attach_resource(
account, Hostname(fqdn), item_hash, interactive=False if (not ask) else None, spa=True if spa else None
account,
Hostname(fqdn),
item_hash,
interactive=False if (not ask) else None,
spa=True if spa else None,
)
raise typer.Exit()

Expand Down Expand Up @@ -339,14 +340,20 @@ async def info(
is_spa = ""
if resource_type == TargetType.IPFS:
final_resource = ""
is_spa = "True" if "spa" in domain_info["info"] and domain_info["info"]["spa"] == "1" else "False"
is_spa = (
"True"
if "spa" in domain_info["info"] and domain_info["info"]["spa"] == "1"
else "False"
)
elif resource_type == TargetType.PROGRAM:
final_resource = domain_info["info"]["message_id"]
if resource_type == TargetType.INSTANCE:
ips = await domain_validator.get_ipv6_addresses(Hostname(fqdn))
final_resource = ",".join([str(ip) for ip in ips])

table.add_row(resource_type, domain_info["info"]["message_id"], final_resource, is_spa)
table.add_row(
resource_type, domain_info["info"]["message_id"], final_resource, is_spa
)

console.print(table)
raise typer.Exit()
5 changes: 3 additions & 2 deletions src/aleph_client/commands/files.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json as json_lib
import logging
import os
from datetime import datetime
from pathlib import Path
from typing import Optional
Expand All @@ -19,6 +20,7 @@

from aleph_client.commands import help_strings
from aleph_client.commands.utils import setup_logging
from aleph_client.exit_codes import exit_with_error_message
from aleph_client.utils import AsyncTyper

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -82,8 +84,7 @@ async def upload(
account=account, api_server=sdk_settings.API_HOST
) as client:
if not path.is_file():
typer.echo(f"Error: File not found: '{path}'")
raise typer.Exit(code=1)
exit_with_error_message(os.EX_NOINPUT, f"No such file or directory: {path}")

with open(path, "rb") as fd:
logger.debug("Reading file")
Expand Down
Loading
Loading