diff --git a/.travis.yml b/.travis.yml index abc300c0..abde8122 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ matrix: - python: 3.11 env: TOXENV=py311-django41 install: -- pip install tox +- pip install tox pytest before_script: > export CLOUDINARY_URL=$(bash tools/get_test_cloud.sh); diff --git a/django_tests/test_cloudinaryField.py b/django_tests/test_cloudinaryField.py index 11b95c95..32483016 100644 --- a/django_tests/test_cloudinaryField.py +++ b/django_tests/test_cloudinaryField.py @@ -1,7 +1,7 @@ import os import unittest -from mock import mock +from test.helper_test import mock from urllib3.util import parse_url import cloudinary @@ -77,7 +77,7 @@ def get_image_name(instance): c.pre_save(poll, None) self.assertTrue(upload_mock.called) - self.assertEqual(upload_mock.call_args.kwargs['public_id'], 'question') + self.assertEqual(upload_mock.call_args[1]['public_id'], 'question') def test_pre_save(self): c = CloudinaryField('image', width_field="image_width", height_field="image_height") diff --git a/django_tests/test_cloudinary_file_field.py b/django_tests/test_cloudinary_file_field.py index 2533ac81..9303c045 100644 --- a/django_tests/test_cloudinary_file_field.py +++ b/django_tests/test_cloudinary_file_field.py @@ -1,6 +1,6 @@ from django.core.files.uploadedfile import SimpleUploadedFile from django.test import TestCase -from mock import mock +from test.helper_test import mock import cloudinary from cloudinary import CloudinaryResource diff --git a/pyproject.toml b/pyproject.toml index 12a12b0a..af3a2b81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,9 @@ dependencies = [ [project.optional-dependencies] dev = [ - "tox" + "tox", + "pytest==4.6; python_version < '3.7'", + "pytest; python_version >= '3.7'" ] [project.urls] diff --git a/setup.py b/setup.py index ca10aa4e..8fc932c9 100644 --- a/setup.py +++ b/setup.py @@ -3,15 +3,9 @@ from setuptools import find_packages, setup if version_info[0] >= 3: - - setup(test_suite="test", - tests_require=[ - "mock" + ("<4" if version_info < (3, 6) else "") - ], - ) - + setup() else: - # Following code is legacy (Python 2.7 compatibiltiy) and will be removed in the future! + # Following code is legacy (Python 2.7 compatibility) and will be removed in the future! # TODO: Remove in next major update (when dropping Python 2.7 compatibility) version = "1.41.0" @@ -76,6 +70,7 @@ "certifi" ], tests_require=[ - "mock<4" + "mock<4", + "pytest" ], ) diff --git a/test/helper_test.py b/test/helper_test.py index d8d721c7..d90155ea 100644 --- a/test/helper_test.py +++ b/test/helper_test.py @@ -18,6 +18,14 @@ from cloudinary.exceptions import NotFound from test.addon_types import ADDON_ALL +try: + from unittest import mock +except ImportError: + # Python 2.7 + import mock + +patch = mock.patch + SUFFIX = os.environ.get('TRAVIS_JOB_ID') or random.randint(10000, 99999) REMOTE_TEST_IMAGE = "http://cloudinary.com/images/old_logo.png" diff --git a/test/test_api.py b/test/test_api.py index 418b1561..c93b07d1 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -4,7 +4,7 @@ from collections import OrderedDict import six -from mock import patch + from urllib3 import disable_warnings, ProxyManager, PoolManager import cloudinary @@ -13,7 +13,7 @@ from test.helper_test import SUFFIX, TEST_IMAGE, get_uri, get_headers, get_params, get_list_param, get_param, \ TEST_DOC, get_method, UNIQUE_TAG, api_response_mock, ignore_exception, cleanup_test_resources_by_tag, \ cleanup_test_transformation, cleanup_test_resources, UNIQUE_TEST_FOLDER, EVAL_STR, get_json_body, REMOTE_TEST_IMAGE, \ - TEST_IMAGE_SIZE, URLLIB3_REQUEST + TEST_IMAGE_SIZE, URLLIB3_REQUEST, patch from cloudinary.exceptions import BadRequest, NotFound MOCK_RESPONSE = api_response_mock() diff --git a/test/test_api_authorization.py b/test/test_api_authorization.py index 6bd1603c..982d6544 100644 --- a/test/test_api_authorization.py +++ b/test/test_api_authorization.py @@ -1,12 +1,11 @@ import unittest import six -from mock import patch import cloudinary from cloudinary import api from cloudinary import uploader -from test.helper_test import TEST_IMAGE, get_headers, get_params, URLLIB3_REQUEST +from test.helper_test import TEST_IMAGE, get_headers, get_params, URLLIB3_REQUEST, patch from test.test_api import MOCK_RESPONSE from test.test_config import OAUTH_TOKEN, CLOUD_NAME, API_KEY, API_SECRET from test.test_uploader import API_TEST_PRESET diff --git a/test/test_archive.py b/test/test_archive.py index 87225c9c..acc62dce 100644 --- a/test/test_archive.py +++ b/test/test_archive.py @@ -9,13 +9,12 @@ import cloudinary.poster.streaminghttp from cloudinary import uploader, utils -from mock import patch import six import urllib3 from urllib3 import disable_warnings from test.helper_test import SUFFIX, TEST_IMAGE, api_response_mock, cleanup_test_resources_by_tag, UNIQUE_TEST_ID, \ - get_uri, get_list_param, get_params, URLLIB3_REQUEST + get_uri, get_list_param, get_params, URLLIB3_REQUEST, patch MOCK_RESPONSE = api_response_mock() diff --git a/test/test_cloudinary_resource.py b/test/test_cloudinary_resource.py index 6086d435..9c94abe9 100644 --- a/test/test_cloudinary_resource.py +++ b/test/test_cloudinary_resource.py @@ -1,13 +1,12 @@ from unittest import TestCase -import mock from urllib3 import disable_warnings import cloudinary from cloudinary import CloudinaryResource from cloudinary import uploader from test.helper_test import SUFFIX, TEST_IMAGE, http_response_mock, get_uri, cleanup_test_resources_by_tag, \ - URLLIB3_REQUEST + URLLIB3_REQUEST, mock disable_warnings() diff --git a/test/test_config.py b/test/test_config.py index 6a5db7ec..21cd23cd 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -1,11 +1,9 @@ import os from unittest import TestCase -from mock import mock - import cloudinary from cloudinary.provisioning import account_config - +from test.helper_test import mock CLOUD_NAME = 'test123' API_KEY = 'key' diff --git a/test/test_image.py b/test/test_image.py index 3b8ca0fe..904b7964 100644 --- a/test/test_image.py +++ b/test/test_image.py @@ -6,10 +6,10 @@ from collections import OrderedDict import six -from mock import mock import cloudinary from cloudinary import CloudinaryImage +from test.helper_test import mock class ImageTest(unittest.TestCase): diff --git a/test/test_metadata.py b/test/test_metadata.py index 5f4a6633..4e275262 100644 --- a/test/test_metadata.py +++ b/test/test_metadata.py @@ -1,9 +1,7 @@ -import json import time import unittest from datetime import datetime, timedelta -from mock import patch from six import text_type from urllib3 import disable_warnings @@ -11,7 +9,8 @@ from cloudinary import api from cloudinary.exceptions import BadRequest, NotFound from test.helper_test import ( - UNIQUE_TEST_ID, get_uri, get_params, get_method, api_response_mock, ignore_exception, get_json_body, URLLIB3_REQUEST + UNIQUE_TEST_ID, get_uri, get_params, get_method, api_response_mock, ignore_exception, get_json_body, + URLLIB3_REQUEST, patch ) MOCK_RESPONSE = api_response_mock() diff --git a/test/test_search.py b/test/test_search.py index bdb927d1..32a313a4 100644 --- a/test/test_search.py +++ b/test/test_search.py @@ -3,14 +3,13 @@ import time import unittest -from mock.mock import patch from six import iterkeys from urllib3 import disable_warnings import cloudinary from cloudinary import uploader, SearchFolders, Search from test.helper_test import SUFFIX, TEST_IMAGE, TEST_TAG, UNIQUE_TAG, TEST_FOLDER, UNIQUE_TEST_FOLDER, \ - retry_assertion, cleanup_test_resources_by_tag, URLLIB3_REQUEST, get_json_body, get_uri + retry_assertion, cleanup_test_resources_by_tag, URLLIB3_REQUEST, get_json_body, get_uri, patch from test.test_api import MOCK_RESPONSE, NEXT_CURSOR from test.test_config import CLOUD_NAME, API_KEY, API_SECRET diff --git a/test/test_uploader.py b/test/test_uploader.py index 1469d4a3..90a71897 100644 --- a/test/test_uploader.py +++ b/test/test_uploader.py @@ -6,9 +6,7 @@ from datetime import datetime import six -from mock import patch from urllib3 import disable_warnings -from urllib3.util import parse_url import cloudinary from cloudinary import api, uploader, utils, exceptions @@ -19,7 +17,7 @@ from test.helper_test import uploader_response_mock, SUFFIX, TEST_IMAGE, get_params, get_headers, TEST_ICON, TEST_DOC, \ REMOTE_TEST_IMAGE, UTC, populate_large_file, TEST_UNICODE_IMAGE, get_uri, get_method, get_param, \ cleanup_test_resources_by_tag, cleanup_test_transformation, cleanup_test_resources, EVAL_STR, ON_SUCCESS_STR, \ - URLLIB3_REQUEST + URLLIB3_REQUEST, patch, retry_assertion from test.test_utils import TEST_ID, TEST_FOLDER MOCK_RESPONSE = uploader_response_mock() @@ -620,6 +618,7 @@ def test_tags(self): uploader.replace_tag(UNIQUE_TAG, result["public_id"]) @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret") + @retry_assertion() def test_multiple_tags(self): """ Should support adding multiple tags: list ["tag1","tag2"] and comma-separated "tag1,tag2" """ result = uploader.upload(TEST_IMAGE, tags=[UNIQUE_TAG]) diff --git a/test/test_utils.py b/test/test_utils.py index 316084ef..0fd596bb 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -4,7 +4,6 @@ import tempfile import unittest import uuid -import json import time from collections import OrderedDict from datetime import datetime, date @@ -12,7 +11,6 @@ from os.path import getsize import six -from mock import patch import cloudinary.utils from cloudinary import CL_BLANK @@ -32,7 +30,7 @@ verify_api_response_signature, ) from cloudinary.compat import to_bytes -from test.helper_test import TEST_IMAGE, REMOTE_TEST_IMAGE +from test.helper_test import TEST_IMAGE, REMOTE_TEST_IMAGE, patch from test.test_api import ( API_TEST_TRANS_SCALE100, API_TEST_TRANS_SCALE100_STR, @@ -58,6 +56,7 @@ MOCKED_NOW = 1549533574 API_SECRET = 'X7qLTrsES31MzxxkxPPA-pAGGfU' + class TestUtils(unittest.TestCase): crop_transformation = {'crop': 'crop', 'width': 100} crop_transformation_str = 'c_crop,w_100' diff --git a/tox.ini b/tox.ini index 14404d1a..14ab54d4 100644 --- a/tox.ini +++ b/tox.ini @@ -6,12 +6,13 @@ envlist = [testenv] usedevelop = True commands = - core: python setup.py test {env:P_ARGS:} + core: python -m pytest test django{111,22,32}: django-admin.py test -v2 django_tests {env:D_ARGS:} django{40,41}: django-admin test -v2 django_tests {env:D_ARGS:} passenv = * deps = - django{111,22,32,40,41}: mock + pytest + py27: mock django111: Django>=1.11,<1.12 django22: Django>=2.2,<2.3 django32: Django>=3.2,<3.3