MockContext

class felis.db.database_context.MockContext(metadata, connection)

Bases: DatabaseContext

Database context for a mock connection.

Parameters:
  • metadata (MetaData) – The SQLAlchemy metadata defining the database objects.

  • connection (MockConnection) – The SQLAlchemy mock connection.

Attributes Summary

dialect

The SQLAlchemy dialect for the context (Dialect).

dialect_name

Get the dialect name for this database context (str).

engine

The SQAlchemy engine for the context (Engine).

metadata

The SQLAlchemy metadata representing the database for the context (MetaData).

Methods Summary

close()

Close the mock connection (no-op).

create_all()

Create all database objects in the schema using the metadata object.

create_indexes()

Create all indexes in the schema using the metadata object.

drop()

Drop the schema in the database if it exists.

drop_indexes()

Drop all indexes in the schema using the metadata object.

execute(statement[, parameters])

Execute a SQL statement and return the result.

initialize()

Create the target schema in the database if it does not exist already.

Attributes Documentation

dialect
dialect_name
engine
metadata

Methods Documentation

close()

Close the mock connection (no-op).

Return type:

None

create_all()

Create all database objects in the schema using the metadata object.

Raises:

DatabaseContextError – If there is an error creating the schema objects in the database.

Return type:

None

create_indexes()

Create all indexes in the schema using the metadata object.

Raises:

DatabaseContextError – If there is an error creating the indexes in the database.

Return type:

None

drop()

Drop the schema in the database if it exists.

Implementations should use IF EXISTS semantics to avoid raising an error if the schema does not exist.

Raises:

DatabaseContextError – If there is an error dropping the schema.

Return type:

None

drop_indexes()

Drop all indexes in the schema using the metadata object.

Raises:

DatabaseContextError – If there is an error dropping the indexes in the database.

Return type:

None

execute(statement, parameters=None)

Execute a SQL statement and return the result.

Parameters:
Returns:

The result of the statement execution.

Return type:

Result

Raises:

DatabaseContextError – If there is an error executing the SQL statement.

initialize()

Create the target schema in the database if it does not exist already.

Sub-classes should implement idempotent behavior so that calling this method multiple times has no adverse effects. If the schema already exists, the method should simply return without raising an error. (A warning message may be logged in this case.)

Raises:

DatabaseContextError – If there is an error instantiating the schema.

Return type:

None