|
10 | 10 | import cloudinary |
11 | 11 | from cloudinary import api, uploader, utils |
12 | 12 | from cloudinary.utils import fq_public_id |
13 | | -from test.helper_test import SUFFIX, TEST_IMAGE, get_uri, get_headers, get_params, get_list_param, get_param, TEST_DOC, get_method, \ |
14 | | - UNIQUE_TAG, api_response_mock, ignore_exception, cleanup_test_resources_by_tag, cleanup_test_transformation, \ |
15 | | - cleanup_test_resources, UNIQUE_TEST_FOLDER, EVAL_STR, get_json_body |
| 13 | +from test.helper_test import SUFFIX, TEST_IMAGE, get_uri, get_headers, get_params, get_list_param, get_param, \ |
| 14 | + TEST_DOC, get_method, UNIQUE_TAG, api_response_mock, ignore_exception, cleanup_test_resources_by_tag, \ |
| 15 | + cleanup_test_transformation, cleanup_test_resources, UNIQUE_TEST_FOLDER, EVAL_STR, get_json_body, REMOTE_TEST_IMAGE |
16 | 16 | from cloudinary.exceptions import BadRequest, NotFound |
17 | 17 |
|
18 | 18 | MOCK_RESPONSE = api_response_mock() |
@@ -284,6 +284,22 @@ def test06b_resources_direction(self, mocker): |
284 | 284 | self.assertTrue(get_uri(args).endswith('/resources/image/tags/{}'.format(API_TEST_TAG))) |
285 | 285 | self.assertEqual(get_params(args)['direction'], 'desc') |
286 | 286 |
|
| 287 | + @patch('urllib3.request.RequestMethods.request') |
| 288 | + @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret") |
| 289 | + def test_visual_search(self, mocker): |
| 290 | + """ should allow using visual search """ |
| 291 | + mocker.return_value = MOCK_RESPONSE |
| 292 | + |
| 293 | + api.visual_search(REMOTE_TEST_IMAGE, API_TEST_ASSET_ID, "sample image") |
| 294 | + |
| 295 | + args, kwargs = mocker.call_args |
| 296 | + self.assertTrue(get_uri(args).endswith('/resources/visual_search')) |
| 297 | + |
| 298 | + params = get_params(args) |
| 299 | + self.assertEqual(REMOTE_TEST_IMAGE, params['image_url']) |
| 300 | + self.assertEqual(API_TEST_ASSET_ID, params['image_asset_id']) |
| 301 | + self.assertEqual("sample image", params['text']) |
| 302 | + |
287 | 303 | @patch('urllib3.request.RequestMethods.request') |
288 | 304 | @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret") |
289 | 305 | def test_extra_headers(self, mocker): |
|
0 commit comments