Skip to content

Commit

Permalink
Merge pull request #2185 from shaangill025/fix_upgrade_process
Browse files Browse the repository at this point in the history
Update and automate ACA-Py upgrade process
  • Loading branch information
swcurran authored Mar 30, 2023
2 parents c061566 + ccce11f commit 19f1345
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 192 deletions.
114 changes: 82 additions & 32 deletions aries_cloudagent/commands/tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"),
)
),
Expand All @@ -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"),
)
),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"),
)
),
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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},
}
),
):
Expand All @@ -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(
Expand Down Expand Up @@ -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",
]
)

Expand Down Expand Up @@ -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",
Expand All @@ -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(
Expand Down
Loading

0 comments on commit 19f1345

Please sign in to comment.