Skip to content

Commit 3337b84

Browse files
committed
10192 Fix Chargebee source
Fix `coupon` stream. Add unit tests.
1 parent ce5c007 commit 3337b84

23 files changed

+2778
-44
lines changed

airbyte-integrations/connectors/source-chargebee/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ RUN pip install .
1313

1414
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1515

16-
LABEL io.airbyte.version=0.1.7
16+
LABEL io.airbyte.version=0.1.8
1717
LABEL io.airbyte.name=airbyte/source-chargebee

airbyte-integrations/connectors/source-chargebee/integration_tests/configured_catalog.json

+26
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@
1313
"destination_sync_mode": "append",
1414
"cursor_field": ["updated_at"]
1515
},
16+
{
17+
"stream": {
18+
"name": "event",
19+
"json_schema": {},
20+
"supported_sync_modes": ["full_refresh", "incremental"],
21+
"source_defined_cursor": true,
22+
"default_cursor_field": ["occurred_at"],
23+
"source_defined_primary_key": [["id"]]
24+
},
25+
"sync_mode": "incremental",
26+
"destination_sync_mode": "append",
27+
"cursor_field": ["occurred_at"]
28+
},
29+
{
30+
"stream": {
31+
"name": "coupon",
32+
"json_schema": {},
33+
"supported_sync_modes": ["full_refresh", "incremental"],
34+
"source_defined_cursor": true,
35+
"default_cursor_field": ["updated_at"],
36+
"source_defined_primary_key": [["id"]]
37+
},
38+
"sync_mode": "incremental",
39+
"destination_sync_mode": "append",
40+
"cursor_field": ["updated_at"]
41+
},
1642
{
1743
"stream": {
1844
"name": "customer",

airbyte-integrations/connectors/source-chargebee/integration_tests/future_state.json

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"subscription": {
33
"updated_at": 2147483647
44
},
5+
"coupon": {
6+
"updated_at": 2147483647
7+
},
58
"customer": {
69
"updated_at": 2147483647
710
},

airbyte-integrations/connectors/source-chargebee/integration_tests/product_catalog_v2_configured_catalog.json

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
"destination_sync_mode": "append",
1414
"cursor_field": ["updated_at"]
1515
},
16+
{
17+
"stream": {
18+
"name": "coupon",
19+
"json_schema": {},
20+
"supported_sync_modes": ["full_refresh", "incremental"],
21+
"source_defined_cursor": true,
22+
"default_cursor_field": ["updated_at"],
23+
"source_defined_primary_key": [["id"]]
24+
},
25+
"sync_mode": "incremental",
26+
"destination_sync_mode": "append",
27+
"cursor_field": ["updated_at"]
28+
},
1629
{
1730
"stream": {
1831
"name": "customer",

airbyte-integrations/connectors/source-chargebee/setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
TEST_REQUIREMENTS = [
1818
"pytest~=6.1",
1919
"source-acceptance-test",
20+
"jsonschema~=3.2.0",
21+
"responses~=0.13.3",
2022
]
2123

2224
setup(

airbyte-integrations/connectors/source-chargebee/source_chargebee/schemas/coupon.json

+23-33
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"properties": {
66
"id": {
77
"type": ["string", "null"],
8-
"max-length": 40
8+
"max-length": 100
99
},
1010
"name": {
1111
"type": ["string", "null"],
12-
"max-length": 150
12+
"max-length": 50
1313
},
1414
"invoice_name": {
1515
"type": ["string", "null"],
16-
"max-length": 150
16+
"max-length": 100
1717
},
1818
"discount_type": {
1919
"type": ["string", "null"],
@@ -80,49 +80,39 @@
8080
"properties": {
8181
"item_type": {
8282
"type": ["string", "null"],
83-
"enum": ["plan", "adddon", "charge"]
83+
"enum": ["plan", "addon", "charge"]
8484
},
8585
"constraint": {
8686
"type": ["string", "null"],
8787
"enum": ["none", "all", "specific", "criteria"]
8888
},
8989
"item_price_ids": {
9090
"type": ["array", "null"],
91-
"items": {
92-
"type": ["object", "null"],
93-
"properties": {}
94-
}
91+
"items": {}
9592
}
9693
}
9794
}
9895
},
9996
"item_constraint_criteria": {
10097
"type": ["array", "null"],
101-
"items": ["object", "null"],
102-
"properties": {
103-
"item_type": {
104-
"type": ["string", "null"],
105-
"enum": ["plan", "adddon", "charge"]
106-
},
107-
"currencies": {
108-
"type": ["array", "null"],
109-
"items": {
110-
"type": ["object", "null"],
111-
"properties": {}
112-
}
113-
},
114-
"item_family_ids": {
115-
"type": ["array", "null"],
116-
"items": {
117-
"type": ["object", "null"],
118-
"properties": {}
119-
}
120-
},
121-
"item_price_periods": {
122-
"type": ["array", "null"],
123-
"items": {
124-
"type": ["object", "null"],
125-
"properties": {}
98+
"items": {
99+
"type": ["object", "null"],
100+
"properties": {
101+
"item_type": {
102+
"type": ["string", "null"],
103+
"enum": ["plan", "addon", "charge"]
104+
},
105+
"currencies": {
106+
"type": ["array", "null"],
107+
"items": {}
108+
},
109+
"item_family_ids": {
110+
"type": ["array", "null"],
111+
"items": {}
112+
},
113+
"item_price_periods": {
114+
"type": ["array", "null"],
115+
"items": {}
126116
}
127117
}
128118
}

airbyte-integrations/connectors/source-chargebee/source_chargebee/streams.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, start_date: str):
115115
# Convert `start_date` to timestamp(UTC).
116116
self._start_date = pendulum.parse(start_date).int_timestamp if start_date else None
117117

118-
def get_starting_point(self, stream_state: Mapping[str, Any], item_id: str) -> str:
118+
def get_starting_point(self, stream_state: Mapping[str, Any], item_id: str) -> int:
119119
start_point = self._start_date
120120

121121
if stream_state and stream_state.get(item_id, {}).get(self.cursor_field):
@@ -282,7 +282,7 @@ def _send_request(
282282

283283
class Event(IncrementalChargebeeStream):
284284
"""
285-
API docs: https://apidocs.eu.chargebee.com/docs/api/events?prod_cat_ver=2#list_events
285+
API docs: https://apidocs.chargebee.com/docs/api/events?prod_cat_ver=2#list_events
286286
"""
287287

288288
cursor_field = "occurred_at"
@@ -292,9 +292,14 @@ class Event(IncrementalChargebeeStream):
292292

293293
class Coupon(IncrementalChargebeeStream):
294294
"""
295-
API docs: https://apidocs.eu.chargebee.com/docs/api/coupon?prod_cat_ver=2#list_coupon
295+
API docs: https://apidocs.chargebee.com/docs/api/coupons?prod_cat_ver=2#list_coupons
296296
"""
297297

298298
cursor_field = "updated_at"
299299

300300
api = CouponModel
301+
302+
def request_params(self, **kwargs) -> MutableMapping[str, Any]:
303+
params = super().request_params(**kwargs)
304+
params["sort_by[asc]"] = "created_at"
305+
return params
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#
2+
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
import json
6+
import os
7+
8+
from pytest import fixture
9+
10+
11+
def load_file(fn):
12+
return open(os.path.join("unit_tests", "responses", fn)).read()
13+
14+
15+
@fixture
16+
def test_config_v1():
17+
return {"site": "airbyte-test", "site_api_key": "site_api_key", "start_date": "2021-05-22T06:57:44Z", "product_catalog": "1.0"}
18+
19+
20+
@fixture
21+
def test_config_v2():
22+
return {"site": "airbyte-test", "site_api_key": "site_api_key", "start_date": "2021-05-22T06:57:44Z", "product_catalog": "2.0"}
23+
24+
25+
@fixture
26+
def addons_response():
27+
return json.loads(load_file("addons.json"))
28+
29+
30+
@fixture
31+
def plans_response():
32+
return json.loads(load_file("plans.json"))
33+
34+
35+
@fixture
36+
def coupons_response():
37+
return json.loads(load_file("coupons.json"))
38+
39+
40+
@fixture
41+
def customers_response():
42+
return json.loads(load_file("customers.json"))
43+
44+
45+
@fixture
46+
def invoices_response():
47+
return json.loads(load_file("invoices.json"))
48+
49+
50+
@fixture
51+
def orders_response():
52+
return json.loads(load_file("orders.json"))
53+
54+
55+
@fixture
56+
def events_response():
57+
return json.loads(load_file("events.json"))
58+
59+
60+
@fixture
61+
def subscriptions_response():
62+
return json.loads(load_file("subscriptions.json"))
63+
64+
65+
@fixture
66+
def items_response():
67+
return json.loads(load_file("items.json"))
68+
69+
70+
@fixture
71+
def item_prices_response():
72+
return json.loads(load_file("item_prices.json"))
73+
74+
75+
@fixture
76+
def attached_items_response():
77+
return json.loads(load_file("attached_items.json"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"list": [
3+
{
4+
"addon": {
5+
"id": "LAMBHEART",
6+
"name": "Lamb Hearts",
7+
"invoice_name": "Lamb Hearts",
8+
"charge_type": "non_recurring",
9+
"price": 850,
10+
"period_unit": "not_applicable",
11+
"status": "active",
12+
"enabled_in_portal": false,
13+
"object": "addon",
14+
"taxable": true,
15+
"type": "quantity"
16+
}
17+
},
18+
{
19+
"addon": {
20+
"id": "LAMBHEART-estimate",
21+
"name": "Lamb Hearts Estimate",
22+
"invoice_name": "Lamb Hearts Estimate",
23+
"charge_type": "non_recurring",
24+
"price": 1700,
25+
"period_unit": "not_applicable",
26+
"status": "active",
27+
"enabled_in_portal": false,
28+
"object": "addon",
29+
"taxable": false,
30+
"type": "quantity"
31+
}
32+
},
33+
{
34+
"addon": {
35+
"id": "LAMBHEART-TEST",
36+
"name": "Lamb Hearts TEST",
37+
"invoice_name": "Lamb Hearts TEST",
38+
"charge_type": "non_recurring",
39+
"price": 850,
40+
"period_unit": "not_applicable",
41+
"status": "active",
42+
"enabled_in_portal": false,
43+
"object": "addon",
44+
"taxable": true,
45+
"type": "quantity"
46+
}
47+
},
48+
{
49+
"addon": {
50+
"id": "LAMBHEART-TEST-estimate",
51+
"name": "Lamb Hearts TEST Estimate",
52+
"invoice_name": "Lamb Hearts TEST Estimate",
53+
"charge_type": "non_recurring",
54+
"price": 1700,
55+
"period_unit": "not_applicable",
56+
"status": "active",
57+
"enabled_in_portal": false,
58+
"object": "addon",
59+
"taxable": false,
60+
"type": "quantity"
61+
}
62+
},
63+
{
64+
"addon": {
65+
"id": "CHOMPERY-BEEFJERKY-estimate",
66+
"name": "Chompery Beef Jerky Estimate",
67+
"invoice_name": "Chompery Beef Jerky Estimate",
68+
"charge_type": "non_recurring",
69+
"price": 2400,
70+
"period_unit": "not_applicable",
71+
"status": "active",
72+
"enabled_in_portal": true,
73+
"object": "addon",
74+
"taxable": true,
75+
"type": "quantity"
76+
}
77+
}
78+
]
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"list": [
3+
{
4+
"attached_item": {
5+
"id": "649adf6e-1ac8-4a3b-ac09-5d85b030d762",
6+
"parent_item_id": "cbdemo_standard",
7+
"item_id": "cbdemo_crm_conciergesupport",
8+
"type": "mandatory",
9+
"status": "active",
10+
"quantity": 3,
11+
"created_at": 1628259684,
12+
"resource_version": 1628259684867,
13+
"updated_at": 1628259684,
14+
"object": "attached_item"
15+
}
16+
},
17+
{
18+
"attached_item": {
19+
"id": "3be57e40-84d8-4b70-9ae1-e907651fa819",
20+
"parent_item_id": "cbdemo_standard",
21+
"item_id": "cbdemo_post_payment_actions",
22+
"type": "mandatory",
23+
"status": "active",
24+
"quantity": 3,
25+
"created_at": 1628259646,
26+
"resource_version": 1628259646465,
27+
"updated_at": 1628259646,
28+
"object": "attached_item"
29+
}
30+
}
31+
]
32+
}

0 commit comments

Comments
 (0)