aiida.backends.sqlalchemy.tests package

Submodules

Generic tests that need the be specific to sqlalchemy

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

Bases: aiida.backends.testbase.AiidaTestCase

Test the Computer class.

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

Bases: aiida.backends.testbase.AiidaTestCase

Characterized functions

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

Bases: aiida.backends.testbase.AiidaTestCase

Characterized functions

__module__ = 'aiida.backends.sqlalchemy.tests.generic'
test_query()[source]

Test if queries are working

class aiida.backends.sqlalchemy.tests.migrations.TestMigrationApplicationSQLA(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.migrations'
alembic_dpath = None
migr_method_dir_path = None
migrate_db_with_non_testing_migrations(destination)[source]
setUp()[source]

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

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

Hook method for setting up class fixture before running tests in the class.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_migrations_forward_backward()[source]

This is a very broad test that checks that the migration mechanism works. More specifically, it checks that:

- Alembic database migrations to specific versions work (upgrade &
  downgrade)

- The methods that are checking the database schema version and perform
  the migration procedure to the last version work correctly.
class aiida.backends.sqlalchemy.tests.migrations.TestMigrationSchemaVsModelsSchema(methodName='runTest')[source]

Bases: unittest.case.TestCase

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.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.

Tests for nodes, attributes and links

class aiida.backends.sqlalchemy.tests.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.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.nodes.TestTransitiveClosureDeletionSQLA(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

Test the creation of the transitive closure table

__module__ = 'aiida.backends.sqlalchemy.tests.nodes'
test_creation_and_deletion()[source]
class aiida.backends.sqlalchemy.tests.query.QueryBuilderLimitOffsetsTestSQLA(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

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

Bases: aiida.backends.testbase.AiidaTestCase

__module__ = 'aiida.backends.sqlalchemy.tests.query'
test_clsf_sqla()[source]
class aiida.backends.sqlalchemy.tests.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.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.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.session'
drop_connection()[source]
set_connection(expire_on_commit=True)[source]
test_node_access_with_sessions()[source]
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.

test_session_wfdata()[source]

This test checks that the aiida.backends.sqlalchemy.models.workflow.DbWorkflowData#set_value method works as expected. There were problems with the DbNode object that was added as a value to a DbWorkflowData object. If there was an older version of the dbnode in the session than the one given to to the DbWorkflowData#set_value then there was a collision in the session and SQLA identity map.

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

Bases: aiida.backends.testimplbase.AiidaTestImplementation

__abstractmethods__ = frozenset([])
__module__ = 'aiida.backends.sqlalchemy.tests.testbase'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 92
_abc_registry = <_weakrefset.WeakSet object>
static _create_computer()[source]
clean_db()[source]

This method implements the logic to fully clean the DB.

connection = None
drop_all = False
static inject_computer()[source]
insert_data()[source]

Insert default data into the DB.

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]

This class implements the tear down methods (e.g. cleans up the DB).

tearDown_method()[source]
test_session = None

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.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.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.utils.destroy_database(uri)[source]

Destroy the database at uri, if it exists.

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

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