Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
- name: Ruff Format and Lint Check
uses: chartboost/ruff-action@v1
with:
version: 0.5.7
version: 0.8.0
args: "format --check"
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.16.0
rev: v9.18.0
hooks:
- id: commitlint
stages: [commit-msg]
args: ["--config", ".commitlint.config.js"]
additional_dependencies: ['@commitlint/config-conventional']
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ensure this is synced with pyproject.toml
rev: v0.5.7
rev: v0.8.1
hooks:
# Run the linter
- id: ruff
Expand Down
8 changes: 6 additions & 2 deletions acapy_agent/askar/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,19 @@ async def provision(
) -> Profile:
"""Provision a new instance of a profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=True)
opened = await store_config.open_store(
provision=True, in_memory=config.get("test")
)
return AskarProfile(opened, context)

async def open(
self, context: InjectionContext, config: Mapping[str, Any] = None
) -> Profile:
"""Open an instance of an existing profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=False)
opened = await store_config.open_store(
provision=False, in_memory=config.get("test")
)
return AskarProfile(opened, context)

@classmethod
Expand Down
8 changes: 6 additions & 2 deletions acapy_agent/askar/profile_anon.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,19 @@ async def provision(
) -> Profile:
"""Provision a new instance of a profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=True)
opened = await store_config.open_store(
provision=True, in_memory=config.get("test")
)
return AskarAnoncredsProfile(opened, context)

async def open(
self, context: InjectionContext, config: Mapping[str, Any] = None
) -> Profile:
"""Open an instance of an existing profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=False)
opened = await store_config.open_store(
provision=False, in_memory=config.get("test")
)
return AskarAnoncredsProfile(opened, context)

@classmethod
Expand Down
29 changes: 16 additions & 13 deletions acapy_agent/askar/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import pytest

from ...askar.profile import AskarProfile
from ...askar.profile import AskarProfile, AskarProfileManager
from ...config.injection_context import InjectionContext
from ...ledger.base import BaseLedger
from .. import profile as test_module
from ..profile_anon import AskarAnonProfileManager


@pytest.fixture
Expand Down Expand Up @@ -107,15 +108,17 @@ async def test_profile_manager_transaction():

@pytest.mark.asyncio
async def test_profile_manager_store():
profile = "profileId"

with mock.patch("acapy_agent.askar.profile.AskarProfile") as AskarProfile:
askar_profile = AskarProfile(None, False, profile_id=profile)
askar_profile.profile_id = profile
askar_profile_session = mock.MagicMock()
askar_profile.store.session.return_value = askar_profile_session

sessionProfile = test_module.AskarProfileSession(askar_profile, False)

assert sessionProfile._opener == askar_profile_session
askar_profile.store.session.assert_called_once_with(profile)
config = {
"test": True,
}
context = InjectionContext(
settings=config,
)
await AskarProfileManager().provision(
context=context,
config=config,
)
await AskarAnonProfileManager().provision(
context=context,
config=config,
)
18 changes: 8 additions & 10 deletions acapy_agent/commands/tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@

class TestHelp(IsolatedAsyncioTestCase):
def test_exec_help(self):
with mock.patch.object(
command.ArgumentParser, "print_help"
) as mock_print_help, mock.patch(
"builtins.print", mock.MagicMock()
) as mock_print:
with (
mock.patch.object(command.ArgumentParser, "print_help") as mock_print_help,
mock.patch("builtins.print", mock.MagicMock()) as mock_print,
):
command.execute([])
mock_print_help.assert_called_once()

command.execute(["-v"])
mock_print.assert_called_once_with(command.__version__)

def test_main(self):
with mock.patch.object(
command, "__name__", "__main__"
) as mock_name, mock.patch.object(
command, "execute", mock.MagicMock()
) as mock_execute:
with (
mock.patch.object(command, "__name__", "__main__") as mock_name,
mock.patch.object(command, "execute", mock.MagicMock()) as mock_execute,
):
command.main()
mock_execute.assert_called_once
43 changes: 24 additions & 19 deletions acapy_agent/commands/tests/test_provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ def test_bad_calls(self):

