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'¶
-
-
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'¶
-
-
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'¶
-
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'¶
-
-
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'¶
-
-
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'¶
-
-
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'¶
-
-
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.
-
-
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'¶
-
-
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'¶
-
-
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'¶
-
-
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'¶
-
-
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'¶
-
-
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¶
-
-
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.
-
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
-
-
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'¶
-
-
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'¶
-
-
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'¶
-
-
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'¶
-
-
class
aiida.backends.sqlalchemy.tests.test_migrations.
TestSealUnsealedProcessesMigration
(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
= 'e734dd5e50d7'¶
-
migrate_to
= '7b38a9e783e7'¶
-
-
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/v1.0.0/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'¶
-
-
class
aiida.backends.sqlalchemy.tests.test_query.
QueryBuilderLimitOffsetsTestSQLA
(methodName='runTest')[source]¶ Bases:
aiida.backends.testbase.AiidaTestCase
-
__module__
= 'aiida.backends.sqlalchemy.tests.test_query'¶
-
-
class
aiida.backends.sqlalchemy.tests.test_query.
TestQueryBuilderSQLA
(methodName='runTest')[source]¶ Bases:
aiida.backends.testbase.AiidaTestCase
-
__module__
= 'aiida.backends.sqlalchemy.tests.test_query'¶
-
-
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
-
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'¶
-
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.
-
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
¶
-
connection
= None¶
-