aiida.backends.sqlalchemy.tests package

Submodules

Generic tests that need the be specific to sqlalchemy

class aiida.backends.sqlalchemy.tests.test_generic.TestComputer(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

Test the Computer class.

__module__ = 'aiida.backends.sqlalchemy.tests.test_generic'
test_deletion()[source]
class aiida.backends.sqlalchemy.tests.test_generic.TestGroupNoOrmSQLA(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

These tests check that the group node addition works ok when the skip_orm=True flag is used

__module__ = 'aiida.backends.sqlalchemy.tests.test_generic'
test_group_batch_size()[source]

Test that the group addition in batches works as expected.

test_group_general()[source]

General tests to verify that the group addition with the skip_orm=True flag work properly

class aiida.backends.sqlalchemy.tests.test_generic.TestGroupsSqla(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

Characterized functions

__module__ = 'aiida.backends.sqlalchemy.tests.test_generic'
setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_query()[source]

Test if queries are working

Tests for the migration engine (Alembic) as well as for the AiiDA migrations for SQLAlchemy.

class aiida.backends.sqlalchemy.tests.test_migrations.TestBackwardMigrationsSQLA(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

This is the equivalent of TestMigrationsSQLA for backward migrations. It assumes that the migrate_from revision is higher in the hierarchy than the migrate_to revision.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
setUp()[source]

Go to the migrate_from revision, apply setUpBeforeMigration, then run the migration.

class aiida.backends.sqlalchemy.tests.test_migrations.TestCalcAttributeKeysMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration of the keys of certain attribute for ProcessNodes and CalcJobNodes.

KEY_ENVIRONMENT_VARIABLES_NEW = 'environment_variables'
KEY_ENVIRONMENT_VARIABLES_OLD = 'custom_environment_variables'
KEY_PARSER_NAME_NEW = 'parser_name'
KEY_PARSER_NAME_OLD = 'parser'
KEY_PROCESS_LABEL_NEW = 'process_label'
KEY_PROCESS_LABEL_OLD = '_process_label'
KEY_RESOURCES_NEW = 'resources'
KEY_RESOURCES_OLD = 'jobresource_params'
__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = 'e72ad251bcdb'
migrate_to = '7ca08c391c49'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_attribute_key_changes()[source]

Verify that the keys are successfully changed of the affected attributes.

class aiida.backends.sqlalchemy.tests.test_migrations.TestDataMoveWithinNodeMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration of Data nodes after the data module was moved within the node moduel.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = '041a79fc615f'
migrate_to = '6a5c2ea1439d'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_data_node_type_string()[source]

Verify that type string of the Data node was successfully adapted.

class aiida.backends.sqlalchemy.tests.test_migrations.TestDbLogMigrationBackward(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestBackwardMigrationsSQLA

Check that backward migrations work also for the DbLog migration(s).

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = '041a79fc615f'
migrate_to = '7ca08c391c49'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_objpk_objname()[source]

This test verifies that the objpk and objname have the right values after a forward and a backward migration.

class aiida.backends.sqlalchemy.tests.test_migrations.TestDbLogMigrationRecordCleaning(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration of the keys of certain attribute for ProcessNodes and CalcJobNodes.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = '7ca08c391c49'
migrate_to = '041a79fc615f'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

tearDown()[source]

Need to manually delete all the workflows created for the test because the model does not exist any more.

Because the model does not exist anymore, they are no longer being cleaned in the database reset of the test base class. To prevent foreign keys from other tables still referencing these tables, we have to make sure to clean them here manually, before we call the parent, which will call the standard reset database methods.

test_dblog_calculation_node()[source]

Verify that after the migration there is only two log records left and verify that they corresponds to the CalculationNodes.

test_dblog_correct_export_of_logs()[source]

Verify that export log methods for legacy workflows, unknown entities and log records that don’t correspond to nodes, work as expected

test_metadata_correctness()[source]

Verify that the metadata of the remaining records don’t have an objpk and objmetadata values.

class aiida.backends.sqlalchemy.tests.test_migrations.TestDbLogUUIDAddition(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test that the UUID column is correctly added to the DbLog table and that the uniqueness constraint is added without problems (if the migration arrives until 375c2db70663 then the constraint is added properly.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = '041a79fc615f'
migrate_to = '375c2db70663'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_dblog_unique_uuids()[source]

Verify that the UUIDs of the log records are unique

class aiida.backends.sqlalchemy.tests.test_migrations.TestGroupRenamingMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration that renames the DbGroup type strings

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = 'b8b23ddefad4'
migrate_to = 'e72ad251bcdb'
setUpBeforeMigration()[source]

Create the DbGroups with the old type strings

test_group_string_update()[source]

Test that the type strings are properly migrated

class aiida.backends.sqlalchemy.tests.test_migrations.TestLegacyJobCalcStateDataMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration that performs a data migration of legacy JobCalcState.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = '07fac78e6209'
migrate_to = '26d561acd560'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_data_migrated()[source]

Verify that the process_state, process_status and exit_status are set correctly.

class aiida.backends.sqlalchemy.tests.test_migrations.TestLegacyProcessAttributeMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration that performs a data migration of legacy process attributes.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = 'e797afa09270'
migrate_to = 'e734dd5e50d7'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_data_migrated()[source]

Verify that the attributes for process node have been deleted and _sealed has been changed to sealed.

class aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationEngine(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Just a simple test to verify that the TestMigrationsSQLA class indeed works and moves between the expected migration revisions

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = 'b8b23ddefad4'
migrate_to = 'e72ad251bcdb'
setUpBeforeMigration()[source]

Cache the start revision

test_revision_numbers()[source]

Check that we went to the correct version

class aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationSchemaVsModelsSchema(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

This class checks that the schema that results from a migration is the same generated by the models. This is important since migrations are frequently written by hand or extended manually and we have to ensure that the final result is what is conceived in the SQLA models.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
alembic_cfg_left = None
alembic_dpath = None
db_url_left = None
db_url_right = None
migr_method_dir_path = None
setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_model_and_migration_schemas_are_the_same()[source]

Compare two databases.

Compares the database obtained with all migrations against the one we get out of the models. It produces a text file with the results to help debug differences.

class aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

This class contains tests for the migration mechanism of SQLAlchemy called alembic. It checks if the migrations can be applied and removed correctly.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
_reset_database_and_schema()[source]

Bring back the DB to the correct state.

It is important to also reset the database content to avoid hanging of tests.

alembic_dpath = None
property current_rev

Utility method to get the current revision string

static get_auto_base()[source]

Return the automap_base class that automatically inspects the current database and return SQLAlchemy Models.

Note that these are NOT the ones in AiiDA SQLAlchemy models, so do not have the special methods that we define there (like .save()).

get_current_table(table_name)[source]

Return a Model instantiated at the correct migration. Note that this is obtained by inspecting the database and not by looking into the models file. So, special methods possibly defined in the models files/classes are not present.

For instance, you can do:

DbGroup = self.get_current_table('db_dbgroup')
Parameters

table_name – the name of the table.

static get_node_array(node, name)[source]
static get_session()[source]

Return a session that is properly closed after use.

migr_method_dir_path = None
migrate_db_down(destination)[source]

Perform a migration downwards (downgrade) with alembic

Parameters

destination – the name of the destination migration

migrate_db_up(destination)[source]

Perform a migration upwards (upgrade) with alembic

Parameters

destination – the name of the destination migration

migrate_from = None
migrate_to = None
setUp()[source]

Go to the migrate_from revision, apply setUpBeforeMigration, then run the migration.

setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

classmethod setUpClass(*args, **kwargs)[source]

Prepare the test class with the alembivc configuration

static set_node_array(node, name, array)[source]

Store a new numpy array inside a node. Possibly overwrite the array if it already existed.

Internally, it stores a name.npy file in numpy format.

Parameters
  • name – The name of the array.

  • array – The numpy array to store.

tearDown()[source]

Resets both the database content and the schema to prepare for the next test

class aiida.backends.sqlalchemy.tests.test_migrations.TestNodePrefixRemovalMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration of Data nodes after the data module was moved within the node moduel.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = 'ce56d84bcc35'
migrate_to = '61fc0913fae9'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_data_node_type_string()[source]

Verify that type string of the Data node was successfully adapted.

class aiida.backends.sqlalchemy.tests.test_migrations.TestParameterDataToDictMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the data migration after ParameterData was renamed to Dict.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = '61fc0913fae9'
migrate_to = 'd254fdfed416'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_type_string()[source]

Verify that type string of the Data node was successfully adapted.

class aiida.backends.sqlalchemy.tests.test_migrations.TestProvenanceRedesignMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the data migration part of the provenance redesign migration.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = '140c971ae0a3'
migrate_to = '239cea6d2452'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_verify_migration()[source]

Verify that type string of the Data node was successfully adapted.

class aiida.backends.sqlalchemy.tests.test_migrations.TestResetHash(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration that resets the node hash.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
migrate_from = '26d561acd560'
migrate_to = 'e797afa09270'
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

test_data_migrated()[source]

Verify that only the _aiida_hash extra has been removed.

class aiida.backends.sqlalchemy.tests.test_migrations.TestTrajectoryDataMigration(methodName='runTest')[source]

Bases: aiida.backends.sqlalchemy.tests.test_migrations.TestMigrationsSQLA

Test the migration of the symbols from numpy array to attribute for TrajectoryData nodes.

__module__ = 'aiida.backends.sqlalchemy.tests.test_migrations'
cells = array([[[2., 0., 0.], [0., 2., 0.], [0., 0., 2.]], [[3., 0., 0.], [0., 3., 0.], [0., 0., 3.]]])
migrate_from = '37f3d4882837'
migrate_to = 'ce56d84bcc35'
numpy = <module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/aiida-core/envs/latest/lib/python3.7/site-packages/numpy/__init__.py'>
positions = array([[[0. , 0. , 0. ], [0.5, 0.5, 0.5], [1.5, 1.5, 1.5]], [[0. , 0. , 0. ], [0.5, 0.5, 0.5], [1.5, 1.5, 1.5]]])
setUpBeforeMigration()[source]

Anything to do before running the migrations. This is typically implemented in test subclasses.

stepids = array([60, 70])
test_trajectory_symbols()[source]

Verify that migration of symbols from repository array to attribute works properly.

times = array([0.6, 0.7])
velocities = array([[[ 0. , 0. , 0. ], [ 0. , 0. , 0. ], [ 0. , 0. , 0. ]], [[ 0.5, 0.5, 0.5], [ 0.5, 0.5, 0.5], [-0.5, -0.5, -0.5]]])

Tests for nodes, attributes and links

class aiida.backends.sqlalchemy.tests.test_nodes.TestNodeBasicSQLA(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

These tests check the basic features of nodes (setting of attributes, copying of files, …)

__module__ = 'aiida.backends.sqlalchemy.tests.test_nodes'
test_load_nodes()[source]

Test for load_node() function.

test_multiple_node_creation()[source]

This test checks that a node is not added automatically to the session (and subsequently committed) when a user is in the session. It tests the fix for the issue #234

test_settings()[source]

Test the settings table (similar to Attributes, but without the key.

class aiida.backends.sqlalchemy.tests.test_query.QueryBuilderLimitOffsetsTestSQLA(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

__module__ = 'aiida.backends.sqlalchemy.tests.test_query'
test_ordering_limits_offsets_of_results_for_SQLA()[source]
class aiida.backends.sqlalchemy.tests.test_query.TestQueryBuilderSQLA(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

__module__ = 'aiida.backends.sqlalchemy.tests.test_query'
test_clsf_sqla()[source]
class aiida.backends.sqlalchemy.tests.test_schema.TestRelationshipsSQLA(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

Class of tests concerning the schema and the correct implementation of relationships within the AiiDA ORM

The genereal naming convention is the following: 1)tests on one-to-many relationships: test_<Parent>_<child> (Parent class is capitalized) 2)tests on many-to-many relationships: test_<peer>_<peer> (none is capitalized)

__module__ = 'aiida.backends.sqlalchemy.tests.test_schema'
test_User_node_1()[source]

Test that when a user and a node having that user are created, storing NODE induces storage of the USER

Assert the correct storage of user and node

test_User_node_2()[source]

Test that when a user and a node having that user are created, storing USER does NOT induce storage of the NODE

Assert the correct storage of user and node

test_User_node_3()[source]

Test that when a user and two nodes having that user are created, storing only ONE NODE induces storage of that node, of the user but not of the other node

Assert the correct storage of the user and node. Assert the non-storage of the other node

test_User_node_4()[source]

Test that when several nodes are created with the same user and each of them is assigned to the same name, storage of last node object associated to that node does not trigger storage of all objects.

Assert the correct storage of the user and node. Assert the non-storage of the other nodes

test_inputs_parents_relationship()[source]

This test checks that the inputs_q, parents_q relationship and the corresponding properties work as expected.

test_outputs_children_relationship()[source]

This test checks that the outputs_q, children_q relationship and the corresponding properties work as expected.

Testing Session possible problems.

class aiida.backends.sqlalchemy.tests.test_session.TestSessionSqla(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

The following tests check that the session works as expected in some problematic examples. When a session is initialized with expire_on_commit=False allows more permissive behaviour since committed objects that remain in the session do not need refresh. The opposite happens when expire_on_commit=True.

Moreover, 2 ways of storing objects are tested, i.e. adding the objects manually to the session and committing it & by using the build-in store method of the ORM objects.

__module__ = 'aiida.backends.sqlalchemy.tests.test_session'
drop_connection()[source]
set_connection(expire_on_commit=True)[source]
test_node_access_with_sessions()[source]

This checks that changes to a node from a different session (e.g. different interpreter, or the daemon) are immediately reflected on the AiiDA node when read directly e.g. a change to node.description will immediately be seen.

Tests for bug #1372

test_session_update_and_expiration_1()[source]

expire_on_commit=True & adding manually and committing computer and code objects.

test_session_update_and_expiration_2()[source]

expire_on_commit=True & committing computer and code objects with their built-in store function.

test_session_update_and_expiration_3()[source]

expire_on_commit=False & adding manually and committing computer and code objects.

test_session_update_and_expiration_4()[source]

expire_on_commit=False & committing computer and code objects with their built-in store function.

In this file various data management functions, needed for the SQLA test, are added. They are “heavily inspired” by the sqlalchemy_utils.functions.database (SQLAlchemy-Utils package).

However, they were corrected to work properly with a SQlAlchemy and PostgreSQL. The main problem of the SQLAlchemy-Utils that were rewritten was that they were not properly disposing the (SQLA) engine, resulting to error messages from PostgreSQL.

aiida.backends.sqlalchemy.tests.test_utils.create_database(url, encoding='utf8')[source]

Issue the appropriate CREATE DATABASE statement.

This is a modification of sqlalchemy_utils.functions.database.create_database since the latter one did not correctly work with SQLAlchemy and PostgreSQL.

Parameters
  • url – A SQLAlchemy engine URL.

  • encoding – The encoding to create the database as.

It currently supports only PostgreSQL and the psycopg2 driver.

aiida.backends.sqlalchemy.tests.test_utils.database_exists(url)[source]

Check if a database exists.

This is a modification of sqlalchemy_utils.functions.database.database_exists since the latter one did not correctly work with SQLAlchemy and PostgreSQL.

Parameters

url – A SQLAlchemy engine URL.

Performs backend-specific testing to quickly determine if a database exists on the server.

aiida.backends.sqlalchemy.tests.test_utils.destroy_database(uri)[source]

Destroy the database at uri, if it exists.

aiida.backends.sqlalchemy.tests.test_utils.new_database(uri)[source]

Drop the database at uri and create a brand new one.

class aiida.backends.sqlalchemy.tests.testbase.SqlAlchemyTests[source]

Bases: aiida.backends.testimplbase.AiidaTestImplementation

__abstractmethods__ = frozenset({})
__module__ = 'aiida.backends.sqlalchemy.tests.testbase'
_abc_impl = <_abc_data object>
_backend = None
property backend
clean_db()[source]

This method implements the logic to fully clean the DB.

connection = None
setUpClass_method()[source]

This class prepares the database (cleans it up and installs some basic entries). You have also to set a self.computer and a self.user_email as explained in the docstring of the AiidaTestImplemention docstring.

setUp_method()[source]
tearDownClass_method()[source]

Backend-specific tasks for tearing down the test environment.

tearDown_method()[source]