@@ -640,3 +640,40 @@ async def test_get_download_node(async_client: AsyncClient, array_data_node: orm
640640 response = await async_client .get (f'/nodes/{ array_data_node .pk } /download' )
641641 assert response .status_code == 422 , response .json ()
642642 assert 'Please specify the download format' in response .json ()['detail' ]
643+
644+
645+ @pytest .mark .usefixtures ('default_nodes' )
646+ @pytest .mark .anyio
647+ async def test_get_statistics (async_client : AsyncClient ):
648+ """Test get statistics for nodes."""
649+
650+ from datetime import datetime
651+
652+ default_user_reference_json = {
653+ 'total' : 4 ,
654+ 'types' : {
655+ 'data.core.float.Float.' : 1 ,
656+ 'data.core.str.Str.' : 1 ,
657+ 'data.core.bool.Bool.' : 1 ,
658+ 'data.core.int.Int.' : 1 ,
659+ },
660+ 'ctime_by_day' : {datetime .today ().strftime ('%Y-%m-%d' ): 4 },
661+ }
662+
663+ # Test without specifying user, should use default user
664+ response = await async_client .get ('/nodes/statistics' )
665+ assert response .status_code == 200 , response .json ()
666+ assert response .json () == default_user_reference_json
667+
668+ # Test that the output is the same when we use the pk of the default user
669+ from aiida import orm
670+
671+ default_user_pk = orm .User (email = '' ).collection .get_default ().pk
672+ response = await async_client .get (f'/nodes/statistics?user={ default_user_pk } ' )
673+ assert response .status_code == 200 , response .json ()
674+ assert response .json () == default_user_reference_json
675+
676+ # Test empty response for nonexisting user
677+ response = await async_client .get ('/nodes/statistics?user=99999' )
678+ assert response .status_code == 200 , response .json ()
679+ assert response .json () == {'total' : 0 , 'types' : {}, 'ctime_by_day' : {}}
0 commit comments