ronantakizawa/codereview-bench huggingface dataset:
Repository: thijsvanloef/palworld-server-docker
File: scripts/update.sh (Shell)

Code before:
#!/bin/bash

if [ "${UPDATE_ON_BOOT}" = false ]; then
    echo "Update on Boot needs to be enabled for auto updating"
    exit 1
fi

CURRENTBUILD=$(awk '/buildid/{ print $2 }' < palworld/steamapps/appmanifest_2394010.acf)
TARGETBUILD=$(curl https://api.steamcmd.net/v1/info/2394010 --silent | grep -P '"public": {"buildid": "\d+"' -o | sed -r 's/.*("[0-9]+")$/\1/')

if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
    echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD."
    if [ "${RCON_ENABLED}" = true ]; then
        rm /palworld/steamapps/appmanifest_2394010.acf
        rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${WARN_MINUTES}_Minutes"
        sleep "${WARN_MINUTES}m"
        backup
        rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
    else
        echo "An update is available however auto updating without rcon is not supported"
    fi
else
    echo "The Server is up to date!"
fi

Review comment (suggestion):
Using relative instead of absolute path.
```
palworld/steamapps/appmanifest_2394010.acf: No such file or directory
```

```suggestion
CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf)
```

Code after:
#!/bin/bash

if [ "${UPDATE_ON_BOOT}" = false ]; then
    echo "Update on Boot needs to be enabled for auto updating"
    exit 0
fi

temp_file=$(mktemp)
http_code=$(curl https://api.steamcmd.net/v1/info/2394010 --output "$temp_file" --silent --location --write-out "%{http_code}")

CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf)
TARGETBUILD=$(grep -P '"public": {"buildid": "\d+"' -o <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/')
rm "$temp_file"

if [ "$http_code" -ne 200 ]; then
    echo "There was a problem reaching the Steam api. Unable to check for updates!"
    exit 1
fi

if [ -z "$TARGETBUILD" ]; then
    echo "The server response does not contain the expected BuildID. Unable to check for updates!"
    exit 1
fi

if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
    echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD."
    if [ "${RCON_ENABLED}" = true ]; then
        rm /palworld/steamapps/appmanifest_2394010.acf
        rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
        sleep "${AUTO_UPDATE_WARN_MINUTES}m"
        backup
        rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
    else
Repository: thijsvanloef/palworld-server-docker
File: scripts/update.sh (Shell)

Code before:
#!/bin/bash

if [ "${UPDATE_ON_BOOT}" = false ]; then
    echo "Update on Boot needs to be enabled for auto updating"
    exit 1
fi

CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf)
TARGETBUILD=$(curl https://api.steamcmd.net/v1/info/2394010 --silent | grep -P '"public": {"buildid": "\d+"' -o | sed -r 's/.*("[0-9]+")$/\1/')

if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
    echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD."
    if [ "${RCON_ENABLED}" = true ]; then
        rm /palworld/steamapps/appmanifest_2394010.acf
        rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
        sleep "${AUTO_UPDATE_WARN_MINUTES}m"
        backup
        rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
    else
        echo "An update is available however auto updating without rcon is not supported"
    fi
else
    echo "The Server is up to date!"
fi

Review comment (suggestion):
In the event that `TARGET_BUILD` is empty you shouldn't update.
This will happen if the site is unavailable. You can test by changing to an invalid site.
```suggestion
if [ -n "$TARGETBUILD" ] && [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
```

Code after:
#!/bin/bash

if [ "${UPDATE_ON_BOOT}" = false ]; then
    echo "Update on Boot needs to be enabled for auto updating"
    exit 0
fi

temp_file=$(mktemp)
http_code=$(curl https://api.steamcmd.net/v1/info/2394010 --output "$temp_file" --silent --location --write-out "%{http_code}")

CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf)
TARGETBUILD=$(grep -P '"public": {"buildid": "\d+"' -o <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/')
rm "$temp_file"

if [ "$http_code" -ne 200 ]; then
    echo "There was a problem reaching the Steam api. Unable to check for updates!"
    exit 1
fi

if [ -z "$TARGETBUILD" ]; then
    echo "The server response does not contain the expected BuildID. Unable to check for updates!"
    exit 1
fi

if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
    echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD."
    if [ "${RCON_ENABLED}" = true ]; then
        rm /palworld/steamapps/appmanifest_2394010.acf
        rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
        sleep "${AUTO_UPDATE_WARN_MINUTES}m"
        backup
        rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
    else
        echo "An update is available however auto updating without rcon is not supported"
    fi
else
    echo "The Server is up to date!"
fi
Repository: thijsvanloef/palworld-server-docker
File: scripts/update.sh (Shell)

Code before:
#!/bin/bash

if [ "${UPDATE_ON_BOOT}" = false ]; then
    echo "Update on Boot needs to be enabled for auto updating"
    exit 1
fi

CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf)
TARGETBUILD=$(curl https://api.steamcmd.net/v1/info/2394010 --silent | grep -P '"public": {"buildid": "\d+"' -o | sed -r 's/.*("[0-9]+")$/\1/')

if [ -n "$TARGETBUILD" ] && [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
    echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD."
    if [ "${RCON_ENABLED}" = true ]; then
        rm /palworld/steamapps/appmanifest_2394010.acf
        rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
        sleep "${AUTO_UPDATE_WARN_MINUTES}m"
        backup
        rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
    else
        echo "An update is available however auto updating without rcon is not supported"
    fi
else
    echo "The Server is up to date!"
fi

Review comment (suggestion):
Not sure if it matters but when the site is not reachable we still say `The Server is update to date`

Code after:
TARGETBUILD=$(grep -P '"public": {"buildid": "\d+"' -o <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/')
rm "$temp_file"

if [ "$http_code" -ne 200 ]; then
    echo "There was a problem reaching the Steam api. Unable to check for updates!"
    exit 1
fi

if [ -z "$TARGETBUILD" ]; then
    echo "The server response does not contain the expected BuildID. Unable to check for updates!"
    exit 1
fi

if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
    echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD."
    if [ "${RCON_ENABLED}" = true ]; then
        rm /palworld/steamapps/appmanifest_2394010.acf
        rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
        sleep "${AUTO_UPDATE_WARN_MINUTES}m"
        backup
        rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
    else
        echo "An update is available however auto updating without rcon is not supported"
    fi
else
    echo "The Server is up to date!"
fi
Repository: thijsvanloef/palworld-server-docker
File: scripts/restore.sh (Shell)

Code before:
#!/bin/bash

# Backup file directory path
BACKUP_DIRECTORY_PATH="/palworld/backups"

# Resotre path
RESTORE_PATH="/palworld/Pal"

term_error_handler() {
    echo "An error occurred during server shutdown."
    exit 1
}

restore_error_handler() {
    printf "\033[0;31mAn error occurred during restore.\033[0m\n"
    if [ -d "./tmp_save/Saved" ]; then
      read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
      if [[ $RUN_ANSWER == "y" ]] || [[ $RUN_ANSWER == "Y" ]]; then
        rm -rf "$RESTORE_PATH/Saved"
        mv "./tmp_save/Saved" "$RESTORE_PATH"
        printf "\e[0;32mRecovery complete.\e[0m\n"
      fi
    fi

    rm -rf "./tmp"
    rm -rf "./tmp_save"

    exit 1
}

if [ "${RCON_ENABLED}" != true ]; then
  echo "RCON is not enabled. Please enable RCON to use this feature."
  exit 1
fi

Review comment (suggestion):
Since it's only called by trap you'll want the [disable statement](https://github.com/koalaman/shellcheck/wiki/SC2317#exceptions)
```suggestion

# shellcheck disable=SC2317
term_error_handler() {
```

Code after:
#!/bin/bash

# Backup file directory path
BACKUP_DIRECTORY_PATH="/palworld/backups"

# Resotre path
RESTORE_PATH="/palworld/Pal"

# Copy the save file before restore temporary path
TMP_SAVE_PATH="/palworld/backups/restore-"$(date +"%Y-%m-%d_%H-%M-%S")

# shellcheck disable=SC2317
term_error_handler() {
    echo "An error occurred during server shutdown."
    exit 1
}

# shellcheck disable=SC2317
restore_error_handler() {
    printf "\033[0;31mAn error occurred during restore.\033[0m\n"
    if [ -d "$TMP_SAVE_PATH/Saved" ]; then
        read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
        if [[ ${RUN_ANSWER,,} == "y" ]]; then
            rm -rf "$RESTORE_PATH/Saved"
            mv "$TMP_SAVE_PATH/Saved" "$RESTORE_PATH"
            printf "\e[0;32mRecovery complete.\e[0m\n"
        fi
    fi

    echo "Clean up the temporary directory."
    rm -rf "$TMP_PATH" "$TMP_SAVE_PATH"

    exit 1
}
Repository: thijsvanloef/palworld-server-docker
File: scripts/restore.sh (Shell)

Code before:
#!/bin/bash

# Backup file directory path
BACKUP_DIRECTORY_PATH="/palworld/backups"

# Resotre path
RESTORE_PATH="/palworld/Pal"

term_error_handler() {
    echo "An error occurred during server shutdown."
    exit 1
}

restore_error_handler() {
    printf "\033[0;31mAn error occurred during restore.\033[0m\n"
    if [ -d "./tmp_save/Saved" ]; then
      read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
      if [[ $RUN_ANSWER == "y" ]] || [[ $RUN_ANSWER == "Y" ]]; then
        rm -rf "$RESTORE_PATH/Saved"
        mv "./tmp_save/Saved" "$RESTORE_PATH"
        printf "\e[0;32mRecovery complete.\e[0m\n"
      fi
    fi

    rm -rf "./tmp"
    rm -rf "./tmp_save"

    exit 1
}

if [ "${RCON_ENABLED}" != true ]; then
  echo "RCON is not enabled. Please enable RCON to use this feature."
  exit 1
fi

# Show up backup list
echo "Backup List:"
select BACKUP_FILE in "$BACKUP_DIRECTORY_PATH"/*; do
    if [ -n "$BACKUP_FILE" ]; then

Review comment (suggestion):
Since it's only called by trap you'll want the [disable statement](https://github.com/koalaman/shellcheck/wiki/SC2317#exceptions)
```suggestion

# shellcheck disable=SC2317
restore_error_handler() {
```

Code after:
#!/bin/bash

# Backup file directory path
BACKUP_DIRECTORY_PATH="/palworld/backups"

# Resotre path
RESTORE_PATH="/palworld/Pal"

# Copy the save file before restore temporary path
TMP_SAVE_PATH="/palworld/backups/restore-"$(date +"%Y-%m-%d_%H-%M-%S")

# shellcheck disable=SC2317
term_error_handler() {
    echo "An error occurred during server shutdown."
    exit 1
}

# shellcheck disable=SC2317
restore_error_handler() {
    printf "\033[0;31mAn error occurred during restore.\033[0m\n"
    if [ -d "$TMP_SAVE_PATH/Saved" ]; then
        read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
        if [[ ${RUN_ANSWER,,} == "y" ]]; then
            rm -rf "$RESTORE_PATH/Saved"
            mv "$TMP_SAVE_PATH/Saved" "$RESTORE_PATH"
            printf "\e[0;32mRecovery complete.\e[0m\n"
        fi
    fi

    echo "Clean up the temporary directory."
    rm -rf "$TMP_PATH" "$TMP_SAVE_PATH"

    exit 1
}

if [ "${RCON_ENABLED}" != true ]; then
    echo "RCON is not enabled. Please enable RCON to use this feature."
    exit 1
fi
Repository: thijsvanloef/palworld-server-docker
File: scripts/restore.sh (Shell)

Code before:
#!/bin/bash

# Backup file directory path
BACKUP_DIRECTORY_PATH="/palworld/backups"

# Resotre path
RESTORE_PATH="/palworld/Pal"

# Copy the save file before restore temporary path
TMP_SAVE_PATH="/palworld/backups/restore-"$(date +"%Y-%m-%d_%H-%M-%S")

# shellcheck disable=SC2317
term_error_handler() {
    echo "An error occurred during server shutdown."
    exit 1
}

# shellcheck disable=SC2317
restore_error_handler() {
    printf "\033[0;31mAn error occurred during restore.\033[0m\n"
    if [ -d "$TMP_SAVE_PATH/Saved" ]; then
        read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
        if [[ $RUN_ANSWER == "y" ]] || [[ $RUN_ANSWER == "Y" ]]; then
            rm -rf "$RESTORE_PATH/Saved"
            mv "$TMP_SAVE_PATH/Saved" "$RESTORE_PATH"
            printf "\e[0;32mRecovery complete.\e[0m\n"
        fi
    fi

    echo "Clean up the temporary directory."
    rm -rf "$TMP_PATH"
    rm -rf "$TMP_SAVE_PATH"

    exit 1
}

if [ "${RCON_ENABLED}" != true ]; then
    echo "RCON is not enabled. Please enable RCON to use this feature."
    exit 1
fi

# Show up backup list
echo "Backup List:"
select BACKUP_FILE in "$BACKUP_DIRECTORY_PATH"/*; do
    if [ -n "$BACKUP_FILE" ]; then
        echo "Selected backup: $BACKUP_FILE"
        break
    else

Review comment (suggestion):
I'd convert to lowercase for comparison.
```suggestion
        if [[ ${RUN_ANSWER,,} == "y" ]]; then
```

Code after:
#!/bin/bash

# Backup file directory path
BACKUP_DIRECTORY_PATH="/palworld/backups"

# Resotre path
RESTORE_PATH="/palworld/Pal"

# Copy the save file before restore temporary path
TMP_SAVE_PATH="/palworld/backups/restore-"$(date +"%Y-%m-%d_%H-%M-%S")

# shellcheck disable=SC2317
term_error_handler() {
    echo "An error occurred during server shutdown."
    exit 1
}

# shellcheck disable=SC2317
restore_error_handler() {
    printf "\033[0;31mAn error occurred during restore.\033[0m\n"
    if [ -d "$TMP_SAVE_PATH/Saved" ]; then
        read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
        if [[ ${RUN_ANSWER,,} == "y" ]]; then
            rm -rf "$RESTORE_PATH/Saved"
            mv "$TMP_SAVE_PATH/Saved" "$RESTORE_PATH"
            printf "\e[0;32mRecovery complete.\e[0m\n"
        fi
    fi

    echo "Clean up the temporary directory."
    rm -rf "$TMP_PATH" "$TMP_SAVE_PATH"

    exit 1
}

if [ "${RCON_ENABLED}" != true ]; then
    echo "RCON is not enabled. Please enable RCON to use this feature."
    exit 1
fi

# Show up backup list
echo "Backup List:"
mapfile -t BACKUP_FILES < <(find "$BACKUP_DIRECTORY_PATH" -type f -name "*.tar.gz" | sort)
select BACKUP_FILE in "${BACKUP_FILES[@]}"; do
    if [ -n "$BACKUP_FILE" ]; then
        echo "Selected backup: $BACKUP_FILE"
        break
    else
Repository: thijsvanloef/palworld-server-docker
File: scripts/compile-settings.sh (Shell)

Code before:
IS_MULTIPLAY = $IS_MULTIPLAY
IS_PVP = $IS_PVP
CAN_PICKUP_OTHER_GUILD_DEATH_PENALTY_DROP = $CAN_PICKUP_OTHER_GUILD_DEATH_PENALTY_DROP
ENABLE_NON_LOGIN_PENALTY = $ENABLE_NON_LOGIN_PENALTY
ENABLE_FAST_TRAVEL = $ENABLE_FAST_TRAVEL
IS_START_LOCATION_SELECT_BY_MAP = $IS_START_LOCATION_SELECT_BY_MAP
EXIST_PLAYER_AFTER_LOGOUT = $EXIST_PLAYER_AFTER_LOGOUT
ENABLE_DEFENSE_OTHER_GUILD_PLAYER = $ENABLE_DEFENSE_OTHER_GUILD_PLAYER
COOP_PLAYER_MAX_NUM = $COOP_PLAYER_MAX_NUM
SERVER_PLAYER_MAX_NUM = $SERVER_PLAYER_MAX_NUM
SERVER_NAME = $SERVER_NAME
SERVER_DESCRIPTION = $SERVER_DESCRIPTION
ADMIN_PASSWORD = $ADMIN_PASSWORD
SERVER_PASSWORD = $SERVER_PASSWORD
PUBLIC_PORT = $PUBLIC_PORT
PUBLIC_IP = $PUBLIC_IP
RCON_ENABLED = $RCON_ENABLED
RCON_PORT = $RCON_PORT
REGION = $REGION
USEAUTH = $USEAUTH
BAN_LIST_URL = $BAN_LIST_URL
REST_API_ENABLED= $REST_API_ENABLED
REST_API_PORT= $REST_API_PORT
SHOW_PLAYER_LIST = $SHOW_PLAYER_LIST
ALLOW_CONNECT_PLATFORM= $ALLOW_CONNECT_PLATFORM
USE_BACKUP_SAVE_DATA= $USE_BACKUP_SAVE_DATA
====Debug====
EOF
fi

cat > "$config_file" <<EOF
[/Script/Pal.PalGameWorldSettings]
$(envsubst < /home/steam/server/files/PalWorldSettings.ini.template | tr -d "\n\r")
EOF

LogSuccess "Compiling PalWorldSettings.ini done!"

Review comment (suggestion):
```suggestion
REST_API_ENABLED = $REST_API_ENABLED
REST_API_PORT = $REST_API_PORT
SHOW_PLAYER_LIST = $SHOW_PLAYER_LIST
ALLOW_CONNECT_PLATFORM = $ALLOW_CONNECT_PLATFORM
USE_BACKUP_SAVE_DATA = $USE_BACKUP_SAVE_DATA
```

Keep it consistent 

Code after:
IS_MULTIPLAY = $IS_MULTIPLAY
IS_PVP = $IS_PVP
CAN_PICKUP_OTHER_GUILD_DEATH_PENALTY_DROP = $CAN_PICKUP_OTHER_GUILD_DEATH_PENALTY_DROP
ENABLE_NON_LOGIN_PENALTY = $ENABLE_NON_LOGIN_PENALTY
ENABLE_FAST_TRAVEL = $ENABLE_FAST_TRAVEL
IS_START_LOCATION_SELECT_BY_MAP = $IS_START_LOCATION_SELECT_BY_MAP
EXIST_PLAYER_AFTER_LOGOUT = $EXIST_PLAYER_AFTER_LOGOUT
ENABLE_DEFENSE_OTHER_GUILD_PLAYER = $ENABLE_DEFENSE_OTHER_GUILD_PLAYER
COOP_PLAYER_MAX_NUM = $COOP_PLAYER_MAX_NUM
SERVER_PLAYER_MAX_NUM = $SERVER_PLAYER_MAX_NUM
SERVER_NAME = $SERVER_NAME
SERVER_DESCRIPTION = $SERVER_DESCRIPTION
ADMIN_PASSWORD = $ADMIN_PASSWORD
SERVER_PASSWORD = $SERVER_PASSWORD
PUBLIC_PORT = $PUBLIC_PORT
PUBLIC_IP = $PUBLIC_IP
RCON_ENABLED = $RCON_ENABLED
RCON_PORT = $RCON_PORT
REGION = $REGION
USEAUTH = $USEAUTH
BAN_LIST_URL = $BAN_LIST_URL
REST_API_ENABLED = $REST_API_ENABLED
REST_API_PORT = $REST_API_PORT
SHOW_PLAYER_LIST = $SHOW_PLAYER_LIST
ALLOW_CONNECT_PLATFORM = $ALLOW_CONNECT_PLATFORM
USE_BACKUP_SAVE_DATA = $USE_BACKUP_SAVE_DATA
====Debug====
EOF
fi

cat > "$config_file" <<EOF
[/Script/Pal.PalGameWorldSettings]
$(envsubst < /home/steam/server/files/PalWorldSettings.ini.template | tr -d "\n\r")
EOF

LogSuccess "Compiling PalWorldSettings.ini done!"
Repository: tiangolo/fastapi
File: tests/test_response_model_default_factory.py (Python)

Code before:
import functools
import random

from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field

app = FastAPI()

messages = ["操作成功.", "Successful operation."]


class ResponseModel(BaseModel):
    code: int = 200
    message: str = Field(default_factory=functools.partial(random.choice, messages))


@app.get(
    "/response_model_has_default_factory_return_dict",
    response_model=ResponseModel,
)
async def response_model_has_default_factory_return_dict():
    return {"code": 200}


@app.get(
    "/response_model_has_default_factory_return_model",
    response_model=ResponseModel,
)
async def response_model_has_default_factory_return_model():
    return ResponseModel()


client = TestClient(app)


def test_response_model_has_default_factory_return_dict():
    response = client.get("/response_model_has_default_factory_return_dict")

    assert response.status_code == 200, response.text

Review comment (suggestion):
```suggestion
    message: str = Field(default_factory=lambda: "Successful operation.")
```

Code after:
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field

app = FastAPI()


class ResponseModel(BaseModel):
    code: int = 200
    message: str = Field(default_factory=lambda: "Successful operation.")


@app.get(
    "/response_model_has_default_factory_return_dict",
    response_model=ResponseModel,
)
async def response_model_has_default_factory_return_dict():
    return {"code": 200}


@app.get(
    "/response_model_has_default_factory_return_model",
    response_model=ResponseModel,
)
async def response_model_has_default_factory_return_model():
    return ResponseModel()


client = TestClient(app)


def test_response_model_has_default_factory_return_dict():
    response = client.get("/response_model_has_default_factory_return_dict")

    assert response.status_code == 200, response.text

    assert response.json()["code"] == 200
    assert response.json()["message"] == "Successful operation."
Repository: tiangolo/fastapi
File: tests/test_response_model_default_factory.py (Python)

Code before:
@app.get(
    "/response_model_has_default_factory_return_dict",
    response_model=ResponseModel,
)
async def response_model_has_default_factory_return_dict():
    return {"code": 200}


@app.get(
    "/response_model_has_default_factory_return_model",
    response_model=ResponseModel,
)
async def response_model_has_default_factory_return_model():
    return ResponseModel()


client = TestClient(app)


def test_response_model_has_default_factory_return_dict():
    response = client.get("/response_model_has_default_factory_return_dict")

    assert response.status_code == 200, response.text

    assert response.json()["code"] == 200
    assert response.json()["message"] in messages


def test_response_model_has_default_factory_return_model():
    response = client.get("/response_model_has_default_factory_return_model")

    assert response.status_code == 200, response.text

    assert response.json()["code"] == 200
    assert response.json()["message"] in messages


Review comment (suggestion):
```suggestion
    assert response.json()["message"] == "Successful operation."
```

Code after:
    return {"code": 200}


@app.get(
    "/response_model_has_default_factory_return_model",
    response_model=ResponseModel,
)
async def response_model_has_default_factory_return_model():
    return ResponseModel()


client = TestClient(app)


def test_response_model_has_default_factory_return_dict():
    response = client.get("/response_model_has_default_factory_return_dict")

    assert response.status_code == 200, response.text

    assert response.json()["code"] == 200
    assert response.json()["message"] == "Successful operation."


def test_response_model_has_default_factory_return_model():
    response = client.get("/response_model_has_default_factory_return_model")

    assert response.status_code == 200, response.text

    assert response.json()["code"] == 200
    assert response.json()["message"] == "Successful operation."