Skip to content

Commit

Permalink
Remove schema from Stripe & Clearbit attributes [ch426] (#20)
Browse files Browse the repository at this point in the history
* Removed schema from Stripe & Clearbit attributes [ch426]

* Version bumped to 1.1.8 [ch426]

* Fixing travis build for 3.3 [ch426]

* Removed 3.3 [ch426]
  • Loading branch information
hassansin authored and pkopac committed Jul 27, 2018
1 parent 585ecf3 commit 0595f4e
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 92 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: python

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
Expand Down
2 changes: 1 addition & 1 deletion chartmogul/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"""

__title__ = 'chartmogul'
__version__ = '1.1.7'
__version__ = '1.1.8'
__build__ = 0x000000
__author__ = 'ChartMogul Ltd'
__license__ = 'MIT'
Expand Down
67 changes: 2 additions & 65 deletions chartmogul/api/attributes.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,6 @@
from marshmallow import Schema, fields, post_load
from ..resource import Resource, DataObject


class Stripe(DataObject):
class _Schema(Schema):
uid = fields.Int()
coupon = fields.Boolean()

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


class Name(DataObject):
class _Schema(Schema):
fullName = fields.String()

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


class Employment(DataObject):
class _Schema(Schema):
name = fields.String()

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


class Person(DataObject):
class _Schema(Schema):
name = fields.Nested(Name._Schema)
employment = fields.Nested(Employment._Schema)

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


class Company(DataObject):
class _Schema(Schema):
name = fields.String()
legalName = fields.String()
domain = fields.String()
url = fields.String()
category = fields.Dict()
metrics = fields.Dict()

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


class Clearbit(DataObject):
class _Schema(Schema):
company = fields.Nested(Company._Schema)
person = fields.Nested(Person._Schema)

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


class Attributes(Resource):
"""
https://dev.chartmogul.com/v1.0/reference#customer-attributes
Expand All @@ -72,8 +9,8 @@ class Attributes(Resource):

class _Schema(Schema):
tags = fields.List(fields.String())
stripe = fields.Nested(Stripe._Schema)
clearbit = fields.Nested(Clearbit._Schema)
stripe = fields.Dict()
clearbit = fields.Dict()
custom = fields.Dict()

@post_load
Expand Down
2 changes: 1 addition & 1 deletion chartmogul/api/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from marshmallow import Schema, fields, post_load
from ..resource import Resource, DataObject, _add_method
from collections import namedtuple
from .attributes import Stripe, Name, Employment, Person, Company, Clearbit, Attributes
from .attributes import Attributes


class Address(DataObject):
Expand Down
115 changes: 91 additions & 24 deletions test/api/test_customer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest
from chartmogul import Customer, Config
from chartmogul.api.customer import Attributes, Stripe, Clearbit,\
Company, Person, Name, Employment, Address
from chartmogul.api.customer import Attributes, Address
from datetime import datetime
import requests_mock

Expand Down Expand Up @@ -112,39 +111,39 @@
zip="0185128",
attributes=Attributes(
tags=["engage", "unit loss", "discountable"],
stripe=Stripe(
uid=7,
coupon=True
),
clearbit=Clearbit(
company=Company(
name="Example Company",
legalName="Example Company Inc.",
domain="examplecompany.com",
url="http://examplecompany.com",
category={
stripe={
"uid": 7,
"coupon": True
},
clearbit={
"company": {
"name": "Example Company",
"legalName": "Example Company Inc.",
"domain": "examplecompany.com",
"url": "http://examplecompany.com",
"category": {
"sector": "Information Technology",
"industryGroup": "Software and Services",
"industry": "Software",
"subIndustry": "Application Software"
},
metrics={
"metrics": {
"alexaGlobalRank": 2319,
"googleRank": 7,
"employees": 1000,
"marketCap": None,
"raised": 1502450000
},
),
person=Person(
name=Name(
fullName="Bob Kramer"
),
employment=Employment(
name="Example Company"
)
)
),
},
"person": {
"name": {
"fullName": "Bob Kramer"
},
"employment": {
"name": "Example Company"
}
}
},
custom={
"CAC": 213,
"utmCampaign": "social media 1",
Expand Down Expand Up @@ -183,6 +182,39 @@
"zip": "0185128",
"attributes": {
"tags": ["engage", "unit loss", "discountable"],
"stripe":{
"uid": 7,
"coupon": True
},
"clearbit": {
"company": {
"name": "Example Company",
"legalName": "Example Company Inc.",
"domain": "examplecompany.com",
"url": "http://examplecompany.com",
"category": {
"sector": "Information Technology",
"industryGroup": "Software and Services",
"industry": "Software",
"subIndustry": "Application Software"
},
"metrics": {
"raised": 1502450000,
"employees": 1000,
"googleRank": 7,
"alexaGlobalRank": 2319,
"marketCap": None
},
},
"person": {
"name": {
"fullName": "Bob Kramer"
},
"employment": {
"name": "Example Company"
}
}
},
"custom": [
{'key': 'CAC', 'type': 'Integer', 'value': 213},
{"key": "utmCampaign", "value": "social media 1", "type": "String"},
Expand All @@ -195,6 +227,39 @@

sentCreateExpected = {
'attributes': {
"stripe":{
"uid": 7,
"coupon": True
},
"clearbit": {
"company": {
"name": "Example Company",
"legalName": "Example Company Inc.",
"domain": "examplecompany.com",
"url": "http://examplecompany.com",
"category": {
"sector": "Information Technology",
"industryGroup": "Software and Services",
"industry": "Software",
"subIndustry": "Application Software"
},
"metrics": {
"raised": 1502450000,
"employees": 1000,
"googleRank": 7,
"alexaGlobalRank": 2319,
"marketCap": None
},
},
"person": {
"name": {
"fullName": "Bob Kramer"
},
"employment": {
"name": "Example Company"
}
}
},
'custom': [
{'key': 'CAC', 'type': 'Integer', 'value': 213},
{"key": "utmCampaign", "value": "social media 1", "type": "String"},
Expand Down Expand Up @@ -254,6 +319,8 @@ def test_all(self, mock_requests):
# self.assertEqual(str(customers), str(expected))
# => check only first level fields are OK
self.assertEqual(sorted(dir(customers)), sorted(dir(expected)))
self.assertEqual(sorted(customers.entries[0].attributes.stripe), sorted(expected.entries[0].attributes.stripe))
self.assertEqual(sorted(customers.entries[0].attributes.clearbit), sorted(expected.entries[0].attributes.clearbit))
self.assertTrue(isinstance(customers.entries[0], Customer))

@requests_mock.mock()
Expand Down

0 comments on commit 0595f4e

Please sign in to comment.