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

Code before:

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


def test_search_apps_configured_only_with_multiple_configurations(
    db_session: Session,
    test_client: TestClient,
    dummy_apps: list[App],
    dummy_project_1: Project,
    dummy_project_2: Project,
    dummy_api_key_1: str,
) -> None:
    # Configure the same app in multiple projects
    app_config_1 = AppConfiguration(
        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=[],
    )
    app_config_2 = AppConfiguration(
        project_id=dummy_project_2.id,
        app_id=dummy_apps[0].id,
        security_scheme=SecurityScheme.API_KEY,
        security_config_overrides={},
        enabled=True,
        all_functions_enabled=True,
        enabled_functions=[],

Review comment (security):
test case name `test_search_apps_configured_only_with_multiple_configurations` is a bit ambiguous.
Essentially what you are trying to test here is project level access control, so something like `test_search_apps_configured_only_excludes_configurations_from_other_projects`  would be better

Code after:
    }
    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,
    }
    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 one app"
    assert apps[0].name == dummy_apps[0].name, "Returned app and configured app are not the same"