Skip to content

Commit

Permalink
Fixing problem with invalid dates for subscription events (#77)
Browse files Browse the repository at this point in the history
* Fixing problem with invalid dates for subscription events

* String --> DateTime. Update unit tests to match expected results. Add VCR. Downgrade to specific VCR package version

* Remove BIN file

* Don't break test CI for forks (#78)

* Try continue-on-error

* Fixate urllib3

* Remove the debug exit

* Fixing inting errors

* Bump vcrpy package version to test if we resolve CI error: module 'collections' has no attribute 'MutableMapping'

* List vcrpy version in requirements.txt to try and resolve CI error: module 'collections' has no attribute 'MutableMapping'

* vcrpy version

* urllib3 version

---------

Co-authored-by: polis80cy <[email protected]>
Co-authored-by: Petr Kopac <[email protected]>
  • Loading branch information
3 people authored May 23, 2023
1 parent bb9658e commit 8514ba4
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 40 deletions.
4 changes: 2 additions & 2 deletions chartmogul/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
Provides convenient Python bindings for ChartMogul's API.
:copyright: (c) 2019 by ChartMogul Ltd.
:copyright: (c) 2023 by ChartMogul Ltd.
:license: MIT, see LICENSE for more details.
"""

__title__ = 'chartmogul'
__build__ = 0x000000
__author__ = 'ChartMogul Ltd'
__license__ = 'MIT'
__copyright__ = 'Copyright 2021 ChartMogul Ltd'
__copyright__ = 'Copyright 2023 ChartMogul Ltd'
6 changes: 3 additions & 3 deletions chartmogul/api/subscription_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class SubscriptionEvent(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#subscription_events
https://dev.chartmogul.com/reference/subscription-events
"""
_path = "/subscription_events"
_root_key = 'subscription_events'
Expand All @@ -16,8 +16,8 @@ class _Schema(Schema):
data_source_uuid = fields.String(required=True)
customer_external_id = fields.String(required=True)
event_type = fields.String(required=True)
event_date = fields.Date(required=True)
effective_date = fields.Date(required=True)
event_date = fields.DateTime(required=True)
effective_date = fields.DateTime(required=True)
subscription_external_id = fields.String(allow_none=True)
plan_external_id = fields.String(allow_none=True)
currency = fields.String(allow_none=True)
Expand Down
2 changes: 1 addition & 1 deletion chartmogul/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.1.1'
__version__ = '3.1.2'
78 changes: 78 additions & 0 deletions fixtures/fetch_subscription_events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- chartmogul-python/3.1.2
content-type:
- application/json
method: GET
uri: https://api.chartmogul.com/v1/subscription_events
response:
body:
string: !!binary |
H4sIAAAAAAAAA+2bXZOiOBSG/wvX7VS+P/wdfbVbUxRCUEGQhmDrdPV/3xC2dtepHRkJAbvKKm+U
Qzwkj29OXpOPoGk3TVzvK70/lqE6qVI3wfrPj2CfBGtMuUQCE/QSJJGOwubY1rEK27a7GCRNKDFM
oYzQKuZJuoJQJauNgnKVbjiPUkaTKJHBSxC3jT4Wqg7VWau6jA6hbYBDCTg0169yaJS+jivbw+Gn
mOt2ENn94Ni0Ux0i8wz//Y7+XvtYoXkEZdJGAOEVoCvIXwFbI7BG/A9zr0pTFev9Sf0cB/ArAGv7
snFdF4X6UnVtXSUeR2WsDgeVdK39TxJ1faxN3358mg6plUkmCSP964Taqkv4dsxbG5V6ry/Bun/Q
uK1rVcb/vI+KY2uy3Zdh3A9sH6ajc/iLS7XSdRR339t3WjdQ3U2fL9dIQD9IQMEA64byqmfvRyLP
i0bwJxLdb28uJIAfJBCkEDB3JLIs3V2a8UiwR1MJm9CAStiYxVQCSz9IECoRBRMgQTWrd96QQLNP
HF8ACeEHCSgQ7/Tecd7Y/mDYRSTobZGYnwib0IBI2JjlRIL7IYIhTlBXfboiEVfbs0N1+USiW1H0
hedvVpeY+UGCI8anmDc4T6pdNX7eII+mEjahAZWwMcupBPWDBKPUCIW7SuzqgorMGxLzr0G/ABLE
DxIQE47ciSCIxuVlPBH4tkjMT4RNaEAkbMxyIoH9EMEwR3gCV4LSfBN39tBIo+qJxP2lBPKEBAFi
CiSy8j19I+ORQI+mEjahAZWwMcuphCfvEhufindD6bjgIO8sSRxKiScS96uEJ++SAmjcS3ckUiYY
EuNVAj6aStiEBlTCxiymEsiTUcUwIXgCJHBxZmeHWmIAifmdqi+AhCdbgmEq4QROVYbzt62DSoDb
KjE/EjahAZWwMcuphCdbAgsMYDeUjrVE9l7k0sGpeiJxdy2BPNkS2FhVeILyMs0zWejRtQSUD6YS
fUK3VaKPWU4lPPkSxGzOYRMgIZDcvT+RMLuMZtstgZAfX4JALsQEuyVEqk+X8RMHFE+VuPdfL+TJ
l6AcCzGFSmRbpLt2xrmXQ0jMbmj3CQ1MHJbj5SYOj76EnOI/jktRoicSc04c0JMvATGXdIIVx1an
cZqNV4lH24wLbUIDKmFjFlMJ6GkHDSGSsAmQwLu3bONQSzyRuHsRCj2tOIyhjRkwv25HXyLfpCfq
oBKPthkX/sbOyz5mOZXwteKQUoAJ3Euc0wt2WIQOIDG7e/mQSHx/CQqlI3MKJSjNGZUwV+asyN/H
fKABpKrVqf+w37C3UemxVv0n/56cka8QralYQ/oNY2sRVtHWnIcxCxh91OZ4T/fWLH8I4p+ffwGd
9Me3YzQAAA==
headers:
Access-Control-Allow-Credentials:
- 'true'
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Length:
- '1033'
Content-Type:
- application/json; charset=utf-8
Date:
- Fri, 19 May 2023 12:58:15 GMT
ETag:
- W/"81eb5df6ece395240b6951a8223b5f5d"
Referrer-Policy:
- strict-origin-when-cross-origin
Vary:
- Accept-Encoding
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- DENY
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- 7ac6e671676b1fe526cf0c67d988f7b1
X-Runtime:
- '0.128295'
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
yarl
mock>=1.0.1
requests-mock>=1.3.0
vcrpy>=1.11.1
vcrpy<3.0.0
PyYAML>=5.1.2
httpretty>=0.9.6
wrapt>=1.11.2
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ promise>=1.0.1
marshmallow>=3.10.0
future>=0.18.3
urllib3<2.0
vcrpy<=4.0.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'promise>=1.0.1',
'marshmallow>=3.10.0',
'future>=0.18.3',
'urllib3<2.0'
]
test_requirements = [
# This is needed to circumvent a vcrpy dependency problem And can be
Expand All @@ -28,7 +29,7 @@

'mock>=1.0.1',
'requests-mock>=1.3.0',
'vcrpy>=1.11.1',
'vcrpy<3.0.0',
'PyYAML>=5.1.2',
'httpretty>=0.9.6',
'wrapt>=1.11.2'
Expand Down
16 changes: 8 additions & 8 deletions test/api/test_subscription_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"customer_external_id": "scus_022",
"data_source_uuid": "ds_1fm3eaac-62d0-31ec-clf4-4bf0mbe81aba",
"event_type": "subscription_start_scheduled",
"event_date": "2022-03-30",
"effective_date": "2022-04-01",
"event_date": "2022-03-30 23:00:00.000",
"effective_date": "2022-04-01 23:00:00.000",
"subscription_external_id": "sub_0001",
"plan_external_id": "gol d_monthly",
"currency": "USD",
Expand All @@ -31,8 +31,8 @@
"customer_external_id": "scus_022",
"data_source_uuid": "ds_1fm3eaac-62d0-31ec-clf4-4bf0mbe81aba",
"event_type": "subscription_start_scheduled",
"event_date": "2022-03-30",
"effective_date": "2022-04-01",
"event_date": "2022-03-30 23:00:00.000",
"effective_date": "2022-04-01 23:00:00.000",
"subscription_external_id": "sub_0001",
"plan_external_id": "gol d_monthly",
"currency": "USD",
Expand All @@ -54,8 +54,8 @@
customer_external_id="scus_022",
data_source_uuid="ds_1fm3eaac-62d0-31ec-clf4-4bf0mbe81aba",
event_type="subscription_start_scheduled",
event_date="2022-03-30",
effective_date="2022-04-01",
event_date="2022-03-30 23:00:00.000",
effective_date="2022-04-01 23:00:00.000",
subscription_external_id="sub_0001",
plan_external_id="gol d_monthly",
currency="USD",
Expand All @@ -71,8 +71,8 @@ def test_create_subscription_event(self, mock_requests):
"customer_external_id": "scus_022",
"data_source_uuid": "ds_1fm3eaac-62d0-31ec-clf4-4bf0mbe81aba",
"event_type": "subscription_start_scheduled",
"event_date": "2022-03-30",
"effective_date": "2022-04-01",
"event_date": "2022-03-30 23:00:00.000",
"effective_date": "2022-04-01 23:00:00.000",
"subscription_external_id": "sub_0001",
"plan_external_id": "gold_monthly",
"currency": "USD",
Expand Down
34 changes: 34 additions & 0 deletions test/integration/fixtures/delete_invoice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
interactions:
- request:
body: '{}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '2'
User-Agent:
- chartmogul-python/3.1.1
content-type:
- application/json
method: POST
uri: https://api.chartmogul.com/v1/data_sources
response:
body:
string: '{"code":400,"message":"Parameter \"name\" is missing","param":"name"}'
headers:
Connection:
- keep-alive
Content-Length:
- '69'
Content-Type:
- application/json
Date:
- Fri, 19 May 2023 09:41:27 GMT
status:
code: 400
message: Bad Request
version: 1
78 changes: 78 additions & 0 deletions test/integration/fixtures/fetch_subscription_events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- chartmogul-python/3.1.1
content-type:
- application/json
method: GET
uri: https://api.chartmogul.com/v1/subscription_events
response:
body:
string: !!binary |
H4sIAAAAAAAAA+2b35KiOBTG34Xrdir/Q3yOvtqtKQohqCBIQ7B1uvrdNwlbu+vUjoyEgF1llT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vATEXdIIVx1Zl
SZaPV4lH24wLbUIDKmFjFlMJ6GkHDSGCsAmQwLu3fONQSzyRuHsRCj2tOLShjRnQv25HX6LYZCfq
oBKPthkX/sbOyz5mOZXwteIQIgQTuJe4oBfssAgdQGJ29/Ihkfj+EpRSxfoUSlDpMypRIfVZkb+P
+UANSN3IU/9hv2FvI7NjI/tP/j05I14hXgO8JvgbR9YPquOtPg+jFzDqqPTxHvNWL38I4p+ffwES
uS0yYzQAAA==
headers:
Access-Control-Allow-Credentials:
- 'true'
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Length:
- '1033'
Content-Type:
- application/json; charset=utf-8
Date:
- Fri, 19 May 2023 13:03:43 GMT
ETag:
- W/"605f65f25551e36f294b1276648844b4"
Referrer-Policy:
- strict-origin-when-cross-origin
Vary:
- Accept-Encoding
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- DENY
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- 4549e2f044e141372f3e09f1bf571314
X-Runtime:
- '0.052033'
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
24 changes: 0 additions & 24 deletions test/integration/test_delete_invoice

This file was deleted.

13 changes: 13 additions & 0 deletions test/integration/test_fetch_subscription_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
import vcr
from chartmogul import Config, SubscriptionEvent

config = Config(api_key = '-')

class FetchSubscriptionEventsTestCase(unittest.TestCase):
"""
Tests errors & user mistakes.
"""
@vcr.use_cassette('fixtures/fetch_subscription_events.yaml', filter_headers=['authorization'])
def test_subscription_events(self):
result = SubscriptionEvent.all(config).get()

0 comments on commit 8514ba4

Please sign in to comment.