Skip to content

Commit 0d1e308

Browse files
authored
[AIRFLOW-6970] Improve GCP Video Intelligence system tests (#7604)
1 parent 46e55fb commit 0d1e308

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

airflow/providers/google/cloud/hooks/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import httplib2
3535
import tenacity
3636
from google.api_core.exceptions import (
37-
AlreadyExists, Forbidden, GoogleAPICallError, ResourceExhausted, RetryError,
37+
AlreadyExists, Forbidden, GoogleAPICallError, ResourceExhausted, RetryError, TooManyRequests,
3838
)
3939
from google.api_core.gapic_v1.client_info import ClientInfo
4040
from google.auth.environment_vars import CREDENTIALS
@@ -76,12 +76,12 @@ def is_soft_quota_exception(exception: Exception):
7676
"""
7777
if isinstance(exception, Forbidden):
7878
return any(
79-
reason in error["reason"]
79+
reason in error.details()
8080
for reason in INVALID_REASONS
8181
for error in exception.errors
8282
)
8383

84-
if isinstance(exception, ResourceExhausted):
84+
if isinstance(exception, (ResourceExhausted, TooManyRequests)):
8585
return any(
8686
key in error.details()
8787
for key in INVALID_KEYS

tests/providers/google/cloud/hooks/test_base.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ def test_do_nothing_on_non_error(self):
8181
def test_retry_on_exception(self):
8282
message = "POST https://translation.googleapis.com/language/translate/v2: User Rate Limit Exceeded"
8383
errors = [
84-
{
85-
'message': 'User Rate Limit Exceeded',
86-
'domain': 'usageLimits',
87-
'reason': 'userRateLimitExceeded',
88-
}
84+
mock.MagicMock(details=mock.PropertyMock(return_value='userRateLimitExceeded'))
8985
]
9086
custom_fn = NoForbiddenAfterCount(
9187
count=5,
@@ -99,7 +95,7 @@ def test_raise_exception_on_non_quota_exception(self):
9995
with self.assertRaisesRegex(Forbidden, "Daily Limit Exceeded"):
10096
message = "POST https://translation.googleapis.com/language/translate/v2: Daily Limit Exceeded"
10197
errors = [
102-
{'message': 'Daily Limit Exceeded', 'domain': 'usageLimits', 'reason': 'dailyLimitExceeded'}
98+
mock.MagicMock(details=mock.PropertyMock(return_value='dailyLimitExceeded'))
10399
]
104100

105101
_retryable_test_with_temporary_quota_retry(

tests/providers/google/cloud/operators/test_video_intelligence_system.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import pytest
2121

22+
from airflow.providers.google.cloud.example_dags.example_video_intelligence import GCP_BUCKET_NAME
2223
from tests.providers.google.cloud.utils.gcp_authenticator import GCP_AI_KEY, GCP_GCS_KEY
2324
from tests.test_utils.gcp_system_helpers import CLOUD_DAG_FOLDER, GoogleSystemTest, provide_gcp_context
2425

2526
GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "example-project")
26-
GCP_BUCKET_NAME = os.environ.get("GCP_VIDEO_INTELLIGENCE_BUCKET_NAME", "test-bucket-name")
27-
GCP_VIDEO_SOURCE_URL = os.environ.get("GCP_VIDEO_INTELLIGENCE_VIDEO_SOURCE_URL", "http://nasa.gov")
27+
GCP_VIDEO_SOURCE_URL = "https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4"
2828

2929

3030
@pytest.mark.backend("mysql", "postgres")
@@ -49,5 +49,5 @@ def tearDown(self):
4949
super().tearDown()
5050

5151
@provide_gcp_context(GCP_AI_KEY)
52-
def test_run_example_dag_spanner(self):
52+
def test_example_dag(self):
5353
self.run_dag('example_gcp_video_intelligence', CLOUD_DAG_FOLDER)

0 commit comments

Comments
 (0)