Skip to content

Commit

Permalink
test(storage): fix async troubles
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm committed Aug 24, 2024
1 parent 6adbd6a commit 4cc6e51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/api/api_v1/endpoints/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def register_organization(
)
organization = await organizations.create(payload)
bucket_name = s3_service.resolve_bucket_name(organization.id)
if not (await s3_service.create_bucket(bucket_name)):
if not s3_service.create_bucket(bucket_name):
# Delete the organization if the bucket creation failed
await organizations.delete(organization.id)
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to create bucket")
Expand Down
9 changes: 6 additions & 3 deletions src/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import io
from datetime import datetime
from typing import AsyncGenerator, Dict, Generator

Expand Down Expand Up @@ -177,7 +178,7 @@ async def organization_session(async_session: AsyncSession):
await async_session.commit()
# Create buckets
for entry in ORGANIZATION_TABLE:
await s3_service.create_bucket(s3_service.resolve_bucket_name(entry["id"]))
s3_service.create_bucket(s3_service.resolve_bucket_name(entry["id"]))
yield async_session
await async_session.rollback()
# Delete buckets
Expand Down Expand Up @@ -227,12 +228,14 @@ async def detection_session(
await user_session.commit()
# Create bucket files
for entry in DET_TABLE:
await s3_service.upload_file(s3_service.resolve_bucket_name(entry["camera_id"]), entry["bucket_key"], b"")
bucket = s3_service.get_bucket(s3_service.resolve_bucket_name(entry["camera_id"]))
bucket.upload_file(entry["bucket_key"], io.BytesIO(b""))
yield user_session
await user_session.rollback()
# Delete bucket files
for entry in DET_TABLE:
await s3_service.delete_file(s3_service.resolve_bucket_name(entry["camera_id"]), entry["bucket_key"])
bucket = s3_service.get_bucket(s3_service.resolve_bucket_name(entry["camera_id"]))
bucket.delete_file(entry["bucket_key"])


def get_token(access_id: int, scopes: str, organizationid: int) -> Dict[str, str]:
Expand Down

0 comments on commit 4cc6e51

Please sign in to comment.