Skip to content

Commit

Permalink
Merge pull request #92 from rapidpro/def-export
Browse files Browse the repository at this point in the history
Add back get definitions
  • Loading branch information
rowanseymour authored Apr 16, 2024
2 parents 85cdced + 35c9851 commit ba8a378
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions temba_client/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Channel,
Classifier,
Contact,
Export,
Field,
Flow,
FlowStart,
Expand Down Expand Up @@ -125,6 +126,17 @@ def get_contacts(self, uuid=None, urn=None, group=None, deleted=None, before=Non
)
return self._get_query("contacts", params, Contact)

def get_definitions(self, flows=(), campaigns=(), dependencies=None):
"""
Gets an export of specified definitions
:param flows: flow objects or UUIDs to include
:param campaigns: campaign objects or UUIDs to include
:param dependencies: whether to include dependencies
:return: definitions export
"""
params = self._build_params(flow=flows, campaign=campaigns, dependencies=dependencies)
return Export.deserialize(self._get_raw("definitions", params))

def get_fields(self, key=None):
"""
Gets all matching contact fields
Expand Down
23 changes: 23 additions & 0 deletions temba_client/v2/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,29 @@ def test_get_contacts(self, mock_request):
},
)

def test_get_definitions(self, mock_request):
mock_request.return_value = MockResponse(200, self.read_json("definitions"))

# check with all params
definitions = self.client.get_definitions(
flows=["04a4752b-0f49-480e-ae60-3a3f2bea485c", "ffce0fbb-4fe1-4052-b26a-91beb2ebae9a"],
campaigns=[],
dependencies=False,
)

self.assertRequest(
mock_request,
"get",
"definitions",
params={
"flow": ["04a4752b-0f49-480e-ae60-3a3f2bea485c", "ffce0fbb-4fe1-4052-b26a-91beb2ebae9a"],
"campaign": [],
"dependencies": 0,
},
)

self.assertEqual(definitions.version, "10.1")

def test_get_fields(self, mock_request):
# check no params
mock_request.return_value = MockResponse(200, self.read_json("fields"))
Expand Down
8 changes: 8 additions & 0 deletions temba_client/v2/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ class Contact(TembaObject):
last_seen_on = DatetimeField()


class Export(TembaObject):
version = SimpleField()
flows = ListField()
campaigns = ListField()
triggers = ListField()
fields = ListField()
groups = ListField()

class Field(TembaObject):
key = SimpleField()
name = SimpleField()
Expand Down

0 comments on commit ba8a378

Please sign in to comment.