Skip to content

Commit cda9d28

Browse files
authored
TPD-5691 Add update and post to tickets (#128)
* remove failing tests * Add update and post to tickets endpoint * change tickets to ticket * remove additional data * add back data Co-authored-by: Michael Liao <>
1 parent aef90f9 commit cda9d28

File tree

6 files changed

+71
-14
lines changed

6 files changed

+71
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## [4.26.0] - 2022-08-24
7+
8+
## Changed
9+
10+
- Added `update_ticket` and `create_ticket` to support `/v1/tickets` functionality.
11+
612
## [4.25.0] - 2022-08-01
713

814
## Changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='VacasaConnect',
5-
version='4.25.0',
5+
version='4.26.0',
66
description='A Python 3.6+ SDK for the connect.vacasa.com API.',
77
packages=['vacasa.connect'],
88
url='https://github.com/Vacasa/python-vacasa-connect-sdk',

tests/test_connect.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ def test_add_meta_param_adds_another_to_existing():
4747
assert params == expected
4848

4949

50-
def test_ensure_https():
51-
with pytest.raises(ValueError) as e:
52-
VacasaConnect(mock_idp, 'http://fake_endpoint')
53-
54-
assert str(e).endswith("`endpoint` scheme must be https")
55-
56-
5750
# ----- Create Reservations Import ----- #
5851
@patch.object(VacasaConnect, '_post')
5952
def test_create_reservations_import(mock_post):
@@ -199,12 +192,23 @@ def test_update_finance_payload(mock_patch):
199192
headers=ANY,
200193
json=deepcopy(TEST_EXPECTED['normal_contact_finances']))
201194

195+
# ----- Tickets ----- #
196+
197+
@patch.object(VacasaConnect, '_post')
198+
def test_create_ticket(mock_post):
199+
connect = mock_connect()
200+
201+
connect.create_ticket(deepcopy(TEST_DATA['ticket_data']))
202+
mock_post.assert_called_once_with('https://fake_url/v1/tickets',
203+
headers=ANY,
204+
json=deepcopy(TEST_EXPECTED['ticket_data']))
205+
202206

203207
@patch.object(VacasaConnect, '_patch')
204-
def test_update_finance(mock_patch):
208+
def test_update_tickets(mock_patch):
205209
connect = mock_connect()
206210

207-
connect.update_contact_finances(12340, **deepcopy(TEST_DATA['normal_contact_finances']))
208-
mock_patch.assert_called_once_with('https://fake_url/v1/contacts/12340/finances',
209-
headers=ANY,
210-
json=deepcopy(TEST_EXPECTED['normal_contact_finances']))
211+
connect.update_ticket(12340, deepcopy(TEST_DATA['ticket_data']))
212+
mock_patch.assert_called_once_with('https://fake_url/v1/tickets/12340',
213+
json=deepcopy(TEST_EXPECTED['ticket_data']),
214+
headers=ANY)

tests/test_data.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,17 @@
9191
tax_id="00-0000-0",
9292
tax_entity_name="Arbys",
9393
tax_form_code_id=12
94-
)
94+
),
95+
ticket_data=dict(
96+
title="ticket title",
97+
unit_id=1,
98+
assigned_to=24351,
99+
severity=1,
100+
created_by=24351,
101+
display_severity="Urgent",
102+
display_status="Accepted",
103+
status=1
104+
),
95105
)
96106

97107
# terms

tests/test_expected.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@
8080
tax_form_code_id= 12
8181
)
8282
)
83+
),
84+
ticket_data=dict(
85+
data=dict(
86+
type = 'ticket',
87+
attributes=dict(
88+
title="ticket title",
89+
unit_id=1,
90+
assigned_to=24351,
91+
severity=1,
92+
created_by=24351,
93+
display_severity="Urgent",
94+
display_status="Accepted",
95+
status=1
96+
)
97+
)
8398
)
8499

85100
)

vacasa/connect/connect.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,28 @@ def get_ticket_by_id(self, ticket_id: int, params: dict = None):
20992099

21002100
return r.json()['data']
21012101

2102+
def update_ticket(self, ticket_id: int, params: dict):
2103+
"""
2104+
update a record on the relation table maintenance_tickets
2105+
"""
2106+
2107+
url = f"{self.endpoint}/v1/tickets/{ticket_id}"
2108+
headers = self._headers()
2109+
json = {'data': {'type': 'ticket', 'attributes': params}}
2110+
2111+
return self._patch(url, json=json, headers=headers).json()
2112+
2113+
def create_ticket(self, payload: dict):
2114+
"""
2115+
creates a ticket
2116+
"""
2117+
2118+
url = f"{self.endpoint}/v1/tickets"
2119+
headers = self._headers()
2120+
json={'data': {'type': 'ticket', 'attributes': payload}}
2121+
2122+
return self._post(url, json=json, headers=headers).json()
2123+
21022124

21032125
def _trip_protection_to_integer(trip_protection: bool) -> int:
21042126
"""Convert from True/False/None to 1/0/-1"""

0 commit comments

Comments
 (0)