Testing#

Running and writing tests for ops-db-api.

Running Tests#

# Run all tests
pytest

# Run with coverage
pytest --cov=ccat_ops_db_api

# Run specific test file
pytest tests/test_transaction_buffering.py

# Run specific test
pytest tests/test_transaction_buffering.py::test_buffer_transaction

Writing Tests#

Test structure:

import pytest
from ccat_ops_db_api.transaction_buffering import SQLAlchemyTransactionBuilder

def test_transaction_builder():
    builder = SQLAlchemyTransactionBuilder(endpoint="test", site="test")

    step = builder.create(
        model_class=models.ExecutedObsUnit,
        data={"id": uuid.uuid4(), "status": "running"},
        step_id="test"
    )

    transaction = builder.build()
    assert len(transaction.steps) == 1

See existing tests in tests/ directory for more examples.