def test_train(self): endpoint = '/v4/collections/{0}/train'.format('collection_id') url = '{0}{1}'.format(base_url, endpoint) response = { "collection_id": "collection_id", "training_status": { "objects": { "in_progress": "true", "data_changed": "true", "ready": "true", "latest_failed": "true", "description": "description" } }, "created": "2000-01-23T04:56:07.000+00:00", "name": "name", "description": "description", "image_count": 0, "updated": "2000-01-23T04:56:07.000+00:00" } responses.add(responses.POST, url, body=json.dumps(response), status=202, content_type='application/json') authenticator = IAMAuthenticator('bogusapikey') service = ibm_watson.VisualRecognitionV4('YYYY-MM-DD', authenticator=authenticator) service.set_service_url(base_url) detailed_response = service.train(collection_id='collection_id') result = detailed_response.get_result() assert result is not None assert len(responses.calls) == 2
def test_list_images(self): endpoint = '/v4/collections/{0}/images'.format('collection_id') url = '{0}{1}'.format(base_url, endpoint) response = { "images": [{ "image_id": "image_id", "updated": "2000-01-23T04:56:07.000+00:00" }, { "image_id": "image_id", "updated": "2000-01-23T04:56:07.000+00:00" }] } responses.add(responses.GET, url, body=json.dumps(response), status=200, content_type='application/json') authenticator = IAMAuthenticator('bogusapikey') service = ibm_watson.VisualRecognitionV4('YYYY-MM-DD', authenticator=authenticator) service.set_service_url(base_url) detailed_response = service.list_images(collection_id='collection_id') result = detailed_response.get_result() assert result is not None assert len(responses.calls) == 2
def setup_class(cls): cls.visual_recognition = ibm_watson.VisualRecognitionV4('2019-02-11') cls.visual_recognition.set_default_headers({ 'X-Watson-Learning-Opt-Out': '1', 'X-Watson-Test': '1' })
def setup_class(cls): cls.visual_recognition = ibm_watson.VisualRecognitionV4('2019-02-11') cls.visual_recognition.set_default_headers({ 'X-Watson-Learning-Opt-Out': '1', 'X-Watson-Test': '1' }) cls.collection_id = '9e5d8394-e9d2-4b53-b88f-da6fce7ad4e3'
def test_delete_user_data(self): endpoint = '/v4/user_data' url = '{0}{1}'.format(base_url, endpoint) response = {} responses.add(responses.DELETE, url, body=json.dumps(response), status=202, content_type='') authenticator = IAMAuthenticator('bogusapikey') service = ibm_watson.VisualRecognitionV4('YYYY-MM-DD', authenticator=authenticator) service.set_service_url(base_url) detailed_response = service.delete_user_data(customer_id='customer_id') result = detailed_response.get_result() assert result is not None assert len(responses.calls) == 2
def test_get_jpeg_image(self): endpoint = '/v4/collections/{0}/images/{1}/jpeg'.format( 'collection_id', 'image_id').format('image_id') url = '{0}{1}'.format(base_url, endpoint) response = {} responses.add(responses.GET, url, body=json.dumps(response), status=200, content_type='') authenticator = IAMAuthenticator('bogusapikey') service = ibm_watson.VisualRecognitionV4('YYYY-MM-DD', authenticator=authenticator) service.set_service_url(base_url) detailed_response = service.get_jpeg_image( collection_id='collection_id', image_id='image_id', size='size') result = detailed_response.get_result() assert result is not None assert len(responses.calls) == 2
def test_add_image_training_data(self): endpoint = '/v4/collections/{0}/images/{1}/training_data'.format( 'collection_id', 'image_id') url = '{0}{1}'.format(base_url, endpoint) response = { "objects": [{ "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }, { "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }] } responses.add(responses.POST, url, body=json.dumps(response), status=200, content_type='application/json') authenticator = IAMAuthenticator('bogusapikey') service = ibm_watson.VisualRecognitionV4('YYYY-MM-DD', authenticator=authenticator) service.set_service_url(base_url) detailed_response = service.add_image_training_data( collection_id='collection_id', image_id='image_id') result = detailed_response.get_result() assert result is not None assert len(responses.calls) == 2
def test_analyze(self): endpoint = '/v4/analyze' url = '{0}{1}'.format(base_url, endpoint) response = { "images": [{ "objects": { "collections": [{ "collection_id": "collection_id", "objects": [{ "score": 7.0614014, "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }, { "score": 7.0614014, "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }] }, { "collection_id": "collection_id", "objects": [{ "score": 7.0614014, "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }, { "score": 7.0614014, "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }] }] }, "source": { "archive_filename": "archive_filename", "filename": "filename", "type": "file", "resolved_url": "resolved_url", "source_url": "source_url" }, "errors": { "code": "invalid_field", "message": "The date provided for `version` is not valid. Specify dates in `YYYY-MM-DD` format.", "more_info": "https://cloud.ibm.com/apidocs/visual-recognition-v4#versioning", "target": { "type": "parameter", "name": "version" } }, "dimensions": { "width": 6, "height": 0 } }, { "objects": { "collections": [{ "collection_id": "collection_id", "objects": [{ "score": 7.0614014, "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }, { "score": 7.0614014, "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }] }, { "collection_id": "collection_id", "objects": [{ "score": 7.0614014, "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }, { "score": 7.0614014, "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }] }] }, "source": { "archive_filename": "archive_filename", "filename": "filename", "type": "file", "resolved_url": "resolved_url", "source_url": "source_url" }, "errors": { "code": "invalid_field", "message": "The date provided for `version` is not valid. Specify dates in `YYYY-MM-DD` format.", "more_info": "https://cloud.ibm.com/apidocs/visual-recognition-v4#versioning", "target": { "type": "parameter", "name": "version" } }, "dimensions": { "width": 6, "height": 0 } }], "trace": "trace", "warnings": [{ "code": "invalid_field", "more_info": "more_info", "message": "message" }, { "code": "invalid_field", "more_info": "more_info", "message": "message" }] } responses.add(responses.POST, url, body=json.dumps(response), status=200, content_type='application/json') authenticator = IAMAuthenticator('bogusapikey') service = ibm_watson.VisualRecognitionV4('YYYY-MM-DD', authenticator=authenticator) service.set_service_url(base_url) with open( os.path.join(os.path.dirname(__file__), '../../resources/cars.zip'), 'rb') as cars: detailed_response = service.analyze( collection_ids=['collection_id1, collection_id2'], features=[AnalyzeEnums.Features.OBJECTS.value], images_file=[FileWithMetadata(cars)], image_url=[ 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/American_Eskimo_Dog.jpg/1280px-American_Eskimo_Dog.jpg' ], threshold='0.2') result = detailed_response.get_result() assert result is not None assert len(responses.calls) == 2
def test_get_image_details(self): endpoint = '/v4/collections/{0}/images/{1}'.format( 'collection_id', 'image_id').format('image_id') url = '{0}{1}'.format(base_url, endpoint) response = { "training_data": { "objects": [{ "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }, { "location": { "top": 1, "left": 5, "width": 5, "height": 2 }, "object": "object" }] }, "created": "2000-01-23T04:56:07.000+00:00", "source": { "archive_filename": "archive_filename", "filename": "filename", "type": "file", "resolved_url": "resolved_url", "source_url": "source_url" }, "image_id": "image_id", "updated": "2000-01-23T04:56:07.000+00:00", "errors": { "code": "invalid_field", "message": "The date provided for `version` is not valid. Specify dates in `YYYY-MM-DD` format.", "more_info": "https://cloud.ibm.com/apidocs/visual-recognition-v4#versioning", "target": { "type": "parameter", "name": "version" } }, "dimensions": { "width": 6, "height": 0 } } responses.add(responses.GET, url, body=json.dumps(response), status=200, content_type='application/json') authenticator = IAMAuthenticator('bogusapikey') service = ibm_watson.VisualRecognitionV4('YYYY-MM-DD', authenticator=authenticator) service.set_service_url(base_url) detailed_response = service.get_image_details( collection_id='collection_id', image_id='image_id') result = detailed_response.get_result() assert result is not None assert len(responses.calls) == 2