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

Update and automate ACA-Py upgrade process #2185

Merged
merged 6 commits into from
Mar 30, 2023
Merged
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
114 changes: 82 additions & 32 deletions aries_cloudagent/commands/tests/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -17,10 +17,7 @@ class TestUpgrade(AsyncTestCase):
async def setUp(self):
self.session = InMemoryProfile.test_session()
self.profile = self.session.profile

self.session_storage = InMemoryProfile.test_session()
self.profile_storage = self.session_storage.profile
self.storage = self.session_storage.inject(BaseStorage)
self.storage = self.session.inject(BaseStorage)
record = StorageRecord(
"acapy_version",
"v0.7.2",
@@ -37,7 +34,7 @@ async def test_upgrade_storage_from_version_included(self):
"wallet_config",
async_mock.CoroutineMock(
return_value=(
self.profile_storage,
self.profile,
async_mock.CoroutineMock(did="public DID", verkey="verkey"),
)
),
@@ -61,7 +58,7 @@ async def test_upgrade_storage_missing_from_version(self):
"wallet_config",
async_mock.CoroutineMock(
return_value=(
self.profile_storage,
self.profile,
async_mock.CoroutineMock(did="public DID", verkey="verkey"),
)
),
@@ -98,6 +95,10 @@ async def test_upgrade_from_version(self):
)

async def test_upgrade_callable(self):
version_storage_record = await self.storage.find_record(
type_filter="acapy_version", tag_query={}
)
await self.storage.delete_record(version_storage_record)
with async_mock.patch.object(
test_module,
"wallet_config",
@@ -139,7 +140,7 @@ async def test_upgrade_x_same_version(self):
"wallet_config",
async_mock.CoroutineMock(
return_value=(
self.profile_storage,
self.profile,
async_mock.CoroutineMock(did="public DID", verkey="verkey"),
)
),
@@ -151,6 +152,10 @@ async def test_upgrade_x_same_version(self):
)

async def test_upgrade_missing_from_version(self):
version_storage_record = await self.storage.find_record(
type_filter="acapy_version", tag_query={}
)
await self.storage.delete_record(version_storage_record)
with async_mock.patch.object(
test_module,
"wallet_config",
@@ -167,13 +172,19 @@ async def test_upgrade_missing_from_version(self):
), async_mock.patch.object(
ConnRecord, "save", async_mock.CoroutineMock()
):
await test_module.upgrade(
{
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
}
)
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
}
)
assert "No upgrade from version found in wallet or" in str(ctx.exception)

async def test_upgrade_x_callable_not_set(self):
version_storage_record = await self.storage.find_record(
type_filter="acapy_version", tag_query={}
)
await self.storage.delete_record(version_storage_record)
with async_mock.patch.object(
test_module,
"wallet_config",
@@ -196,7 +207,7 @@ async def test_upgrade_x_callable_not_set(self):
},
"update_existing_records": True,
},
"v0.6.0": {"update_existing_records": True},
"v0.6.0": {"update_existing_records_b": True},
}
),
):
@@ -206,7 +217,7 @@ async def test_upgrade_x_callable_not_set(self):
"upgrade.from_version": "v0.6.0",
}
)
assert "No update_existing_records function specified" in str(ctx.exception)
assert "No function specified for" in str(ctx.exception)

async def test_upgrade_x_class_not_found(self):
with async_mock.patch.object(
@@ -268,7 +279,8 @@ async def test_execute(self):
"--upgrade-config",
"./aries_cloudagent/config/tests/test-acapy-upgrade-config.yaml",
"--from-version",
"v0.7.2",
"v0.7.0",
"--force-upgrade",
]
)

@@ -305,17 +317,7 @@ async def test_upgrade_x_invalid_record_type(self):
)
assert "Only BaseRecord can be resaved" in str(ctx.exception)

async def test_upgrade_x_invalid_config(self):
with async_mock.patch.object(
test_module.yaml,
"safe_load",
async_mock.MagicMock(return_value={}),
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade({})
assert "No version configs found in" in str(ctx.exception)

async def test_upgrade_x_from_version_not_in_config(self):
async def test_upgrade_force(self):
with async_mock.patch.object(
test_module,
"wallet_config",
@@ -325,14 +327,62 @@ async def test_upgrade_x_from_version_not_in_config(self):
async_mock.CoroutineMock(did="public DID", verkey="verkey"),
)
),
), async_mock.patch.object(
test_module.yaml,
"safe_load",
async_mock.MagicMock(
return_value={
"v0.7.2": {
"resave_records": {
"base_record_path": [
"aries_cloudagent.connections.models.conn_record.ConnRecord"
],
},
"update_existing_records": True,
},
"v0.7.3": {
"update_existing_records": True,
},
"v0.7.1": {
"update_existing_records": False,
},
}
),
):
await test_module.upgrade(
{
"upgrade.from_version": "v0.7.0",
"upgrade.force_upgrade": True,
}
)

async def test_get_upgrade_version_list(self):
assert len(test_module.get_upgrade_version_list(from_version="v0.7.2")) >= 1

async def test_add_version_record(self):
await test_module.add_version_record(self.profile, "v0.7.4")
version_storage_record = await self.storage.find_record(
type_filter="acapy_version", tag_query={}
)
assert version_storage_record.value == "v0.7.4"
await self.storage.delete_record(version_storage_record)
with self.assertRaises(test_module.StorageNotFoundError):
await self.storage.find_record(type_filter="acapy_version", tag_query={})
await test_module.add_version_record(self.profile, "v0.7.5")
version_storage_record = await self.storage.find_record(
type_filter="acapy_version", tag_query={}
)
assert version_storage_record.value == "v0.7.5"

async def test_upgrade_x_invalid_config(self):
with async_mock.patch.object(
test_module.yaml,
"safe_load",
async_mock.MagicMock(return_value={}),
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
"upgrade.from_version": "v1.2.3",
}
)
assert "No upgrade configuration found for" in str(ctx.exception)
await test_module.upgrade({})
assert "No version configs found in" in str(ctx.exception)

def test_main(self):
with async_mock.patch.object(
Loading