Skip to content

Commit

Permalink
Update tests for gRPC/HTTP support.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Jan 17, 2017
1 parent b518c5f commit 01474cc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
6 changes: 3 additions & 3 deletions system_tests/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _assert_properties(self, image_property):

def test_detect_properties_content(self):
self._pb_not_implemented_skip(
'gRPC not implemented for text detection.')
'gRPC not implemented for image properties detection.')
client = Config.CLIENT
with open(FACE_FILE, 'rb') as image_file:
image = client.image(content=image_file.read())
Expand All @@ -509,7 +509,7 @@ def test_detect_properties_content(self):

def test_detect_properties_gcs(self):
self._pb_not_implemented_skip(
'gRPC not implemented for text detection.')
'gRPC not implemented for image properties detection.')
client = Config.CLIENT
bucket_name = Config.TEST_BUCKET.name
blob_name = 'faces.jpg'
Expand All @@ -528,7 +528,7 @@ def test_detect_properties_gcs(self):

def test_detect_properties_filename(self):
self._pb_not_implemented_skip(
'gRPC not implemented for text detection.')
'gRPC not implemented for image properties detection.')
client = Config.CLIENT
image = client.image(filename=FACE_FILE)
properties = image.detect_properties()
Expand Down
59 changes: 38 additions & 21 deletions vision/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def test_face_annotation(self):
]
}
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

features = [Feature(feature_type=FeatureTypes.FACE_DETECTION,
Expand All @@ -123,8 +124,8 @@ def test_image_with_client_raw_content(self):
from google.cloud.vision.image import Image

credentials = _make_credentials()
client = self._make_one(project=PROJECT,
credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
raw_image = client.image(content=IMAGE_CONTENT)
self.assertIsInstance(raw_image, Image)
self.assertEqual(raw_image.content, IMAGE_CONTENT)
Expand All @@ -135,8 +136,8 @@ def test_image_with_client_filename(self):
from google.cloud.vision.image import Image

credentials = _make_credentials()
client = self._make_one(project=PROJECT,
credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
with patch('google.cloud.vision.image.open',
mock_open(read_data=IMAGE_CONTENT)) as m:
file_image = client.image(filename='my_image.jpg')
Expand All @@ -156,7 +157,8 @@ def test_multiple_detection_from_content(self):
returned['responses'][0]['logoAnnotations'] = logos['logoAnnotations']

credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(returned)

limit = 2
Expand Down Expand Up @@ -203,7 +205,8 @@ def test_face_detection_from_source(self):
from unit_tests._fixtures import FACE_DETECTION_RESPONSE
RETURNED = FACE_DETECTION_RESPONSE
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(source_uri=IMAGE_SOURCE)
Expand All @@ -220,7 +223,8 @@ def test_face_detection_from_content(self):
from unit_tests._fixtures import FACE_DETECTION_RESPONSE
RETURNED = FACE_DETECTION_RESPONSE
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(content=IMAGE_CONTENT)
Expand All @@ -238,7 +242,8 @@ def test_face_detection_from_content_no_results(self):
'responses': [{}]
}
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(content=IMAGE_CONTENT)
Expand All @@ -257,7 +262,8 @@ def test_label_detection_from_source(self):
LABEL_DETECTION_RESPONSE as RETURNED)

credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(source_uri=IMAGE_SOURCE)
Expand All @@ -278,7 +284,8 @@ def test_label_detection_no_results(self):
'responses': [{}]
}
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(content=IMAGE_CONTENT)
Expand All @@ -292,7 +299,8 @@ def test_landmark_detection_from_source(self):
LANDMARK_DETECTION_RESPONSE as RETURNED)

credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(source_uri=IMAGE_SOURCE)
Expand All @@ -314,7 +322,8 @@ def test_landmark_detection_from_content(self):
LANDMARK_DETECTION_RESPONSE as RETURNED)

credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(content=IMAGE_CONTENT)
Expand All @@ -331,7 +340,8 @@ def test_landmark_detection_no_results(self):
'responses': [{}]
}
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(content=IMAGE_CONTENT)
Expand All @@ -344,7 +354,8 @@ def test_logo_detection_from_source(self):
from unit_tests._fixtures import LOGO_DETECTION_RESPONSE
RETURNED = LOGO_DETECTION_RESPONSE
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(source_uri=IMAGE_SOURCE)
Expand All @@ -361,7 +372,8 @@ def test_logo_detection_from_content(self):
from unit_tests._fixtures import LOGO_DETECTION_RESPONSE
RETURNED = LOGO_DETECTION_RESPONSE
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(content=IMAGE_CONTENT)
Expand All @@ -379,7 +391,8 @@ def test_text_detection_from_source(self):
TEXT_DETECTION_RESPONSE as RETURNED)

credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(source_uri=IMAGE_SOURCE)
Expand All @@ -402,7 +415,8 @@ def test_safe_search_detection_from_source(self):

RETURNED = SAFE_SEARCH_DETECTION_RESPONSE
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(source_uri=IMAGE_SOURCE)
Expand All @@ -421,7 +435,8 @@ def test_safe_search_no_results(self):
'responses': [{}]
}
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(content=IMAGE_CONTENT)
Expand All @@ -435,7 +450,8 @@ def test_image_properties_detection_from_source(self):

RETURNED = IMAGE_PROPERTIES_RESPONSE
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(source_uri=IMAGE_SOURCE)
Expand All @@ -457,7 +473,8 @@ def test_image_properties_no_results(self):
'responses': [{}]
}
credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials)
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
client._connection = _Connection(RETURNED)

image = client.image(content=IMAGE_CONTENT)
Expand Down

0 comments on commit 01474cc

Please sign in to comment.