-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REST API: Add full_types_count as new entry point
This feature returns a namespace tree of the available node types in the database (data node_types + process process_types) with the addition of a count at each leaf / branch. It also has the option of doing so for a single user, if the pk is provided as an option.
- Loading branch information
1 parent
9683716
commit 62ed643
Showing
10 changed files
with
159 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Unit tests for REST API statistics.""" | ||
from threading import Thread | ||
|
||
import requests | ||
import pytest | ||
|
||
|
||
def linearize_namespace(tree_namespace, linear_namespace=None): | ||
"""Linearize a branched namespace with full_type, count, and subspaces""" | ||
if linear_namespace is None: | ||
linear_namespace = {} | ||
|
||
full_type = tree_namespace['full_type'] | ||
while full_type[-1] != '.': | ||
full_type = full_type[0:-1] | ||
|
||
counter = tree_namespace['counter'] | ||
subspaces = tree_namespace['subspaces'] | ||
|
||
linear_namespace[full_type] = counter | ||
for subspace in subspaces: | ||
linearize_namespace(subspace, linear_namespace) | ||
|
||
return linear_namespace | ||
|
||
|
||
@pytest.mark.usefixtures('populate_restapi_database') | ||
def test_count_consistency(restapi_server, server_url): | ||
""" | ||
Test the consistency in values between full_type_count and statistics | ||
""" | ||
server = restapi_server() | ||
server_thread = Thread(target=server.serve_forever) | ||
|
||
try: | ||
server_thread.start() | ||
type_count_response = requests.get(f'{server_url}/nodes/full_types_count', timeout=10) | ||
statistics_response = requests.get(f'{server_url}/nodes/statistics', timeout=10) | ||
finally: | ||
server.shutdown() | ||
|
||
type_count_dict = linearize_namespace(type_count_response.json()['data']) | ||
statistics_dict = statistics_response.json()['data']['types'] | ||
|
||
for full_type, count in statistics_dict.items(): | ||
if full_type in type_count_dict: | ||
assert count == type_count_dict[full_type] |