async def test_provision_ledger_configured(self):
profile = mock.MagicMock(close=mock.CoroutineMock())
with mock.patch.object(
test_module,
"wallet_config",
mock.CoroutineMock(
return_value=(
profile,
mock.CoroutineMock(did="public DID", verkey="verkey"),
)
with (
mock.patch.object(
test_module,
"wallet_config",
mock.CoroutineMock(
return_value=(
profile,
mock.CoroutineMock(did="public DID", verkey="verkey"),
)
),
),
mock.patch.object(
test_module, "ledger_config", mock.CoroutineMock(return_value=True)
),
), mock.patch.object(
test_module, "ledger_config", mock.CoroutineMock(return_value=True)
):
await test_module.provision({})

Expand All @@ -44,9 +47,10 @@ async def test_provision_config_x(self):
await test_module.provision({})

def test_main(self):
with mock.patch.object(test_module, "__name__", "__main__"), mock.patch.object(
test_module, "execute", mock.MagicMock()
) as mock_execute:
with (
mock.patch.object(test_module, "__name__", "__main__"),
mock.patch.object(test_module, "execute", mock.MagicMock()) as mock_execute,
):
test_module.main()
mock_execute.assert_called_once

Expand All @@ -55,12 +59,13 @@ async def test_provision_should_store_provided_mediation_invite(self):
mediation_invite = "test-invite"
test_profile = await create_test_profile()

with mock.patch.object(
test_module.MediationInviteStore, "store"
) as invite_store, mock.patch.object(
test_module,
"wallet_config",
mock.CoroutineMock(return_value=(test_profile, mock.MagicMock())),
with (
mock.patch.object(test_module.MediationInviteStore, "store") as invite_store,
mock.patch.object(
test_module,
"wallet_config",
mock.CoroutineMock(return_value=(test_profile, mock.MagicMock())),
),
):
# when
await test_module.provision({"mediation.invite": mediation_invite})
Expand Down
52 changes: 26 additions & 26 deletions acapy_agent/commands/tests/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ async def test_start_shutdown_app(self):
await test_module.shutdown_app(mock_conductor)

def test_exec_start(self):
with mock.patch.object(
# Normally this would be a CoroutineMock. However, it is awaited by
# run_loop, which is mocked out. So we mock it as a MagicMock.
test_module,
"start_app",
mock.MagicMock(),
) as start_app, mock.patch.object(
test_module, "run_loop"
) as run_loop, mock.patch.object(
# Same here as note above
test_module,
"shutdown_app",
mock.MagicMock(),
) as shutdown_app, mock.patch.object(
test_module, "uvloop", mock.MagicMock()
) as mock_uvloop:
with (
mock.patch.object(
# Normally this would be a CoroutineMock. However, it is awaited by
# run_loop, which is mocked out. So we mock it as a MagicMock.
test_module,
"start_app",
mock.MagicMock(),
) as start_app,
mock.patch.object(test_module, "run_loop") as run_loop,
mock.patch.object(
# Same here as note above
test_module,
"shutdown_app",
mock.MagicMock(),
) as shutdown_app,
mock.patch.object(test_module, "uvloop", mock.MagicMock()) as mock_uvloop,
):
mock_uvloop.install = mock.MagicMock()
test_module.execute(
[
Expand All @@ -54,6 +55,7 @@ def test_exec_start(self):
"0.0.0.0",
"80",
"--no-ledger",
"--wallet-test",
]
)
start_app.assert_called_once()
Expand Down Expand Up @@ -102,11 +104,10 @@ async def test_run_loop_init_x(self):
startup_call = startup()
shutdown = mock.CoroutineMock()
shutdown_call = shutdown()
with mock.patch.object(
test_module, "asyncio", autospec=True
) as mock_asyncio, mock.patch.object(
test_module, "LOGGER", autospec=True
) as mock_logger:
with (
mock.patch.object(test_module, "asyncio", autospec=True) as mock_asyncio,
mock.patch.object(test_module, "LOGGER", autospec=True) as mock_logger,
):
test_module.run_loop(startup_call, shutdown_call)
mock_add = mock_asyncio.get_event_loop.return_value.add_signal_handler
mock_add.assert_called_once()
Expand Down Expand Up @@ -135,10 +136,9 @@ async def test_run_loop_init_x(self):
mock_logger.exception.assert_called_once()

def test_main(self):
with mock.patch.object(
test_module, "__name__", "__main__"
) as mock_name, mock.patch.object(
test_module, "execute", mock.MagicMock()
) as mock_execute:
with (
mock.patch.object(test_module, "__name__", "__main__") as mock_name,
mock.patch.object(test_module, "execute", mock.MagicMock()) as mock_execute,
):
test_module.main()
mock_execute.assert_called_once
Loading
Loading