Repository: aipotheosis-labs/aci
File: backend/aci/server/tests/routes/app_configurations/test_app_configurations_add.py (Python)

Code before:
    dummy_api_key_1: str,
    dummy_apps: list[App],
) -> None:
    # success case
    dummy_app = dummy_apps[0]
    body = AppConfigurationCreate(app_name=dummy_app.name, security_scheme=SecurityScheme.OAUTH2)

    response = test_client.post(
        f"{config.ROUTER_PREFIX_APP_CONFIGURATIONS}",
        json=body.model_dump(mode="json"),
        headers={"x-api-key": dummy_api_key_1},
    )
    assert response.status_code == status.HTTP_200_OK
    AppConfigurationPublic.model_validate(response.json())

    # failure case: App already configured
    response = test_client.post(
        f"{config.ROUTER_PREFIX_APP_CONFIGURATIONS}",
        json=body.model_dump(mode="json"),
        headers={"x-api-key": dummy_api_key_1},
    )
    assert response.status_code == status.HTTP_409_CONFLICT
    assert str(response.json()["error"]).startswith("App configuration already exists")


# use paramterize to test two cases:
# 1. no redirect_url
# 2. with redirect_url
@pytest.mark.parametrize(
    "redirect_url", [None, "https://api.user-app.com/v1/linked-accounts/oauth2/callback"]
)
def test_create_app_configuration_with_security_scheme_override(
    test_client: TestClient,
    dummy_api_key_1: str,
    dummy_apps: list[App],
    redirect_url: str | None,
) -> None:
    dummy_app = dummy_apps[0]
    body = AppConfigurationCreate.model_validate(
        {
            "app_name": dummy_app.name,
            "security_scheme": SecurityScheme.OAUTH2,
            "security_scheme_overrides": {
                "oauth2": {
                    "client_id": "123456",
                    "client_secret": "abcdef",
                    "redirect_url": redirect_url,
                }
            },
        }
    )

Review comment (suggestion):

```suggestion
# use parametrize to test two cases:
```

Code after:
    dummy_api_key_1: str,
    dummy_apps: list[App],
) -> None:
    # success case
    dummy_app = dummy_apps[0]
    body = AppConfigurationCreate(app_name=dummy_app.name, security_scheme=SecurityScheme.OAUTH2)

    response = test_client.post(
        f"{config.ROUTER_PREFIX_APP_CONFIGURATIONS}",
        json=body.model_dump(mode="json"),
        headers={"x-api-key": dummy_api_key_1},
    )
    assert response.status_code == status.HTTP_200_OK
    AppConfigurationPublic.model_validate(response.json())

    # failure case: App already configured
    response = test_client.post(
        f"{config.ROUTER_PREFIX_APP_CONFIGURATIONS}",
        json=body.model_dump(mode="json"),
        headers={"x-api-key": dummy_api_key_1},
    )
    assert response.status_code == status.HTTP_409_CONFLICT
    assert str(response.json()["error"]).startswith("App configuration already exists")


# use parametrize to test two cases:
# 1. no redirect_url
# 2. with redirect_url
@pytest.mark.parametrize(
    "redirect_url", [None, "https://api.user-app.com/v1/linked-accounts/oauth2/callback"]
)
def test_create_app_configuration_with_security_scheme_override(
    test_client: TestClient,
    dummy_api_key_1: str,
    dummy_apps: list[App],
    redirect_url: str | None,
) -> None:
    dummy_app = dummy_apps[0]
    body = AppConfigurationCreate.model_validate(
        {
            "app_name": dummy_app.name,
            "security_scheme": SecurityScheme.OAUTH2,
            "security_scheme_overrides": {
                "oauth2": {
                    "client_id": "123456",
                    "client_secret": "abcdef",
                    "redirect_url": redirect_url,
                }
            },
        }
    )