Skip to content

Commit

Permalink
test: fix system tests for VPCSC (#69)
Browse files Browse the repository at this point in the history
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-videointelligence/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕
  • Loading branch information
sli2126 authored Oct 31, 2020
1 parent 894bbff commit 9b0fbe6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,33 @@

"""System tests for VideoIntelligence API."""

import os
import pytest

from google.cloud import videointelligence_v1
from test_utils.retry import RetryResult
from test_utils.vpcsc_config import vpcsc_config


INPUT_URI = "gs://cloud-samples-data/video/cat.mp4"
VPCSC_INPUT_URI = "gs://{}/cat.mp4".format(
os.environ.get("GOOGLE_CLOUD_TESTS_VPCSC_INSIDE_PERIMETER_BUCKET")
)


@pytest.fixture(scope="module")
def client():
return videointelligence_v1.VideoIntelligenceServiceClient()


def _get_video_uri():
return VPCSC_INPUT_URI if vpcsc_config.inside_vpcsc else INPUT_URI


def test_annotate_video(client):
features_element = videointelligence_v1.enums.Feature.LABEL_DETECTION
features = [features_element]
response = client.annotate_video(input_uri=INPUT_URI, features=features)
response = client.annotate_video(input_uri=_get_video_uri(), features=features)

retry = RetryResult(result_predicate=bool, max_tries=7)
retry(response.done)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform"
CREDENTIALS_FILE = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
API_ENDPOINT_URL = "https://videointelligence.googleapis.com/v1/videos:annotate"
BUCKET_INSIDE = os.environ.get("GOOGLE_CLOUD_TESTS_VPCSC_INSIDE_PERIMETER_BUCKET")


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -64,18 +65,18 @@ def test_outside_perimeter_blocked(headers):

response = requests.post(url=API_ENDPOINT_URL, data=body, headers=headers)

assert response.json["error"]["code"] == 403
assert response.json["error"]["status"] == "PERMISSION_DENIED"
assert response.json()["error"]["code"] == 403
assert response.json()["error"]["status"] == "PERMISSION_DENIED"


@vpcsc_config.skip_unless_inside_vpcsc
def test_inside_perimeter_allowed(headers):
body = _make_body(bucket_name=vpcsc_config.inside_bucket)
body = _make_body(bucket_name=BUCKET_INSIDE)

response = requests.post(url=API_ENDPOINT_URL, data=body, headers=headers)

operation = response.json
operation = response.json()
op_url = "https://videointelligence.googleapis.com/v1/{}".format(operation["name"])
op_response = requests.get(url=op_url, headers=headers)
# Assert that we do not get an error.
assert op_response.json["name"] == operation["name"]
assert op_response.json()["name"] == operation["name"]

0 comments on commit 9b0fbe6

Please sign in to comment.