Skip to content

Commit 168669b

Browse files
committed
refactor(BA-4092): Simplify repository test fixtures
- Merge purgable/non_purgable fixtures into single vfolder_in_db - Use indirect parametrization to pass status to fixture - Return only vfolder_id from fixture (status not needed)
1 parent bb3a24d commit 168669b

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

tests/unit/manager/repositories/vfolder/test_vfolder_repository.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -626,41 +626,51 @@ async def _vfolder_exists(self, db: ExtendedAsyncSAEngine, vfolder_id: uuid.UUID
626626
result = await session.execute(query)
627627
return result.scalar_one_or_none() is not None
628628

629+
@pytest.fixture
630+
async def vfolder_in_db(
631+
self,
632+
request: pytest.FixtureRequest,
633+
db_with_cleanup: ExtendedAsyncSAEngine,
634+
test_domain_name: str,
635+
test_user: uuid.UUID,
636+
) -> uuid.UUID:
637+
"""Create a vfolder with the given status in DB."""
638+
status: VFolderOperationStatus = request.param
639+
vfolder_id = uuid.uuid4()
640+
await self._create_vfolder_in_db(
641+
db_with_cleanup,
642+
vfolder_id=vfolder_id,
643+
domain_name=test_domain_name,
644+
user_id=test_user,
645+
status=status,
646+
)
647+
return vfolder_id
648+
629649
@pytest.mark.parametrize(
630-
"status",
650+
"vfolder_in_db",
631651
[
632652
VFolderOperationStatus.DELETE_COMPLETE,
633653
VFolderOperationStatus.DELETE_PENDING,
634654
],
635655
ids=["delete_complete", "delete_pending"],
656+
indirect=True,
636657
)
637658
async def test_purge_vfolder_success(
638659
self,
639660
db_with_cleanup: ExtendedAsyncSAEngine,
640661
vfolder_repository: VfolderRepository,
641-
test_domain_name: str,
642-
test_user: uuid.UUID,
643-
status: VFolderOperationStatus,
662+
vfolder_in_db: uuid.UUID,
644663
) -> None:
645664
"""Test successful purge of vfolder with purgable status."""
646-
vfolder_id = uuid.uuid4()
647-
await self._create_vfolder_in_db(
648-
db_with_cleanup,
649-
vfolder_id=vfolder_id,
650-
domain_name=test_domain_name,
651-
user_id=test_user,
652-
status=status,
653-
)
665+
vfolder_id = vfolder_in_db
654666

655667
# Verify vfolder exists before purge
656668
assert await self._vfolder_exists(db_with_cleanup, vfolder_id)
657669

658670
purger = Purger(row_class=VFolderRow, pk_value=vfolder_id)
659671
result = await vfolder_repository.purge_vfolder(purger)
660672

661-
# Verify result contains correct data
662673
assert result.id == vfolder_id
663-
assert result.status == status
664674

665675
# Verify vfolder is deleted from DB
666676
assert not await self._vfolder_exists(db_with_cleanup, vfolder_id)
@@ -677,7 +687,7 @@ async def test_purge_vfolder_not_found(
677687
await vfolder_repository.purge_vfolder(purger)
678688

679689
@pytest.mark.parametrize(
680-
"status",
690+
"vfolder_in_db",
681691
[
682692
VFolderOperationStatus.READY,
683693
VFolderOperationStatus.PERFORMING,
@@ -687,24 +697,16 @@ async def test_purge_vfolder_not_found(
687697
VFolderOperationStatus.DELETE_ERROR,
688698
],
689699
ids=["ready", "performing", "cloning", "mounted", "delete_ongoing", "delete_error"],
700+
indirect=True,
690701
)
691702
async def test_purge_vfolder_invalid_status(
692703
self,
693704
db_with_cleanup: ExtendedAsyncSAEngine,
694705
vfolder_repository: VfolderRepository,
695-
test_domain_name: str,
696-
test_user: uuid.UUID,
697-
status: VFolderOperationStatus,
706+
vfolder_in_db: uuid.UUID,
698707
) -> None:
699708
"""Test purge fails when vfolder has non-purgable status."""
700-
vfolder_id = uuid.uuid4()
701-
await self._create_vfolder_in_db(
702-
db_with_cleanup,
703-
vfolder_id=vfolder_id,
704-
domain_name=test_domain_name,
705-
user_id=test_user,
706-
status=status,
707-
)
709+
vfolder_id = vfolder_in_db
708710

709711
purger = Purger(row_class=VFolderRow, pk_value=vfolder_id)
710712

0 commit comments

Comments
 (0)