Skip to content

Commit

Permalink
fix python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez committed Nov 13, 2023
1 parent 40fcbeb commit bf3a70d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion functions-python/tokens/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_idp_api_key() -> str:
"""
gcp_idp_api_key = os.environ.get("FEEDS_GCP_IDP_API_KEY")
if gcp_idp_api_key is None:
raise ValueError("GCP_IDP_API_KEY environment variable is not set.")
raise ValueError("FEEDS_GCP_IDP_API_KEY environment variable is not set.")
return gcp_idp_api_key


Expand Down
4 changes: 2 additions & 2 deletions functions-python/tokens/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_source_path(file: str):
return source


@mock.patch.dict(os.environ, {"GCP_IDP_API_KEY": "gcp_idp_api_test_key"})
@mock.patch.dict(os.environ, {"FEEDS_GCP_IDP_API_KEY": "gcp_idp_api_test_key"})
@patch("requests.post")
def test_get_idp_response__valid_request(mock_post):
# Mock the response from IDP requests.post
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_tokens_post_missing_refresh_token():
)


@mock.patch.dict(os.environ, {"GCP_IDP_API_KEY": "gcp_idp_api_test_key"})
@mock.patch.dict(os.environ, {"FEEDS_GCP_IDP_API_KEY": "gcp_idp_api_test_key"})
@patch("requests.post")
def test_tokens_valid_request(mock_post):
"""
Expand Down
17 changes: 12 additions & 5 deletions scripts/api-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ if [[ ! -z "${TEST_FILE}" && ! -z "${FOLDER}" ]]; then
exit 1
fi

# if no parameters is passed, execute all tests
if [[ -z "${FOLDER}" ]] && [[ -z "${TEST_FILE}" ]]; then
execute_tests "../api"
execute_python_tests() {
printf "\nExecuting python tests in $1\n"
cd $ABS_SCRIPTPATH/../functions-python
for file in */; do
if [[ -d "$file" && ! -L "$file" ]]; then
Expand All @@ -86,6 +85,11 @@ if [[ -z "${FOLDER}" ]] && [[ -z "${TEST_FILE}" ]]; then
fi
fi
done
}

# if no parameters is passed, execute all tests
if [[ -z "${FOLDER}" ]] && [[ -z "${TEST_FILE}" ]]; then
execute_tests "../api"
exit 0
fi

Expand All @@ -95,6 +99,9 @@ if [[ ! -z "${TEST_FILE}" ]]; then
fi

if [[ ! -z "${FOLDER}" ]]; then
execute_tests "../$FOLDER"
exit 0
if [[ "${FOLDER}" == "functions-python" ]]; then
execute_python_tests
else
execute_tests "../$FOLDER"
fi
fi

0 comments on commit bf3a70d

Please sign in to comment.