Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to update phone, order user detail, and import action #1074

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion parsons/action_kit/action_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,33 @@ def update_user(self, user_id, **kwargs):
in the `ActionKit API Documentation <https://roboticdogs.actionkit.com/docs/\
manual/api/rest/actionprocessing.html>`_.
`Returns:`
``None``
``HTTP response from the patch request``
"""

resp = self.conn.patch(self._base_endpoint("user", user_id), data=json.dumps(kwargs))
logger.info(f"{resp.status_code}: {user_id}")

return resp

def update_phone(self, phone_id, **kwargs):
"""
Update a phone record.

`Args:`
phone_id: int
The phone id of the phone to update
**kwargs:
Optional arguments and fields to pass to the client. A full list can be found
at the /rest/v1/phone/schema/ path on any ActionKit instance.
`Returns:`
``HTTP response from the patch request``
"""

resp = self.conn.patch(self._base_endpoint("phone", phone_id), data=json.dumps(kwargs))
logger.info(f"{resp.status_code}: {phone_id}")

return resp

def get_event(self, event_id):
"""Get an event.

Expand Down Expand Up @@ -833,6 +852,27 @@ def update_order(self, order_id, **kwargs):
resp = self.conn.patch(self._base_endpoint("order", order_id), data=json.dumps(kwargs))
logger.info(f"{resp.status_code}: {order_id}")

def update_order_user_detail(self, user_detail_id, **kwargs):
"""
Update an order user detail.

`Args:`
user_detail_id: int
The id of the order user detail to update
**kwargs:
Optional arguments and fields to pass to the client. A full list can be found
at the /rest/v1/orderuserdetail/schema/ path on any ActionKit instance.
`Returns:`
``HTTP response from the patch request``
"""

resp = self.conn.patch(
self._base_endpoint("orderuserdetail", user_detail_id), data=json.dumps(kwargs)
)
logger.info(f"{resp.status_code}: {user_detail_id}")

return resp

def get_orderrecurring(self, orderrecurring_id):
"""
Get an orderrecurring.
Expand Down Expand Up @@ -1119,6 +1159,27 @@ def create_generic_action(self, page, email=None, ak_id=None, **kwargs):
**kwargs,
)

def update_import_action(self, action_id, **kwargs):
"""
Update an import action.

`Args:`
action_id: int
The action id of the import action to update
**kwargs:
Optional arguments and fields to pass to the client. A full list can be found
at the /rest/v1/importaction/schema/ path on any ActionKit instance.
`Returns:`
``HTTP response from the patch request``
"""

resp = self.conn.patch(
self._base_endpoint("importaction", action_id), data=json.dumps(kwargs)
)
logger.info(f"{resp.status_code}: {action_id}")

return resp

def bulk_upload_csv(
self,
csv_file,
Expand Down
48 changes: 48 additions & 0 deletions test/test_action_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ def test_update_user(self):

assert res.status_code == 202

def test_update_phone(self):
# Test update phone

# Mock resp and status code
resp_mock = mock.MagicMock()
type(resp_mock.patch()).status_code = mock.PropertyMock(return_value=202)
self.actionkit.conn = resp_mock

res = self.actionkit.update_phone(123, type="mobile")
self.actionkit.conn.patch.assert_called_with(
"https://domain.actionkit.com/rest/v1/phone/123/",
data=json.dumps({"type": "mobile"}),
)

assert res.status_code == 202

def test_update_event(self):
# Test update event

Expand Down Expand Up @@ -453,6 +469,22 @@ def test_update_order(self):
data=json.dumps({"account": "test"}),
)

def test_update_order_user_detail(self):
# Test update order user detail

# Mock resp and status code
resp_mock = mock.MagicMock()
type(resp_mock.patch()).status_code = mock.PropertyMock(return_value=202)
self.actionkit.conn = resp_mock

res = self.actionkit.update_order_user_detail(123, first_name="new name")
self.actionkit.conn.patch.assert_called_with(
"https://domain.actionkit.com/rest/v1/orderuserdetail/123/",
data=json.dumps({"first_name": "new name"}),
)

assert res.status_code == 202

def test_get_orders(self):
# Test get orders
resp_mock = mock.MagicMock()
Expand Down Expand Up @@ -638,6 +670,22 @@ def test_create_generic_action(self):
data=json.dumps({"email": "bob@bob.com", "page": "my_action"}),
)

def test_update_import_action(self):
# Test update import action

# Mock resp and status code
resp_mock = mock.MagicMock()
type(resp_mock.patch()).status_code = mock.PropertyMock(return_value=202)
self.actionkit.conn = resp_mock

res = self.actionkit.update_import_action(123, source="new source")
self.actionkit.conn.patch.assert_called_with(
"https://domain.actionkit.com/rest/v1/importaction/123/",
data=json.dumps({"source": "new source"}),
)

assert res.status_code == 202

def test_bulk_upload_table(self):
resp_mock = mock.MagicMock()
type(resp_mock.post()).status_code = mock.PropertyMock(return_value=201)
Expand Down
Loading