Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Nov 20, 2024
1 parent fc596eb commit 2850056
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 19 deletions.
27 changes: 12 additions & 15 deletions aiida_restapi/routers/nodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Declaration of FastAPI application."""

from __future__ import annotations

import json
import os
import tempfile
Expand Down Expand Up @@ -44,6 +46,14 @@ async def get_nodes_download_formats() -> dict[str, Any]:
return models.Node.get_all_download_formats()


@router.get('/nodes/full_types', response_model=dict[str, Any])
@with_dbenv()
async def get_full_types() -> dict[str, Any]:
"""Return full_types of the nodes"""
result = get_node_namespace(user_pk=None, count_nodes=False).get_description()
return result


@router.get('/nodes/{nodes_id}', response_model=models.Node)
@with_dbenv()
async def read_node(nodes_id: int) -> Optional[models.Node]:
Expand Down Expand Up @@ -134,16 +144,6 @@ async def create_upload_file(
return models.Node.from_orm(orm_object)


from typing import Any # noqa: E402


@router.post('/nodes/full_types', response_model=dict[str, Any])
@with_dbenv()
async def get_full_types() -> dict[str, Any]:
"""Return full_types of the nodes"""
return get_node_namespace(user_pk=None, count_nodes=False).get_description()


### TODO move to identifiers
def construct_full_type(node_type: str, process_type: str) -> str:
"""Return the full type, which uniquely identifies any `Node` with the given `node_type` and `process_type`.
Expand Down Expand Up @@ -242,13 +242,10 @@ def _infer_full_type(self, full_type: Union[str, None]) -> Union[str, None]:
"""Infer the full type based on the current namespace path and the given full type of the leaf."""
from aiida.common.utils import strip_prefix

if full_type is None or self._path is None:
if full_type or self._path is None:
return full_type
else:
# for type checker
full_type_: str = full_type

full_type = strip_prefix(self._path, 'node.')
full_type_ = strip_prefix(self._path, 'node.')

if full_type_.startswith('process.'):
for basepath, full_type_template in self.process_full_type_mapping.items():
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_guide/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ http://localhost:5000/api/v4/nodes?attributes=true&attributes_filter=pbc1
http://localhost:5000/api/v4/nodes/full_types
```

Not implemented for GraphQL, please use the FastAPI for this use case.
Not implemented for GraphQL, please use the REST API for this use case.

```html
http://localhost:5000/api/v4/nodes/download_formats
Expand Down
57 changes: 54 additions & 3 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,60 @@ def test_create_bool_with_extra(client, authenticate): # pylint: disable=unused
assert check_response.json()['extras']['extra_two'] == 'value_2'


def test_get_full_types(client):
def test_get_full_types(default_nodes, client):
"""Test get full_types nodes."""
response = client.get('/nodes/full_types')

assert response.status_code == 200
assert response.json() == {}
assert response.status_code == 200, response.json()
assert response.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': [],
},
{
'namespace': 'float',
'full_type': 'data.core.float.Float.|',
'label': 'Float',
'path': 'node.data.core.float',
'subspaces': [],
},
{
'namespace': 'int',
'full_type': 'data.core.int.Int.|',
'label': 'Int',
'path': 'node.data.core.int',
'subspaces': [],
},
{
'namespace': 'str',
'full_type': 'data.core.str.Str.|',
'label': 'Str',
'path': 'node.data.core.str',
'subspaces': [],
},
],
}
],
}
],
}

0 comments on commit 2850056

Please sign in to comment.