Skip to content

Commit c5672ee

Browse files
committed
Skip tests if they can't pass due to bad data
1 parent acd7403 commit c5672ee

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

tests/test_paddle.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from paddle import Paddle, PaddleException, __version__
44

55

6+
class BadPaddleDataWarning(UserWarning):
7+
pass
8+
9+
610
@pytest.fixture(scope='session')
711
def paddle_client():
812
paddle = Paddle()

tests/test_plans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_create_plan(paddle_client): # NOQA: F811
7777
assert isinstance(response['product_id'], int)
7878
plan_id = response['product_id']
7979

80-
plan_list = paddle_client.get_plan(plan=plan_id)
80+
plan_list = paddle_client.list_plans(plan=plan_id)
8181
plan = plan_list[0]
8282
assert plan['name'] == plan_name
8383
assert plan['trial_days'] == plan_trial_days

tests/test_subscription_users.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import warnings
12
import contextlib
23
import os
34
from datetime import datetime
45

56
import pytest
67
import requests
78

8-
from .test_paddle import paddle_client # NOQA: F401
9+
from .test_paddle import BadPaddleDataWarning, paddle_client # NOQA: F401
910

1011

1112
def test_list_subscription_users(paddle_client): # NOQA: F811
@@ -34,7 +35,15 @@ def test_list_subscription_users_with_subscription_id(paddle_client): # NOQA: F
3435
response = paddle_client.list_subscription_users(
3536
results_per_page=1
3637
)
37-
first_subscription = response[0]
38+
try:
39+
first_subscription = response[0]
40+
except IndexError:
41+
warning = ('No subscriptions returned by list_subscription_users() in '
42+
'test_list_subscription_users_with_subscription_id')
43+
warnings.warn(warning, BadPaddleDataWarning)
44+
skip_message = ('list_subscription_users did not return any user subscription') # NOQA: E501
45+
pytest.skip(skip_message)
46+
3847
subscription_id = first_subscription['subscription_id']
3948
subscription_users = paddle_client.list_subscription_users(
4049
subscription_id=first_subscription['subscription_id'],
@@ -48,7 +57,14 @@ def test_list_subscription_users_with_plan_id(paddle_client): # NOQA: F811
4857
response = paddle_client.list_subscription_users(
4958
results_per_page=1
5059
)
51-
first_subscription = response[0]
60+
try:
61+
first_subscription = response[0]
62+
except IndexError:
63+
warning = ('No subscriptions returned by list_subscription_users() in '
64+
'test_list_subscription_users_with_plan_id')
65+
warnings.warn(warning, BadPaddleDataWarning)
66+
skip_message = ('list_subscription_users did not return any user subscription') # NOQA: E501
67+
pytest.skip(skip_message)
5268
subscription_users = paddle_client.list_subscription_users(
5369
plan_id=first_subscription['plan_id'],
5470
)
@@ -61,7 +77,14 @@ def test_list_subscription_users_with_state(paddle_client): # NOQA: F811
6177
response = paddle_client.list_subscription_users(
6278
results_per_page=1
6379
)
64-
first_subscription = response[0]
80+
try:
81+
first_subscription = response[0]
82+
except IndexError:
83+
warning = ('No subscriptions returned by list_subscription_users() in '
84+
'test_list_subscription_users_with_state')
85+
warnings.warn(warning, BadPaddleDataWarning)
86+
skip_message = ('list_subscription_users did not return any user subscription') # NOQA: E501
87+
pytest.skip(skip_message)
6588
subscription_users = paddle_client.list_subscription_users(
6689
state=first_subscription['state'],
6790
)
@@ -74,6 +97,12 @@ def test_list_subscription_users_with_page(paddle_client): # NOQA: F811
7497
list_one = paddle_client.list_subscription_users(
7598
results_per_page=1, page=1,
7699
)
100+
if not list_one:
101+
warning = ('No subscriptions returned by list_subscription_users() in '
102+
'test_list_subscription_users_with_page')
103+
warnings.warn(warning, BadPaddleDataWarning)
104+
skip_message = ('list_subscription_users did not return any user subscription') # NOQA: E501
105+
pytest.skip(skip_message)
77106
list_two = paddle_client.list_subscription_users(
78107
results_per_page=1, page=2,
79108
)
@@ -85,6 +114,12 @@ def test_list_subscription_users_with_results_per_page(paddle_client): # NOQA:
85114
list_one = paddle_client.list_subscription_users(
86115
results_per_page=1, page=1,
87116
)
117+
if not list_one:
118+
warning = ('No subscriptions returned by list_subscription_users() in '
119+
'test_list_subscription_users_with_page')
120+
warnings.warn(warning, BadPaddleDataWarning)
121+
skip_message = ('list_subscription_users did not return any user subscription') # NOQA: E501
122+
pytest.skip(skip_message)
88123
assert len(list_one) == 1
89124

90125

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ commands =
3737

3838

3939
[pytest]
40+
markers =
41+
mocked: Tests which do not hit the Paddle API
42+
manual_cleanup: Tests which require manual cleanup in Paddle (deselect with '-m "not manual_cleanup"')
4043
norecursedirs = .git,paddle.egg_info, .mypy_cache
4144
python_files = tests.py test_*.py *_tests.py
4245
addopts =
43-
-v -p no:warnings
46+
-v
4447
--cov=paddle
4548
--cov-report html

0 commit comments

Comments
 (0)