Skip to content

Commit 0e661ea

Browse files
Add unit tests
1 parent 77560d8 commit 0e661ea

39 files changed

+630
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ venv
99
.vscode
1010
.idea
1111

12+
.cld-sync

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: python
2+
dist: focal
3+
matrix:
4+
include:
5+
- python: 3.6
6+
env: TOXENV=py36-core
7+
- python: 3.7
8+
env: TOXENV=py37-core
9+
- python: 3.8
10+
env: TOXENV=py38-core
11+
- python: 3.9
12+
env: TOXENV=py39-core
13+
install:
14+
- pip install tox
15+
16+
before_script: >
17+
export CLOUDINARY_URL=$(bash tools/get_test_cloud.sh);
18+
echo cloud_name: "$(echo $CLOUDINARY_URL | cut -d'@' -f2)"
19+
script:
20+
- tox -e $TOXENV
21+
22+
notifications:
23+
email:
24+
recipients:
25+

cloudinary_cli/core/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def config(new, ls, show, rm, from_url):
2121
config_name, cloudinary_url = new or [None, from_url]
2222

2323
if not verify_cloudinary_url(cloudinary_url):
24-
return
24+
return 1
2525

2626
config_name = config_name or cloudinary.config().cloud_name
2727

@@ -31,7 +31,7 @@ def config(new, ls, show, rm, from_url):
3131
logger.info("Example usage: cld -C {} <command>".format(config_name))
3232
elif rm:
3333
if remove_config_keys(rm):
34-
logger.warn(f"Configuration '{rm}' not found.")
34+
logger.warning(f"Configuration '{rm}' not found.")
3535
else:
3636
logger.info(f"Configuration '{rm}' deleted.")
3737
elif ls:

cloudinary_cli/samples/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def dog(transformation, open_in_browser):
2828

2929
def _handle_sample_command(source, transformation=None, open_in_browser=False, resource_type="image"):
3030
cloudinary.config(cloud_name="demo", secure_distribution=None, cname=None)
31-
res = cloudinary_url(source, raw_transformation=transformation, resource_type=resource_type)[0]
31+
res = cloudinary_url(source, raw_transformation=transformation, resource_type=resource_type)
3232
print(res)
3333
if open_in_browser:
3434
open_url(res)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'console_scripts': [
2424
'cld=cloudinary_cli.cli:main',
2525
'cloudinary=cloudinary_cli.cli:main',
26-
],
26+
],
2727
},
2828
long_description=long_description,
2929
long_description_content_type="text/markdown",
@@ -34,7 +34,7 @@
3434
license="MIT",
3535
python_requires='>=3.6.0',
3636
setup_requires=["pytest-runner"],
37-
tests_require=["pytest"],
37+
tests_require=["pytest", "mock", "urllib3"],
3838
install_requires=[
3939
"cloudinary>=1.25.0",
4040
"pygments",

test/helper_test.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import os
2+
import random
3+
import time
4+
from functools import wraps
5+
from pathlib import Path
6+
7+
import cloudinary.api
8+
from cloudinary import logger
9+
from urllib3 import HTTPResponse, disable_warnings
10+
from urllib3._collections import HTTPHeaderDict
11+
12+
SUFFIX = os.environ.get('TRAVIS_JOB_ID') or random.randint(10000, 99999)
13+
14+
RESOURCES_DIR = Path.joinpath(Path(__file__).resolve().parent, "resources")
15+
TEST_FILES_DIR = str(Path.joinpath(RESOURCES_DIR, "test_sync"))
16+
17+
disable_warnings()
18+
19+
20+
def unique_suffix(value):
21+
return f"{value}_{SUFFIX}"
22+
23+
24+
def http_response_mock(body="", headers=None, status=200):
25+
if headers is None:
26+
headers = {}
27+
28+
body = body.encode("UTF-8")
29+
30+
return HTTPResponse(body, HTTPHeaderDict(headers), status=status)
31+
32+
33+
def api_response_mock():
34+
return http_response_mock('{"foo":"bar"}', {"x-featureratelimit-limit": '0',
35+
"x-featureratelimit-reset": 'Sat, 01 Apr 2017 22:00:00 GMT',
36+
"x-featureratelimit-remaining": '0'})
37+
38+
39+
def uploader_response_mock():
40+
return http_response_mock('{"foo":"bar"}')
41+
42+
43+
def retry_assertion(num_tries=3, delay=3):
44+
"""
45+
Helper for retrying inconsistent unit tests
46+
47+
:param num_tries: Number of tries to perform
48+
:param delay: Delay in seconds between retries
49+
"""
50+
51+
def retry_decorator(func):
52+
@wraps(func)
53+
def retry_func(*args, **kwargs):
54+
try_num = 1
55+
while try_num < num_tries:
56+
try:
57+
return func(*args, **kwargs)
58+
except AssertionError:
59+
logger.warning("Assertion #{} out of {} failed, retrying in {} seconds".format(try_num, num_tries,
60+
delay))
61+
time.sleep(delay)
62+
try_num += 1
63+
64+
return func(*args, **kwargs)
65+
66+
return retry_func
67+
68+
return retry_decorator
69+
70+
71+
def delete_cld_folder_if_exists(folder):
72+
cloudinary.api.delete_resources_by_prefix(folder)
73+
try:
74+
cloudinary.api.delete_folder(folder)
75+
except cloudinary.exceptions.NotFound:
76+
pass

test/test_resources/test_file_utils/.hidden_d2/.hidden_f2 renamed to test/resources/test_file_utils/.hidden_d2/.hidden_f2

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)