Skip to content

Commit

Permalink
Switch to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary authored Oct 7, 2024
1 parent 002c705 commit b3b7054
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions django_tests/test_cloudinaryField.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion django_tests/test_cloudinary_file_field.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 4 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -76,6 +70,7 @@
"certifi"
],
tests_require=[
"mock<4"
"mock<4",
"pytest"
],
)
8 changes: 8 additions & 0 deletions test/helper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import OrderedDict

import six
from mock import patch

from urllib3 import disable_warnings, ProxyManager, PoolManager

import cloudinary
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions test/test_api_authorization.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions test/test_cloudinary_resource.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
4 changes: 1 addition & 3 deletions test/test_config.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions test/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
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

import cloudinary
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()
Expand Down
3 changes: 1 addition & 2 deletions test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions test/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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])
Expand Down
5 changes: 2 additions & 3 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import tempfile
import unittest
import uuid
import json
import time
from collections import OrderedDict
from datetime import datetime, date
from fractions import Fraction
from os.path import getsize

import six
from mock import patch

import cloudinary.utils
from cloudinary import CL_BLANK
Expand All @@ -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,
Expand All @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3b7054

Please sign in to comment.