async def test_create_and_get_source(db_session: AsyncSession, skip_if_no_db):
    """Test creating and then retrieving a source."""
    # Create a unique short_name with a uuid to avoid conflicts
    unique_id = uuid.uuid4().hex[:8]

    # Arrange
    source_data = SourceCreate(
        name="Test Integration Source",
        short_name=f"test_source_{unique_id}",
        class_name="TestSourceConnector",
        auth_type=None,
        auth_config_class="TestAuthConfig",
        config_class="TestConfig",
        description="A test source for integration testing",
        organization_id=None,
        output_entity_definition_ids=[],
        config_schema={"type": "object", "properties": {}},
    )

    try:
        # Act - Create
        created_source = await crud_source.create(db=db_session, obj_in=source_data)

        # Assert - Create
        assert created_source is not None
        assert created_source.name == source_data.name
        assert created_source.short_name == source_data.short_name
        assert created_source.class_name == source_data.class_name
        assert created_source.id is not None

        # Act - Get by ID
        retrieved_source = await crud_source.get(db=db_session, id=created_source.id)

        # Assert - Get by ID
        assert retrieved_source is not None
        assert retrieved_source.id == created_source.id
        assert retrieved_source.name == source_data.name
        assert retrieved_source.short_name == source_data.short_name

        # Act - Get by short_name
        retrieved_by_short_name = await crud_source.get_by_short_name(
            db=db_session, short_name=source_data.short_name
        )

        # Assert - Get by short_name
        assert retrieved_by_short_name is not None
        assert retrieved_by_short_name.id == created_source.id
        assert retrieved_by_short_name.name == source_data.name

    except Exception as e:
        logger.error(f"Test failed: {e}")
        raise
Test creating and then retrieving a source.
backend/tests/integration/crud/test_source_integration.py