Skip to content

Commit fde487c

Browse files
authored
Reassert idp-sql and django tests (#7779)
## Description #7342 introduced a change where nox would check for `test_*.py` and `*_test.py` files. Django and IDP-SQL had their tests in `test/`, so this glob didn't find these files, and these tests haven't been run for a bit. Outstanding issues with these tests: *dynamic PR status update follows* --- * Django: Postgres 9.6 EOL ``` Step #6 - "Migrate database": django.db.utils.ProgrammingError: column c.relispartition does not exist Step #6 - "Migrate database": LINE 3: CASE WHEN c.relispartition THEN 'p' WHEN c.relki... Step #6 - "Migrate database": ``` Debugging seems to indicate this happens on old versions of postgres. [Django 4.0 no longer supports Postgres 9.6](https://docs.djangoproject.com/en/4.0/releases/4.0/#dropped-support-for-postgresql-9-6). `test-instance-pg` is Postgres 9.6, which is EOL as of November 2021. Suggest creating a newer versioned instance of a postgres testing database (happy to help here where I can). Update: test-instance-pg has been updated to Postgres 14 --- * IDP: Linting issues ``` ./middleware.py:31:29: ANN401 Dynamically typed expressions (typing.Any) are disallowed def decorated_function(*args: Any, **kwargs: Any) -> Any: ^ ./middleware.py:31:42: ANN401 Dynamically typed expressions (typing.Any) are disallowed def decorated_function(*args: Any, **kwargs: Any) -> Any: ^ ./middleware.py:31:61: ANN401 Dynamically typed expressions (typing.Any) are disallowed def decorated_function(*args: Any, **kwargs: Any) -> Any: ^ ``` This is being addressed as of v2.9.0 of flake8-annotations. sco1/flake8-annotations#136 It will require adding `--allow-star-arg-any` to the flake8 call. Update: while this flag could be used, I opted to use the `TypeVar` method in #7789 --- ## Checklist - [ ] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md) - [ ] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#readme-file) - [ ] **Tests** pass: `nox -s py-3.6` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [ ] Please **merge** this PR for me once it is approved. - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/.github/CODEOWNERS) with the codeowners for this sample
1 parent 651c9cd commit fde487c

10 files changed

+34
-32
lines changed

run/django/test/e2e_test.py renamed to run/django/e2e_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def deployed_service() -> str:
9292
"--project",
9393
GOOGLE_CLOUD_PROJECT,
9494
"--config",
95-
"./test/e2e_test_setup.yaml",
95+
"./e2e_test_setup.yaml",
9696
"--substitutions",
9797
]
9898
+ substitutions
@@ -124,7 +124,7 @@ def deployed_service() -> str:
124124
"--project",
125125
GOOGLE_CLOUD_PROJECT,
126126
"--config",
127-
"./test/e2e_test_cleanup.yaml",
127+
"./e2e_test_cleanup.yaml",
128128
"--substitutions",
129129
]
130130
+ substitutions

run/django/test/e2e_test_cleanup.yaml renamed to run/django/e2e_test_cleanup.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ steps:
1919
args:
2020
- "-ec"
2121
- |
22-
./test/retry.sh "gcloud secrets describe ${_SECRET_SETTINGS_NAME}" \
22+
./retry.sh "gcloud secrets describe ${_SECRET_SETTINGS_NAME}" \
2323
"gcloud secrets delete ${_SECRET_SETTINGS_NAME} --quiet --project $PROJECT_ID"
2424
25-
./test/retry.sh "gcloud secrets describe ${_SECRET_PASSWORD_NAME}" \
25+
./retry.sh "gcloud secrets describe ${_SECRET_PASSWORD_NAME}" \
2626
"gcloud secrets delete ${_SECRET_PASSWORD_NAME} --quiet --project $PROJECT_ID"
2727
28-
./test/retry.sh "gsutil ls gs://${_STORAGE_BUCKET}" \
28+
./retry.sh "gsutil ls gs://${_STORAGE_BUCKET}" \
2929
"gsutil -m rm -r gs://${_STORAGE_BUCKET}"
3030
31-
./test/retry.sh "gcloud container images describe gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}" \
31+
./retry.sh "gcloud container images describe gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}" \
3232
"gcloud container images delete gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} --quiet"
3333
34-
./test/retry.sh "gcloud run services describe ${_SERVICE} --region ${_REGION} --platform ${_PLATFORM}" \
34+
./retry.sh "gcloud run services describe ${_SERVICE} --region ${_REGION} --platform ${_PLATFORM}" \
3535
"gcloud run services delete ${_SERVICE} --region ${_REGION} --platform ${_PLATFORM} --async --quiet"
3636
37-
WAIT=30 ./test/retry.sh "gcloud sql databases describe ${_DB_NAME} --instance ${_DB_INSTANCE} --project $PROJECT_ID" \
37+
WAIT=30 ./retry.sh "gcloud sql databases describe ${_DB_NAME} --instance ${_DB_INSTANCE} --project $PROJECT_ID" \
3838
"gcloud sql databases delete ${_DB_NAME} --instance ${_DB_INSTANCE} --quiet --project $PROJECT_ID"
3939
40-
./test/retry.sh "gcloud sql users list --filter \"name=${_DB_USER}\" --instance ${_DB_INSTANCE}" \
40+
./retry.sh "gcloud sql users list --filter \"name=${_DB_USER}\" --instance ${_DB_INSTANCE}" \
4141
"gcloud sql users delete ${_DB_USER} --instance ${_DB_INSTANCE} --quiet --project $PROJECT_ID"
4242
4343
substitutions:

