-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
verdi database integrity
endpoints for links and nodes
These two new end points will scan the database for invalid links and nodes, by running prepared SQL statements. If any violations are found, they will be printed to the terminal. For now there are no options implemented to apply a patch to remove the violations.
- Loading branch information
Showing
13 changed files
with
426 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# -*- 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 # | ||
########################################################################### | ||
# pylint: disable=invalid-name,protected-access | ||
"""Tests for `verdi database`.""" | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import absolute_import | ||
|
||
import enum | ||
|
||
from click.testing import CliRunner | ||
|
||
from aiida.backends.testbase import AiidaTestCase | ||
from aiida.cmdline.commands import cmd_database | ||
from aiida.common.links import LinkType | ||
from aiida.orm.data import Data | ||
from aiida.orm.node import Node | ||
from aiida.orm.node.process import CalculationNode, WorkflowNode | ||
|
||
|
||
class TestVerdiDatabasaIntegrity(AiidaTestCase): | ||
"""Tests for `verdi database integrity`.""" | ||
|
||
def setUp(self): | ||
self.cli_runner = CliRunner() | ||
|
||
def tearDown(self): | ||
self.reset_database() | ||
|
||
def test_detect_invalid_links_workflow_create(self): | ||
"""Test `verdi database integrity detect-invalid-links` outgoing `create` from `workflow`.""" | ||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertClickResultNoException(result) | ||
|
||
# Create an invalid link: outgoing `create` from a workflow | ||
data = Data().store() | ||
workflow = WorkflowNode().store() | ||
|
||
data._add_dblink_from(workflow, link_type=LinkType.CREATE, label='create') | ||
|
||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertNotEqual(result.exit_code, 0) | ||
self.assertIsNotNone(result.exception) | ||
|
||
def test_detect_invalid_links_calculation_return(self): | ||
"""Test `verdi database integrity detect-invalid-links` outgoing `return` from `calculation`.""" | ||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertClickResultNoException(result) | ||
|
||
# Create an invalid link: outgoing `return` from a calculation | ||
data = Data().store() | ||
calculation = CalculationNode().store() | ||
|
||
data._add_dblink_from(calculation, link_type=LinkType.RETURN, label='return') | ||
|
||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertNotEqual(result.exit_code, 0) | ||
self.assertIsNotNone(result.exception) | ||
|
||
def test_detect_invalid_links_calculation_call(self): | ||
"""Test `verdi database integrity detect-invalid-links` outgoing `call` from `calculation`.""" | ||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertClickResultNoException(result) | ||
|
||
# Create an invalid link: outgoing `call` from a calculation | ||
worklow = WorkflowNode().store() | ||
calculation = CalculationNode().store() | ||
|
||
worklow._add_dblink_from(calculation, link_type=LinkType.CALL_WORK, label='call') | ||
|
||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertNotEqual(result.exit_code, 0) | ||
self.assertIsNotNone(result.exception) | ||
|
||
def test_detect_invalid_links_create_links(self): | ||
"""Test `verdi database integrity detect-invalid-links` when there are multiple incoming `create` links.""" | ||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertClickResultNoException(result) | ||
|
||
# Create an invalid link: two `create` links | ||
data = Data().store() | ||
calculation = CalculationNode().store() | ||
|
||
data._add_dblink_from(calculation, link_type=LinkType.CREATE, label='create') | ||
data._add_dblink_from(calculation, link_type=LinkType.CREATE, label='create') | ||
|
||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertNotEqual(result.exit_code, 0) | ||
self.assertIsNotNone(result.exception) | ||
|
||
def test_detect_invalid_links_call_links(self): | ||
"""Test `verdi database integrity detect-invalid-links` when there are multiple incoming `call` links.""" | ||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertClickResultNoException(result) | ||
|
||
# Create an invalid link: two `call` links | ||
workflow = WorkflowNode().store() | ||
calculation = CalculationNode().store() | ||
|
||
calculation._add_dblink_from(workflow, link_type=LinkType.CALL_CALC, label='call') | ||
calculation._add_dblink_from(workflow, link_type=LinkType.CALL_CALC, label='call') | ||
|
||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertNotEqual(result.exit_code, 0) | ||
self.assertIsNotNone(result.exception) | ||
|
||
def test_detect_invalid_links_unknown_link_type(self): | ||
"""Test `verdi database integrity detect-invalid-links` when link type is invalid.""" | ||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertClickResultNoException(result) | ||
|
||
class WrongLinkType(enum.Enum): | ||
|
||
WRONG_CREATE = 'wrong_create' | ||
|
||
# Create an invalid link: invalid link type | ||
data = Data().store() | ||
calculation = CalculationNode().store() | ||
|
||
data._add_dblink_from(calculation, link_type=WrongLinkType.WRONG_CREATE, label='create') | ||
|
||
result = self.cli_runner.invoke(cmd_database.detect_invalid_links, []) | ||
self.assertNotEqual(result.exit_code, 0) | ||
self.assertIsNotNone(result.exception) | ||
|
||
def test_detect_invalid_nodes_unknown_node_type(self): | ||
"""Test `verdi database integrity detect-invalid-nodes` when node type is invalid.""" | ||
result = self.cli_runner.invoke(cmd_database.detect_invalid_nodes, []) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertClickResultNoException(result) | ||
|
||
# Create a node with invalid type: a base Node type string is considered invalid | ||
# Note that there is guard against storing base Nodes for this reason, which we temporarily disable | ||
Node._storable = True | ||
Node().store() | ||
Node._storable = False | ||
|
||
result = self.cli_runner.invoke(cmd_database.detect_invalid_nodes, []) | ||
self.assertNotEqual(result.exit_code, 0) | ||
self.assertIsNotNone(result.exception) |
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
Empty file.
Oops, something went wrong.