Skip to content

Commit

Permalink
Add nodes/full_types_count/user endpoint
Browse files Browse the repository at this point in the history
Implementation as in aiida-core.
  • Loading branch information
agoscinski committed Nov 21, 2024
1 parent 3109b30 commit df96544
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aiida_restapi/routers/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ async def get_full_types() -> dict[str, Any]:
return get_node_namespace(user_pk=None, count_nodes=False).get_description()


@router.get('/nodes/full_types_count', response_model=dict[str, Any])
@with_dbenv()
async def get_full_types_count(user: Optional[int] = None) -> dict[str, Any]:
"""Return full_types_count of the nodes"""
return get_node_namespace(user_pk=user, count_nodes=True).get_description()


@router.get('/nodes/{nodes_id}', response_model=models.Node)
@with_dbenv()
async def read_node(nodes_id: int) -> Optional[models.Node]:
Expand Down
89 changes: 89 additions & 0 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,92 @@ def test_get_full_types(default_computers, example_processes, default_groups, de
},
],
}


@pytest.mark.anyio
async def test_get_full_types_count(default_nodes, async_client):
"""Test get full_types_count nodes."""

default_user_reference_json = {
'namespace': 'node',
'full_type': 'node.%|',
'label': 'node',
'path': 'node',
'subspaces': [
{
'namespace': 'data',
'full_type': 'data.%|',
'label': 'Data',
'path': 'node.data',
'subspaces': [
{
'namespace': 'core',
'full_type': 'data.core.%|',
'label': 'core',
'path': 'node.data.core',
'subspaces': [
{
'namespace': 'bool',
'full_type': 'data.core.bool.Bool.|',
'label': 'Bool',
'path': 'node.data.core.bool',
'subspaces': [],
'counter': 1,
},
{
'namespace': 'float',
'full_type': 'data.core.float.Float.|',
'label': 'Float',
'path': 'node.data.core.float',
'subspaces': [],
'counter': 1,
},
{
'namespace': 'int',
'full_type': 'data.core.int.Int.|',
'label': 'Int',
'path': 'node.data.core.int',
'subspaces': [],
'counter': 1,
},
{
'namespace': 'str',
'full_type': 'data.core.str.Str.|',
'label': 'Str',
'path': 'node.data.core.str',
'subspaces': [],
'counter': 1,
},
],
'counter': 4,
}
],
'counter': 4,
}
],
'counter': 4,
}

# Test without specifiying user, should use default user
response = await async_client.get('/nodes/full_types_count')
assert response.status_code == 200, response.json()
assert response.json() == default_user_reference_json

# Test that the output is the same when we use the pk of the default user
from aiida import orm

default_user_pk = orm.User(email='').collection.get_default().pk
response = await async_client.get(f'/nodes/full_types_count?user={default_user_pk}')
assert response.status_code == 200, response.json()
assert response.json() == default_user_reference_json

# Test empty response for nonexisting user
response = await async_client.get('/nodes/full_types_count?user=99999')
assert response.status_code == 200, response.json()
assert response.json() == {
'namespace': 'node',
'full_type': 'node.%|',
'label': 'node',
'path': 'node',
'subspaces': [],
}

0 comments on commit df96544

Please sign in to comment.