Skip to content

Commit

Permalink
Add DB API unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dany9966 committed Nov 15, 2024
1 parent efc0876 commit 3bad643
Show file tree
Hide file tree
Showing 7 changed files with 1,119 additions and 31 deletions.
2 changes: 1 addition & 1 deletion coriolis/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def get_transfers(context,
q = q.options(orm.undefer('info'))
q = q.filter()
if transfer_scenario:
q.filter(models.Transfer.scenario == transfer_scenario)
q = q.filter(models.Transfer.scenario == transfer_scenario)
if is_user_context(context):
q = q.filter(
models.Transfer.project_id == context.project_id)
Expand Down
2 changes: 1 addition & 1 deletion coriolis/providers/backup_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def from_connection_info(cls, info, volumes_info):


class SSHBackupWriterImpl(BaseBackupWriterImpl):
def __init__(self, path, disk_id, compress_transfer=None,
def __init__(self, path, disk_id, compress_transfer=False,
encoder_count=3):
self._msg_id = None
self._stdin = None
Expand Down
4 changes: 4 additions & 0 deletions coriolis/tests/db/sqlalchemy/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
class DatabaseSqlalchemyApiTestCase(test_base.CoriolisBaseTestCase):
"""Test suite for the Coriolis Database Sqlalchemy api."""

def tearDown(self):
api._facade = None
super(DatabaseSqlalchemyApiTestCase, self).tearDown()

@mock.patch.object(db_session, 'EngineFacade')
def test_get_facade_none(self, mock_EngineFacade):
cfg.CONF.database.connection = mock.sentinel.connection
Expand Down
27 changes: 14 additions & 13 deletions coriolis/tests/db/sqlalchemy/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,34 +324,35 @@ class ReplicaTestCase(test_base.CoriolisBaseTestCase):
"""Test suite for the Coriolis Database Sqlalchemy Replica."""

def test_to_dict(self):
replica = models.Replica()
replica.id = mock.sentinel.id
transfer = models.Transfer()
transfer.id = mock.sentinel.id

result = replica.to_dict()
result = transfer.to_dict()

self.assertEqual(
mock.sentinel.id,
result["id"]
)


class MigrationTestCase(test_base.CoriolisBaseTestCase):
"""Test suite for the Coriolis Database Sqlalchemy Migration."""
class DeploymentTestCase(test_base.CoriolisBaseTestCase):
"""Test suite for the Coriolis Database Sqlalchemy Deployment."""

def test_to_dict(self):
migration = models.Migration()
migration.id = mock.sentinel.id
migration.replica_id = mock.sentinel.replica_id
migration.shutdown_instances = mock.sentinel.shutdown_instances
migration.replication_count = mock.sentinel.replication_count
transfer = mock.MagicMock(id=mock.sentinel.transfer_id)
deployment = models.Deployment()
deployment.id = mock.sentinel.id
deployment.transfer_id = transfer.id
deployment.transfer = transfer
deployment.shutdown_instances = mock.sentinel.shutdown_instances
expected_result = {
"id": mock.sentinel.id,
"replica_id": mock.sentinel.replica_id,
"transfer_id": mock.sentinel.transfer_id,
"shutdown_instances": mock.sentinel.shutdown_instances,
"replication_count": mock.sentinel.replication_count,
"transfer_scenario_type": transfer.scenario,
}

result = migration.to_dict()
result = deployment.to_dict()

assert all(item in result.items() for item in expected_result.items())

Expand Down
Loading

0 comments on commit 3bad643

Please sign in to comment.