Skip to content

Commit

Permalink
Add tests for field descriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgadling committed Aug 27, 2024
1 parent c36481d commit 6aa15fc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 54 deletions.
1 change: 1 addition & 0 deletions test_app/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ classes:
- EntityMixin
attributes:
name:
description: This is a field description
range: string
required: true
auto_inc_field:
Expand Down
54 changes: 0 additions & 54 deletions test_app/tests/test_auto_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,6 @@

date_now = datetime.datetime.now()


@pytest.mark.asyncio
async def test_graphql_query(
sync_db: SyncDB,
gql_client: GQLTestClient,
) -> None:
"""
Test that we can only fetch samples from the database that we have access to
"""
user_id = 12345
secondary_user_id = 67890
project_id = 123

# Create mock data
with sync_db.session() as session:
SessionStorage.set_session(session)
SampleFactory.create_batch(
2,
collection_location="San Francisco, CA",
collection_date=date_now,
owner_user_id=user_id,
collection_id=project_id,
)
SampleFactory.create_batch(
6,
collection_location="Mountain View, CA",
collection_date=date_now,
owner_user_id=user_id,
collection_id=project_id,
)
SampleFactory.create_batch(
4,
collection_location="Phoenix, AZ",
collection_date=date_now,
owner_user_id=secondary_user_id,
collection_id=9999,
)

# Fetch all samples
query = """
query MyQuery {
samples {
id,
collectionLocation
}
}
"""
output = await gql_client.query(query, user_id=user_id, member_projects=[project_id])
locations = [sample["collectionLocation"] for sample in output["data"]["samples"]]
assert "San Francisco, CA" in locations
assert "Mountain View, CA" in locations
assert "Phoenix, AZ" not in locations


@pytest.mark.asyncio
async def test_autoupdate_fields(gql_client: GQLTestClient, sync_db: SyncDB) -> None:
"""
Expand Down
38 changes: 38 additions & 0 deletions test_app/tests/test_field_descriptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Test that field descriptions are present in the GQL API
"""

import datetime
import pytest
from conftest import GQLTestClient

date_now = datetime.datetime.now()


@pytest.mark.asyncio
async def test_field_description(
gql_client: GQLTestClient,
) -> None:
"""
Test that we can only fetch samples from the database that we have access to
"""

# Fetch all samples
query = """
{
__type(name: "AutoUpdatedType") {
name
fields {
name
description
}
}
}
"""
output = await gql_client.query(query, user_id=999, member_projects=[999])
fields = output["data"]["__type"]["fields"]
field = {}
for field in fields:
if field["name"] == "name":
break
assert field["description"] == "This is a field description"

0 comments on commit 6aa15fc

Please sign in to comment.