Repository: aipotheosis-labs/aci
File: aipolabs/server/tests/routes/apps/test_apps.py (Python)

Code before:
        project_id=dummy_project_1.id,
        app_id=dummy_apps[0].id,
        security_scheme=SecurityScheme.API_KEY,
        security_config_overrides={},
        enabled=True,
        all_functions_enabled=True,
        enabled_functions=[],
    )
    db_session.add(app_config)
    db_session.commit()

    # Test with configured_only=True
    search_params = {
        "configured_only": True,
        "limit": 100,
        "offset": 0,
    }
    response = test_client.get(
        f"{config.ROUTER_PREFIX_APPS}/search",
        params=search_params,
        headers={"x-api-key": dummy_api_key_1},
    )

    assert response.status_code == status.HTTP_200_OK
    apps = [AppBasic.model_validate(response_app) for response_app in response.json()]
    assert len(apps) == 1  # Should only return the one configured app
    assert apps[0].name == dummy_apps[0].name  # assert that the correct app is returned


def test_search_apps_configured_only_with_none_configured(
    db_session: Session,
    test_client: TestClient,
    dummy_apps: list[App],
    dummy_project_1: Project,
    dummy_api_key_1: str,
) -> None:
    # Test with configured_only=True
    search_params = {
        "configured_only": True,
        "limit": 100,
        "offset": 0,
    }
    response = test_client.get(
        f"{config.ROUTER_PREFIX_APPS}/search",
        params=search_params,
        headers={"x-api-key": dummy_api_key_1},
    )

    assert response.status_code == status.HTTP_200_OK
    apps = [AppBasic.model_validate(response_app) for response_app in response.json()]
    assert len(apps) == 0  # Should only return the one configured app

Review comment (bug):
if you think certain comment is necessary, considering it if is suitable as pytest failure message, like:
`assert len(apps) == 1, "Should only return the one configured app"`


Code after:
    search_params = {
        "configured_only": True,
        "limit": 100,
        "offset": 0,
    }
    response = test_client.get(
        f"{config.ROUTER_PREFIX_APPS}/search",
        params=search_params,
        headers={"x-api-key": dummy_api_key_1},
    )

    assert response.status_code == status.HTTP_200_OK
    apps = [AppBasic.model_validate(response_app) for response_app in response.json()]
    assert len(apps) == 1, "Should only return the one configured app"
    assert apps[0].name == dummy_apps[0].name, "Returned app and configured app are not the same"


def test_search_apps_configured_only_with_none_configured(
    db_session: Session,
    test_client: TestClient,
    dummy_apps: list[App],
    dummy_project_1: Project,
    dummy_api_key_1: str,
) -> None:
    search_params = {
        "configured_only": True,
        "limit": 100,
        "offset": 0,
    }
    response = test_client.get(
        f"{config.ROUTER_PREFIX_APPS}/search",
        params=search_params,
        headers={"x-api-key": dummy_api_key_1},
    )
    assert response.status_code == status.HTTP_200_OK
    apps = [AppBasic.model_validate(response_app) for response_app in response.json()]
    assert len(apps) == 0, "Should not return any apps"


def test_search_apps_configured_only_exclude_apps_from_other_projects(
    db_session: Session,
    test_client: TestClient,
    dummy_apps: list[App],
    dummy_google_app_configuration_under_dummy_project_1: AppConfigurationPublic,
    dummy_github_app_configuration_under_dummy_project_2: AppConfigurationPublic,
    dummy_api_key_1: str,
) -> None:
    search_params = {
        "configured_only": True,
        "limit": 100,
        "offset": 0,