run/django/test/e2e_test_setup.yaml renamed to run/django/e2e_test_setup.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ steps:
1919
args:
2020
- "-c"
2121
- |
22-
WAIT=30 ./test/retry.sh "gcloud sql databases create ${_DB_NAME} \
22+
WAIT=30 ./retry.sh "gcloud sql databases create ${_DB_NAME} \
2323
--instance ${_DB_INSTANCE} \
2424
--project ${PROJECT_ID}"
2525
@@ -30,7 +30,7 @@ steps:
3030
- "-c"
3131
- |
3232
echo -n "${_DB_PASS}" > db_password
33-
./test/retry.sh "gcloud sql users create ${_DB_USER} \
33+
./retry.sh "gcloud sql users create ${_DB_USER} \
3434
--password $(cat db_password) \
3535
--instance ${_DB_INSTANCE} \
3636
--project ${PROJECT_ID}"
@@ -42,7 +42,7 @@ steps:
4242
args:
4343
- "-c"
4444
- |
45-
./test/retry.sh "gsutil mb \
45+
./retry.sh "gsutil mb \
4646
-l ${_REGION} \
4747
-p ${PROJECT_ID} \
4848
gs://${_STORAGE_BUCKET}"
@@ -59,7 +59,7 @@ steps:
5959
SECRET_KEY=$(cat /dev/urandom | LC_ALL=C tr -dc '[:alpha:]' | fold -w 30 | head -n1)
6060
PASSWORD_NAME=${_SECRET_PASSWORD_NAME}" > ${_SECRET_SETTINGS_NAME}
6161
62-
./test/retry.sh "gcloud secrets create ${_SECRET_SETTINGS_NAME} \
62+
./retry.sh "gcloud secrets create ${_SECRET_SETTINGS_NAME} \
6363
--project $PROJECT_ID \
6464
--data-file=${_SECRET_SETTINGS_NAME}"
6565
@@ -72,7 +72,7 @@ steps:
7272
7373
echo -n "${_SECRET_PASSWORD_VALUE}" > ${_SECRET_PASSWORD_NAME}
7474
75-
./test/retry.sh "gcloud secrets create ${_SECRET_PASSWORD_NAME} \
75+
./retry.sh "gcloud secrets create ${_SECRET_PASSWORD_NAME} \
7676
--project $PROJECT_ID \
7777
--data-file=${_SECRET_PASSWORD_NAME}"
7878
@@ -89,15 +89,15 @@ steps:
8989
args:
9090
- "-c"
9191
- |
92-
./test/retry.sh "docker build -t gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} ."
92+
./retry.sh "docker build -t gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} ."
9393
9494
- id: "Push Container Image"
9595
name: "gcr.io/cloud-builders/docker"
9696
entrypoint: "/bin/bash"
9797
args:
9898
- "-c"
9999
- |
100-
./test/retry.sh "docker push gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}"
100+
./retry.sh "docker push gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}"
101101
102102
- id: "Migrate database"
103103
name: "gcr.io/google-appengine/exec-wrapper"
@@ -142,7 +142,7 @@ steps:
142142
args:
143143
- "-c"
144144
- |
145-
./test/retry.sh "gcloud run deploy ${_SERVICE} \
145+
./retry.sh "gcloud run deploy ${_SERVICE} \
146146
--project $PROJECT_ID \
147147
--image gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} \
148148
--no-allow-unauthenticated \
File renamed without changes.

run/idp-sql/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ to be set.
7272
### Unit tests
7373

7474
```
75-
pytest test/test_app.py
75+
pytest test_app.py
7676
```
7777

