Skip to content

Commit

Permalink
🐛 Source Chargebee: add tests + fix broken coupon stream (#10366)
Browse files Browse the repository at this point in the history
* 10192 Fix Chargebee source

Fix `coupon` stream.
Add unit tests.

* 10192 Update tests + update docs

* 10192 Bump connector's version
  • Loading branch information
Zirochkaa authored Feb 22, 2022
1 parent 8e8f27a commit e23c29d
Show file tree
Hide file tree
Showing 25 changed files with 2,771 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
- name: Chargebee
sourceDefinitionId: 686473f1-76d9-4994-9cc7-9b13da46147c
dockerRepository: airbyte/source-chargebee
dockerImageTag: 0.1.7
dockerImageTag: 0.1.8
documentationUrl: https://docs.airbyte.io/integrations/sources/chargebee
icon: chargebee.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-chargebee:0.1.7"
- dockerImage: "airbyte/source-chargebee:0.1.8"
spec:
documentationUrl: "https://apidocs.chargebee.com/docs/api"
connectionSpecification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ RUN pip install .

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

LABEL io.airbyte.version=0.1.7
LABEL io.airbyte.version=0.1.8
LABEL io.airbyte.name=airbyte/source-chargebee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@
"destination_sync_mode": "append",
"cursor_field": ["updated_at"]
},
{
"stream": {
"name": "event",
"json_schema": {},
"supported_sync_modes": ["full_refresh", "incremental"],
"source_defined_cursor": true,
"default_cursor_field": ["occurred_at"],
"source_defined_primary_key": [["id"]]
},
"sync_mode": "incremental",
"destination_sync_mode": "append",
"cursor_field": ["occurred_at"]
},
{
"stream": {
"name": "coupon",
"json_schema": {},
"supported_sync_modes": ["full_refresh", "incremental"],
"source_defined_cursor": true,
"default_cursor_field": ["updated_at"],
"source_defined_primary_key": [["id"]]
},
"sync_mode": "incremental",
"destination_sync_mode": "append",
"cursor_field": ["updated_at"]
},
{
"stream": {
"name": "customer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"subscription": {
"updated_at": 2147483647
},
"coupon": {
"updated_at": 2147483647
},
"customer": {
"updated_at": 2147483647
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
"destination_sync_mode": "append",
"cursor_field": ["updated_at"]
},
{
"stream": {
"name": "coupon",
"json_schema": {},
"supported_sync_modes": ["full_refresh", "incremental"],
"source_defined_cursor": true,
"default_cursor_field": ["updated_at"],
"source_defined_primary_key": [["id"]]
},
"sync_mode": "incremental",
"destination_sync_mode": "append",
"cursor_field": ["updated_at"]
},
{
"stream": {
"name": "customer",
Expand Down
2 changes: 2 additions & 0 deletions airbyte-integrations/connectors/source-chargebee/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
TEST_REQUIREMENTS = [
"pytest~=6.1",
"source-acceptance-test",
"jsonschema~=3.2.0",
"responses~=0.13.3",
]

setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"properties": {
"id": {
"type": ["string", "null"],
"max-length": 40
"max-length": 100
},
"name": {
"type": ["string", "null"],
"max-length": 150
"max-length": 50
},
"invoice_name": {
"type": ["string", "null"],
"max-length": 150
"max-length": 100
},
"discount_type": {
"type": ["string", "null"],
Expand Down Expand Up @@ -80,49 +80,39 @@
"properties": {
"item_type": {
"type": ["string", "null"],
"enum": ["plan", "adddon", "charge"]
"enum": ["plan", "addon", "charge"]
},
"constraint": {
"type": ["string", "null"],
"enum": ["none", "all", "specific", "criteria"]
},
"item_price_ids": {
"type": ["array", "null"],
"items": {
"type": ["object", "null"],
"properties": {}
}
"items": {}
}
}
}
},
"item_constraint_criteria": {
"type": ["array", "null"],
"items": ["object", "null"],
"properties": {
"item_type": {
"type": ["string", "null"],
"enum": ["plan", "adddon", "charge"]
},
"currencies": {
"type": ["array", "null"],
"items": {
"type": ["object", "null"],
"properties": {}
}
},
"item_family_ids": {
"type": ["array", "null"],
"items": {
"type": ["object", "null"],
"properties": {}
}
},
"item_price_periods": {
"type": ["array", "null"],
"items": {
"type": ["object", "null"],
"properties": {}
"items": {
"type": ["object", "null"],
"properties": {
"item_type": {
"type": ["string", "null"],
"enum": ["plan", "addon", "charge"]
},
"currencies": {
"type": ["array", "null"],
"items": {}
},
"item_family_ids": {
"type": ["array", "null"],
"items": {}
},
"item_price_periods": {
"type": ["array", "null"],
"items": {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self, start_date: str):
# Convert `start_date` to timestamp(UTC).
self._start_date = pendulum.parse(start_date).int_timestamp if start_date else None

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

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

class Event(IncrementalChargebeeStream):
"""
API docs: https://apidocs.eu.chargebee.com/docs/api/events?prod_cat_ver=2#list_events
API docs: https://apidocs.chargebee.com/docs/api/events?prod_cat_ver=2#list_events
"""

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

class Coupon(IncrementalChargebeeStream):
"""
API docs: https://apidocs.eu.chargebee.com/docs/api/coupon?prod_cat_ver=2#list_coupon
API docs: https://apidocs.chargebee.com/docs/api/coupons?prod_cat_ver=2#list_coupons
"""

cursor_field = "updated_at"

api = CouponModel

def request_params(self, **kwargs) -> MutableMapping[str, Any]:
params = super().request_params(**kwargs)
params["sort_by[asc]"] = "created_at"
return params
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#

import json
import os

from pytest import fixture


def load_file(fn):
return open(os.path.join("unit_tests", "responses", fn)).read()


@fixture
def test_config_v1():
return {"site": "airbyte-test", "site_api_key": "site_api_key", "start_date": "2021-05-22T06:57:44Z", "product_catalog": "1.0"}


@fixture
def test_config_v2():
return {"site": "airbyte-test", "site_api_key": "site_api_key", "start_date": "2021-05-22T06:57:44Z", "product_catalog": "2.0"}


@fixture
def addons_response():
return json.loads(load_file("addons.json"))


@fixture
def plans_response():
return json.loads(load_file("plans.json"))


@fixture
def coupons_response():
return json.loads(load_file("coupons.json"))


@fixture
def customers_response():
return json.loads(load_file("customers.json"))


@fixture
def invoices_response():
return json.loads(load_file("invoices.json"))


@fixture
def orders_response():
return json.loads(load_file("orders.json"))


@fixture
def events_response():
return json.loads(load_file("events.json"))


@fixture
def subscriptions_response():
return json.loads(load_file("subscriptions.json"))


@fixture
def items_response():
return json.loads(load_file("items.json"))


@fixture
def item_prices_response():
return json.loads(load_file("item_prices.json"))


@fixture
def attached_items_response():
return json.loads(load_file("attached_items.json"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"list": [
{
"addon": {
"id": "LAMBHEART",
"name": "Lamb Hearts",
"invoice_name": "Lamb Hearts",
"charge_type": "non_recurring",
"price": 850,
"period_unit": "not_applicable",
"status": "active",
"enabled_in_portal": false,
"object": "addon",
"taxable": true,
"type": "quantity"
}
},
{
"addon": {
"id": "LAMBHEART-estimate",
"name": "Lamb Hearts Estimate",
"invoice_name": "Lamb Hearts Estimate",
"charge_type": "non_recurring",
"price": 1700,
"period_unit": "not_applicable",
"status": "active",
"enabled_in_portal": false,
"object": "addon",
"taxable": false,
"type": "quantity"
}
},
{
"addon": {
"id": "LAMBHEART-TEST",
"name": "Lamb Hearts TEST",
"invoice_name": "Lamb Hearts TEST",
"charge_type": "non_recurring",
"price": 850,
"period_unit": "not_applicable",
"status": "active",
"enabled_in_portal": false,
"object": "addon",
"taxable": true,
"type": "quantity"
}
},
{
"addon": {
"id": "LAMBHEART-TEST-estimate",
"name": "Lamb Hearts TEST Estimate",
"invoice_name": "Lamb Hearts TEST Estimate",
"charge_type": "non_recurring",
"price": 1700,
"period_unit": "not_applicable",
"status": "active",
"enabled_in_portal": false,
"object": "addon",
"taxable": false,
"type": "quantity"
}
},
{
"addon": {
"id": "CHOMPERY-BEEFJERKY-estimate",
"name": "Chompery Beef Jerky Estimate",
"invoice_name": "Chompery Beef Jerky Estimate",
"charge_type": "non_recurring",
"price": 2400,
"period_unit": "not_applicable",
"status": "active",
"enabled_in_portal": true,
"object": "addon",
"taxable": true,
"type": "quantity"
}
}
]
}
Loading

0 comments on commit e23c29d

Please sign in to comment.