Skip to content

Commit f4c9e1a

Browse files
author
Rohit Chatterjee
committed
include_archived as a config setting
1 parent 6ba462d commit f4c9e1a

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

airbyte-integrations/connectors/source-commcare/source_commcare/source.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def __init__(self, start_date, app_id, name, xmlns, schema, **kwargs):
255255
self.streamname = name
256256
self.xmlns = xmlns
257257
self.schema = schema
258+
self.include_archived = kwargs.get("include_archived", False)
258259

259260
@property
260261
def name(self):
@@ -279,7 +280,7 @@ def request_params(
279280
"indexed_on_start": ix.strftime(self.dateformat_for_query),
280281
"order_by": "indexed_on",
281282
"limit": "1000",
282-
"include_archived": True,
283+
"include_archived": self.include_archived,
283284
"xmlns": self.xmlns,
284285
}
285286
if next_page_token:
@@ -366,6 +367,7 @@ def generate_streams(self, args, config, appdata):
366367
"start_date": config["start_date"],
367368
"form_fields_to_exclude": form_fields_to_exclude,
368369
"project_space": config["project_space"],
370+
"include_archived": config["include_archived"],
369371
**args,
370372
}
371373
streams = []

airbyte-integrations/connectors/source-commcare/source_commcare/spec.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ connectionSpecification:
4242
title: Form Fields to be Excluded
4343
description: Forms field which you don't want to pull
4444
order: 4
45+
include_archived:
46+
type: boolean
47+
title: Include Archived Forms
48+
description: Include archived forms in the replication
49+
default: false
50+
order: 5

airbyte-integrations/connectors/source-commcare/unit_tests/test_source.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010

1111
@pytest.fixture(name="config")
12-
def config_fixture():
13-
return {"api_key": "apikey", "app_id": "appid", "project_space": "project_space", "start_date": "2022-01-01T00:00:00Z",'form_fields_to_exclude':[]}
12+
def config_fixture_1():
13+
return {"api_key": "apikey", "app_id": "appid", "project_space": "project_space", "start_date": "2022-01-01T00:00:00Z",'form_fields_to_exclude':[], "include_archived": False}
14+
15+
@pytest.fixture(name="config_include_archived")
16+
def config_fixture_2():
17+
return {"api_key": "apikey", "app_id": "appid", "project_space": "project_space", "start_date": "2022-01-01T00:00:00Z",'form_fields_to_exclude':[], "include_archived": True}
1418

1519

1620
@patch("source_commcare.source.Application.read_records")
@@ -30,3 +34,61 @@ def test_check_connection_fail(mocker, config):
3034
logger_mock = MagicMock()
3135
excepted_outcome = " Invalid apikey, project_space or app_id : 'api_key'"
3236
assert source.check_connection(logger_mock, config={}) == (False, excepted_outcome)
37+
38+
def test_include_archived_false(config):
39+
source = SourceCommcare()
40+
appdata = [
41+
{
42+
"modules": [
43+
{
44+
"forms": [
45+
{
46+
"xmlns": "namespace",
47+
"name": {"en": "english_name"},
48+
}
49+
]
50+
}
51+
]
52+
}
53+
]
54+
streams = source.generate_streams({}, config, appdata)
55+
assert len(streams) == 2
56+
57+
# form
58+
assert streams[0].name == "english_name"
59+
assert streams[0].xmlns == "namespace"
60+
assert streams[0].include_archived == False
61+
62+
# case
63+
assert streams[1].app_id == "appid"
64+
assert streams[1].project_space == "project_space"
65+
assert streams[1].start_date == "2022-01-01T00:00:00Z"
66+
67+
def test_include_archived_true(config_include_archived):
68+
source = SourceCommcare()
69+
appdata = [
70+
{
71+
"modules": [
72+
{
73+
"forms": [
74+
{
75+
"xmlns": "namespace",
76+
"name": {"en": "english_name"},
77+
}
78+
]
79+
}
80+
]
81+
}
82+
]
83+
streams = source.generate_streams({}, config_include_archived, appdata)
84+
assert len(streams) == 2
85+
86+
# form
87+
assert streams[0].name == "english_name"
88+
assert streams[0].xmlns == "namespace"
89+
assert streams[0].include_archived == True
90+
91+
# case
92+
assert streams[1].app_id == "appid"
93+
assert streams[1].project_space == "project_space"
94+
assert streams[1].start_date == "2022-01-01T00:00:00Z"

0 commit comments

Comments
 (0)