Skip to content

Commit

Permalink
Upgrade the Marshmallow dependency to be >=3.10.0 (#38) (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin Kawa <marcin.kawa@hotjar.com>
  • Loading branch information
kawa-marcin and kawa-marcin authored Feb 26, 2021
1 parent cde9524 commit f4041d4
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 70 deletions.
2 changes: 1 addition & 1 deletion chartmogul/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"""

__title__ = 'chartmogul'
__version__ = '1.4.1'
__version__ = '1.5.0'
__build__ = 0x000000
__author__ = 'ChartMogul Ltd'
__license__ = 'MIT'
Expand Down
12 changes: 6 additions & 6 deletions chartmogul/api/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ class Activity(Resource):

class _Schema(Schema):
id = fields.Int()
activity_arr = fields.Number(load_from='activity-arr')
activity_mrr = fields.Number(load_from='activity-mrr')
activity_mrr_movement = fields.Number(load_from='activity-mrr-movement')
activity_arr = fields.Number(data_key='activity-arr')
activity_mrr = fields.Number(data_key='activity-mrr')
activity_mrr_movement = fields.Number(data_key='activity-mrr-movement')
currency = fields.String()
currency_sign = fields.String(load_from='currency-sign')
currency_sign = fields.String(data_key='currency-sign')
date = fields.DateTime()
description = fields.String()
type = fields.String()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Activity(**data)

_schema = _Schema(strict=True)
_schema = _Schema()
4 changes: 2 additions & 2 deletions chartmogul/api/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class _Schema(Schema):
custom = fields.Dict()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Attributes(**data)

_schema = _Schema(strict=True)
_schema = _Schema()
8 changes: 4 additions & 4 deletions chartmogul/api/custom_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class _Schema(Schema):
custom = fields.Dict()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return CustomAttributes(**data)

_customers = namedtuple('Customers', ['entries'])
_schema = _Schema(strict=True)
_schema = _Schema()

@classmethod
def _load(cls, response):
Expand All @@ -31,7 +31,7 @@ def _load(cls, response):
return None
jsonObj = response.json()
if 'entries' in jsonObj:
customers = Customer._schema.load(jsonObj['entries'], many=True).data
customers = Customer._schema.load(jsonObj['entries'], many=True)
return cls._customers(customers)
else:
return cls._schema.load(jsonObj).data
return cls._schema.load(jsonObj)
16 changes: 8 additions & 8 deletions chartmogul/api/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _Schema(Schema):
state = fields.String(allow_none=True)

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Address(**data)


Expand Down Expand Up @@ -56,21 +56,21 @@ class _Schema(Schema):
external_ids = fields.List(fields.String())
data_source_uuids = fields.List(fields.String())
status = fields.String()
customer_since = fields.DateTime(load_from="customer-since", allow_none=True)
customer_since = fields.DateTime(data_key="customer-since", allow_none=True)
mrr = fields.Number()
arr = fields.Number()
billing_system_url = fields.String(load_from="billing-system-url", allow_none=True)
chartmogul_url = fields.String(load_from="chartmogul-url")
billing_system_type = fields.String(load_from="billing-system-type")
billing_system_url = fields.String(data_key="billing-system-url", allow_none=True)
chartmogul_url = fields.String(data_key="chartmogul-url")
billing_system_type = fields.String(data_key="billing-system-type")
currency = fields.String()
currency_sign = fields.String(load_from="currency-sign")
currency_sign = fields.String(data_key="currency-sign")
address = fields.Nested(Address._Schema, allow_none=True)

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Customer(**data)

_schema = _Schema(strict=True)
_schema = _Schema()


Customer.search = Customer._method('all', 'get', '/customers/search')
Expand Down
4 changes: 2 additions & 2 deletions chartmogul/api/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _Schema(Schema):
system = fields.Str()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return DataSource(**data)

_schema = _Schema(strict=True)
_schema = _Schema()
7 changes: 4 additions & 3 deletions chartmogul/api/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class _Schema(Schema):
tax_amount_in_cents = fields.Int()
transaction_fees_in_cents = fields.Int()
account_code = fields.String(allow_none=True)
description = fields.String(allow_none=True)

@post_load
def make(self, data):
def make(self, data, **kwargs):
return LineItem(**data)


Expand Down Expand Up @@ -54,10 +55,10 @@ class _Schema(Schema):
transactions = fields.Nested(Transaction._Schema, many=True)

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Invoice(**data)

_schema = _Schema(strict=True)
_schema = _Schema()

@classmethod
def all(cls, config, **kwargs):
Expand Down
26 changes: 13 additions & 13 deletions chartmogul/api/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Summary(DataObject):
class _Schema(Schema):
current = fields.Number()
previous = fields.Number()
percentage_change = fields.Number(load_from='percentage-change')
percentage_change = fields.Number(data_key='percentage-change')

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Summary(**data)

_schema = _Schema(strict=True)
_schema = _Schema()


class Metrics(Resource):
Expand All @@ -33,31 +33,31 @@ class _Schema(Schema):
Fields are optional, so a subset present is good enough
"""
date = fields.Date()
customer_churn_rate = fields.Number(load_from='customer-churn-rate')
mrr_churn_rate = fields.Number(load_from='mrr-churn-rate')
customer_churn_rate = fields.Number(data_key='customer-churn-rate')
mrr_churn_rate = fields.Number(data_key='mrr-churn-rate')
ltv = fields.Number()
customers = fields.Number()
asp = fields.Number()
arpa = fields.Number()
arr = fields.Number()
mrr = fields.Number()
# MRR only
mrr_new_business = fields.Number(load_from='mrr-new-business')
mrr_expansion = fields.Number(load_from='mrr-expansion')
mrr_contraction = fields.Number(load_from='mrr-contraction')
mrr_churn = fields.Number(load_from='mrr-churn')
mrr_reactivation = fields.Number(load_from='mrr-reactivation')
mrr_new_business = fields.Number(data_key='mrr-new-business')
mrr_expansion = fields.Number(data_key='mrr-expansion')
mrr_contraction = fields.Number(data_key='mrr-contraction')
mrr_churn = fields.Number(data_key='mrr-churn')
mrr_reactivation = fields.Number(data_key='mrr-reactivation')

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Metrics(**data)

_schema = _Schema(strict=True)
_schema = _Schema()

@classmethod
def _many(cls, entries, **kwargs):
if 'summary' in kwargs:
kwargs['summary'] = Summary._schema.load(kwargs['summary']).data
kwargs['summary'] = Summary._schema.load(kwargs['summary'])
return cls._many_cls(entries, **kwargs)


Expand Down
4 changes: 2 additions & 2 deletions chartmogul/api/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class _Schema(Schema):
data = fields.String()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Ping(**data)

_schema = _Schema(strict=True)
_schema = _Schema()


_add_method(Ping, "ping", "get")
4 changes: 2 additions & 2 deletions chartmogul/api/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _Schema(Schema):
external_id = fields.String()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Plan(**data)

_schema = _Schema(strict=True)
_schema = _Schema()
4 changes: 2 additions & 2 deletions chartmogul/api/plan_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class _Schema(Schema):
plans_count = fields.Int()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return PlanGroup(**data)

_schema = _Schema(strict=True)
_schema = _Schema()

@classmethod
def all(cls, config, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions chartmogul/api/plan_group_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _Schema(Schema):
external_id = fields.String()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return PlanGroupPlans(**data)

_schema = _Schema(strict=True)
_schema = _Schema()
16 changes: 8 additions & 8 deletions chartmogul/api/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class _Schema(Schema):
mrr = fields.Number(allow_none=True)
arr = fields.Number(allow_none=True)
status = fields.String(allow_none=True)
billing_cycle = fields.String(load_from='billing-cycle', allow_none=True)
billing_cycle_count = fields.Number(load_from='billing-cycle-count', allow_none=True)
start_date = fields.DateTime(load_from='start-date', allow_none=True)
end_date = fields.DateTime(load_from='end-date', allow_none=True)
billing_cycle = fields.String(data_key='billing-cycle', allow_none=True)
billing_cycle_count = fields.Number(data_key='billing-cycle-count', allow_none=True)
start_date = fields.DateTime(data_key='start-date', allow_none=True)
end_date = fields.DateTime(data_key='end-date', allow_none=True)
currency = fields.String(allow_none=True)
currency_sign = fields.String(load_from='currency-sign', allow_none=True)
currency_sign = fields.String(data_key='currency-sign', allow_none=True)

# /import namespace
uuid = fields.String(allow_none=True)
Expand All @@ -36,17 +36,17 @@ class _Schema(Schema):
cancellation_dates = fields.List(fields.DateTime(), allow_none=True)

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Subscription(**data)

_schema = _Schema(strict=True)
_schema = _Schema()

# /import has different paging
@classmethod
def _loadJSON(cls, jsonObj):
if "subscriptions" in jsonObj:
_many = namedtuple('Subscriptions', ["subscriptions", "current_page", "total_pages", "customer_uuid"])
return _many(cls._schema.load(jsonObj["subscriptions"], many=True).data,
return _many(cls._schema.load(jsonObj["subscriptions"], many=True),
jsonObj["current_page"],
jsonObj["total_pages"],
jsonObj["customer_uuid"])
Expand Down
8 changes: 4 additions & 4 deletions chartmogul/api/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class _Schema(Schema):
tags = fields.List(fields.String())

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Tags(**data)

_customers = namedtuple('Customers', ['entries'])
_schema = _Schema(strict=True)
_schema = _Schema()

@classmethod
def _load(cls, response):
Expand All @@ -31,7 +31,7 @@ def _load(cls, response):
return None
jsonObj = response.json()
if 'entries' in jsonObj:
customers = Customer._schema.load(jsonObj['entries'], many=True).data
customers = Customer._schema.load(jsonObj['entries'], many=True)
return cls._customers(customers)
else:
return cls._schema.load(jsonObj).data
return cls._schema.load(jsonObj)
4 changes: 2 additions & 2 deletions chartmogul/api/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class _Schema(Schema):
result = fields.String()

@post_load
def make(self, data):
def make(self, data, **kwargs):
return Transaction(**data)

_schema = _Schema(strict=True)
_schema = _Schema()
16 changes: 9 additions & 7 deletions chartmogul/resource.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import requests
from builtins import str
from datetime import date, datetime
from json import dumps

import requests
from promise import Promise
from uritemplate import URITemplate
from .retry_request import requests_retry_session
from .errors import APIError, ConfigurationError, ArgumentMissingError, annotateHTTPError

from .api.config import Config
from datetime import datetime, date
from builtins import str
from .errors import APIError, ArgumentMissingError, ConfigurationError, annotateHTTPError
from .retry_request import requests_retry_session

"""
HTTP verb mapping. Based on nodejs library.
Expand Down Expand Up @@ -96,10 +98,10 @@ def _load(cls, response):
def _loadJSON(cls, jsonObj):
# has load_many capability & is many entries result?
if '_root_key' in dir(cls) is not None and cls._root_key in jsonObj:
return cls._many(cls._schema.load(jsonObj[cls._root_key], many=True).data,
return cls._many(cls._schema.load(jsonObj[cls._root_key], many=True),
**{key: jsonObj[key] for key in LIST_PARAMS if key in jsonObj})
else:
return cls._schema.load(jsonObj).data
return cls._schema.load(jsonObj)

@classmethod
def _preProcessParams(cls, params):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
requests>=2.10.0
uritemplate>=3.0.0
promise>=1.0.1
marshmallow>=2.12.1,<3
marshmallow>=3.10.0
future>=0.16.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'requests>=2.10.0',
'uritemplate>=3.0.0',
'promise>=1.0.1',
'marshmallow>=2.12.1,<3',
'marshmallow>=3.10.0',
'future>=0.16.0',
]
test_requirements = [
Expand Down

0 comments on commit f4041d4

Please sign in to comment.