Skip to content

Commit

Permalink
Test separation of files from an object
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorJohn committed Jan 1, 2024
1 parent feeba7b commit ea0202e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ class Todo:
creator: User


@strawberry.input
class DocumentInput:
file: Upload
title: str


@strawberry.type
class Document:
title: str
length: int


users = [
User(id=strawberry.ID("0"), name="Amelia"),
User(id=strawberry.ID("1"), name="Bill"),
Expand Down Expand Up @@ -77,6 +89,11 @@ def read_files(self, files: typing.List[Upload]) -> typing.List[str]:
file.seek(0)
return contents

@strawberry.mutation
def read_document(self, document: DocumentInput) -> Document:
length = len(document.file.read().decode())
return Document(title=document.title, length=length)

@strawberry.mutation
def fake_user(self, id: strawberry.ID, name: str) -> User:
return User(id=id, name=name)
Expand Down
32 changes: 32 additions & 0 deletions tests/test_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,35 @@ async def test_using_in_single_file_under_multiple_paths(graphql_session, tmp_pa
]
}
}


async def test_separation_of_files_from_an_object(graphql_session):
file1 = BytesIO(b"Hello, World!")

query = """
mutation($document: DocumentInput!) {
readDocument(document: $document) {
title
length
}
}
"""

variables = {
"document": {
"file": file1,
"title": "Some Title",
}
}

client = GraphQLClient(endpoint="/graphql", session=graphql_session)
response = await client.execute(query, variables=variables)

assert await response.json() == {
"data": {
"readDocument": {
"title": "Some Title",
"length": 13,
}
}
}

0 comments on commit ea0202e

Please sign in to comment.