Skip to content

Commit

Permalink
Merge pull request #665 from stripe/richardm-file-create-stripe-version
Browse files Browse the repository at this point in the history
Support stripe.File.create(stripe_version='...')
  • Loading branch information
richardm-stripe authored Jul 13, 2020
2 parents d3835ab + 1b4d81c commit 62f1188
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cache:
env:
global:
# If changing this number, please also change it in `tests/conftest.py`.
- STRIPE_MOCK_VERSION=0.90.0
- STRIPE_MOCK_VERSION=0.93.0

before_install:
# Unpack and start stripe-mock so that the test suite can talk to it
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
VENV_NAME?=venv
PIP?=pip
PYTHON?=python

venv: $(VENV_NAME)/bin/activate

$(VENV_NAME)/bin/activate: setup.py
pip install --upgrade pip virtualenv
@test -d $(VENV_NAME) || python -m virtualenv --clear $(VENV_NAME)
$(PIP) install --upgrade pip virtualenv
@test -d $(VENV_NAME) || $(PYTHON) -m virtualenv --clear $(VENV_NAME)
${VENV_NAME}/bin/python -m pip install -U pip tox
${VENV_NAME}/bin/python -m pip install -e .
@touch $(VENV_NAME)/bin/activate
Expand All @@ -16,7 +18,7 @@ ci: venv
@${VENV_NAME}/bin/python setup.py test -a "-n auto --cov=stripe"

coveralls: venv
@${VENV_NAME}/bin/pip install --upgrade coveralls
@${VENV_NAME}/bin/$(PIP) install --upgrade coveralls
@${VENV_NAME}/bin/coveralls

fmt: venv
Expand Down
13 changes: 10 additions & 3 deletions stripe/api_resources/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ def class_url(cls):

@classmethod
def create(
cls, api_key=None, api_version=None, stripe_account=None, **params
# 'api_version' is deprecated, please use 'stripe_version'
cls,
api_key=None,
api_version=None,
stripe_version=None,
stripe_account=None,
**params
):
version = api_version or stripe_version
requestor = api_requestor.APIRequestor(
api_key,
api_base=stripe.upload_api_base,
api_version=api_version,
api_version=version,
account=stripe_account,
)
url = cls.class_url()
Expand All @@ -35,7 +42,7 @@ def create(
"post", url, params=params, headers=supplied_headers
)
return util.convert_to_stripe_object(
response, api_key, api_version, stripe_account
response, api_key, version, stripe_account
)


Expand Down
4 changes: 2 additions & 2 deletions tests/api_resources/test_account_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class TestAccountLink(object):
def test_is_creatable(self, request_mock):
resource = stripe.AccountLink.create(
account="acct_123",
failure_url="https://stripe.com/failure",
success_url="https://stripe.com/success",
refresh_url="https://stripe.com/failure",
return_url="https://stripe.com/success",
type="custom_account_verification",
)
request_mock.assert_requested("post", "/v1/account_links")
Expand Down
20 changes: 20 additions & 0 deletions tests/api_resources/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ def test_is_creatable(self, setup_upload_api_base, request_mock):
)
assert isinstance(resource, stripe.File)

def test_create_respects_stripe_version(
self, setup_upload_api_base, request_mock
):
test_file = tempfile.TemporaryFile()
stripe.File.create(
purpose="dispute_evidence", file=test_file, stripe_version="foo"
)
request_mock.assert_api_version("foo")

# You can use api_version instead of stripe_version
# in File.create. We preserve it for backwards compatibility
def test_create_respects_api_version(
self, setup_upload_api_base, request_mock
):
test_file = tempfile.TemporaryFile()
stripe.File.create(
purpose="dispute_evidence", file=test_file, api_version="foo"
)
request_mock.assert_api_version("foo")

def test_deserializes_from_file(self):
obj = stripe.util.convert_to_stripe_object({"object": "file"})
assert isinstance(obj, stripe.File)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


# When changing this number, don't forget to change it in `.travis.yml` too.
MOCK_MINIMUM_VERSION = "0.90.0"
MOCK_MINIMUM_VERSION = "0.93.0"

# Starts stripe-mock if an OpenAPI spec override is found in `openapi/`, and
# otherwise fall back to `STRIPE_MOCK_PORT` or 12111.
Expand Down

0 comments on commit 62f1188

Please sign in to comment.