7878
### System Tests
@@ -82,5 +82,5 @@ export GOOGLE_CLOUD_PROJECT=<YOUR_PROJECT_ID>
8282
export CLOUD_SQL_CONNECTION_NAME=<YOUR_CLOUD_SQL_CONNECTION_NAME>
8383
export DB_PASSWORD=<POSTGRESQL_PASSWORD>
8484
export IDP_KEY=<IDENTITY_PLATFORM_API_KEY> # See tutorial for creation of this key ("API_KEY")
85-
pytest test/e2e_test.py
85+
pytest e2e_test.py
8686
```

run/idp-sql/test/e2e_test.py renamed to run/idp-sql/e2e_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def deployed_service() -> str:
114114
"--project",
115115
GOOGLE_CLOUD_PROJECT,
116116
"--config",
117-
"./test/e2e_test_setup.yaml",
117+
"./e2e_test_setup.yaml",
118118
"--substitutions",
119119
]
120120
+ substitutions
@@ -166,7 +166,7 @@ def deployed_service() -> str:
166166
"--project",
167167
GOOGLE_CLOUD_PROJECT,
168168
"--config",
169-
"./test/e2e_test_cleanup.yaml",
169+
"./e2e_test_cleanup.yaml",
170170
"--substitutions",
171171
]
172172
+ substitutions

run/idp-sql/test/e2e_test_cleanup.yaml renamed to run/idp-sql/e2e_test_cleanup.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ steps:
2020
args:
2121
- '-ec'
2222
- |
23-
./test/retry.sh "gcloud run services describe ${_SERVICE} --region ${_REGION} --platform ${_PLATFORM}" \
23+
./retry.sh "gcloud run services describe ${_SERVICE} --region ${_REGION} --platform ${_PLATFORM}" \
2424
"gcloud run services delete ${_SERVICE} --region ${_REGION} --platform ${_PLATFORM} --quiet"
2525
26-
./test/retry.sh "gcloud secrets describe ${_SERVICE}-secrets" \
26+
./retry.sh "gcloud secrets describe ${_SERVICE}-secrets" \
2727
"gcloud secrets delete ${_SERVICE}-secrets --quiet --project $PROJECT_ID"
2828
29-
./test/retry.sh "gcloud container images describe gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}" \
29+
./retry.sh "gcloud container images describe gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}" \
3030
"gcloud container images delete gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} --quiet"
3131
32-
WAIT=30 ./test/retry.sh "gcloud sql databases describe ${_DB_NAME} --instance ${_DB_INSTANCE} --project $PROJECT_ID" \
32+
WAIT=30 ./retry.sh "gcloud sql databases describe ${_DB_NAME} --instance ${_DB_INSTANCE} --project $PROJECT_ID" \
3333
"gcloud sql databases delete ${_DB_NAME} --instance ${_DB_INSTANCE} --quiet --project $PROJECT_ID"
3434
3535
substitutions:

run/idp-sql/test/e2e_test_setup.yaml renamed to run/idp-sql/e2e_test_setup.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ steps:
2020
args:
2121
- '-c'
2222
- |
23-
WAIT=30 ./test/retry.sh "gcloud sql databases create ${_DB_NAME} \
23+
WAIT=30 ./retry.sh "gcloud sql databases create ${_DB_NAME} \
2424
--instance ${_DB_INSTANCE} \
2525
--project $PROJECT_ID"
2626
@@ -35,7 +35,7 @@ steps:
3535
sed -i "s/\"DB_NAME\": \"postgres\"/\"DB_NAME\": \"${_DB_NAME}\"/" postgres-secrets.json
3636
sed -i "s/\"DB_USER\": \"postgres\"/\"DB_USER\": \"${_DB_USER}\"/" postgres-secrets.json
3737
38-
./test/retry.sh "gcloud secrets create ${_SERVICE}-secrets \
38+
./retry.sh "gcloud secrets create ${_SERVICE}-secrets \
3939
--project $PROJECT_ID \
4040
--replication-policy="automatic" \
4141
--data-file=postgres-secrets.json" \
@@ -47,23 +47,23 @@ steps:
4747
args:
4848
- '-c'
4949
- |
50-
./test/retry.sh "docker build -t gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} ."
50+
./retry.sh "docker build -t gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} ."
5151
5252
- id: 'Push Container Image'
5353
name: 'gcr.io/cloud-builders/docker'
5454
entrypoint: '/bin/bash'
5555
args:
5656
- '-c'
5757
- |
58-
./test/retry.sh "docker push gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}"
58+
./retry.sh "docker push gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}"
5959
6060
- id: 'Deploy to Cloud Run'
6161
name: 'gcr.io/cloud-builders/gcloud:latest'
6262
entrypoint: /bin/bash
6363
args:
6464
- '-c'
6565
- |
66-
./test/retry.sh "gcloud beta run deploy ${_SERVICE} \
66+
./retry.sh "gcloud beta run deploy ${_SERVICE} \
6767
--project $PROJECT_ID \
6868
--image gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} \
6969
--allow-unauthenticated \

run/idp-sql/middleware.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@
1414

1515

1616
from functools import wraps
17-
from typing import Any, Callable, Dict
17+
from typing import Callable, Dict, TypeVar
1818

1919
import firebase_admin
2020
from firebase_admin import auth # noqa: F401
2121
from flask import request, Response
2222
import structlog
2323

2424

25+
a = TypeVar("a")
26+
2527
default_app = firebase_admin.initialize_app()
2628

2729

2830
# [START cloudrun_user_auth_jwt]
2931
def jwt_authenticated(func: Callable[..., int]) -> Callable[..., int]:
3032
@wraps(func)
31-
def decorated_function(*args: Any, **kwargs: Any) -> Any:
33+
def decorated_function(*args: a, **kwargs: a) -> a:
3234
header = request.headers.get("Authorization", None)
3335
if header:
3436
token = header.split(" ")[1]
File renamed without changes.

0 commit comments

Comments
 (0)