Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robertaboukhalil committed Oct 9, 2023
1 parent e5fb545 commit 85f4425
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 234 deletions.
5 changes: 3 additions & 2 deletions entities/api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def generate_multipart_upload_token(
new_file: db.File,
expiration: int = 3600,
sts_client: STSClient = Depends(get_sts_client),
):
) -> MultipartUploadCredentials:
policy = {
"Version": "2012-10-17",
"Statement": [
Expand Down Expand Up @@ -182,10 +182,11 @@ async def create_file(
cerbos_client: CerbosClient = Depends(get_cerbos_client),
principal: Principal = Depends(require_auth_principal),
s3_client: S3Client = Depends(get_s3_client),
sts_client: STSClient = Depends(get_sts_client),
settings: APISettings = Depends(get_settings),
) -> db.File:
new_file = await create_or_upload_file(
entity_id, entity_field_name, file, -1, session, cerbos_client, principal, s3_client, None, settings
entity_id, entity_field_name, file, -1, session, cerbos_client, principal, s3_client, sts_client, settings
)
assert isinstance(new_file, db.File) # reassure mypy that we're returning the right type
return new_file
Expand Down
25 changes: 16 additions & 9 deletions entities/api/tests/test_file_writes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def test_invalid_fastq(
assert fileinfo["status"] == "FAILED"


# Test generating signed URLs for file upload
# Test generating STS tokens for file uploads
@pytest.mark.asyncio
@pytest.mark.parametrize(
"member_projects,project_id,entity_field",
Expand Down Expand Up @@ -121,14 +121,19 @@ async def test_upload_file(
# Try creating a file
mutation = f"""
mutation MyQuery {{
uploadFile(entityId: "{entity_id}", entityFieldName: "{entity_field}", file: {{
name: "test.fastq", fileFormat: "fastq"
}}) {{
url
uploadFile(
entityId: "{entity_id}",
entityFieldName: "{entity_field}",
file: {{
name: "test.fastq",
fileFormat: "fastq"
}}
) {{
namespace
path
accessKeyId
secretAccessKey
expiration
method
protocol
fields
}}
}}
"""
Expand All @@ -140,7 +145,9 @@ async def test_upload_file(
assert output["errors"] is not None
return

assert output["data"]["uploadFile"]["url"] == "https://local-bucket.s3.amazonaws.com/"
# Moto produces a hard-coded tokens
assert output["data"]["uploadFile"]["accessKeyId"].endswith("EXAMPLE")
assert output["data"]["uploadFile"]["secretAccessKey"].endswith("EXAMPLEKEY")


# Test adding an existing file to the entities service
Expand Down
Loading

0 comments on commit 85f4425

Please sign in to comment.