Skip to content

Commit

Permalink
Change object status calls return labels
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Jun 4, 2018
1 parent a55f858 commit d33ffc0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
6 changes: 6 additions & 0 deletions seatsio/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,9 @@ class BestAvailableObjects:
def __init__(self, data):
self.next_to_each_other = data.get("nextToEachOther")
self.objects = data.get("objects")
self.labels = data.get("labels")


class ChangeObjectStatusResult:
def __init__(self, data):
self.labels = data.get("labels")
11 changes: 6 additions & 5 deletions seatsio/events/eventsClient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from seatsio.domain import Event, StatusChange, ObjectStatus, BestAvailableObjects
from seatsio.domain import Event, StatusChange, ObjectStatus, BestAvailableObjects, ChangeObjectStatusResult
from seatsio.events.changeBestAvailableObjectStatusRequest import ChangeBestAvailableObjectStatusRequest
from seatsio.events.changeObjectStatusRequest import ChangeObjectStatusRequest
from seatsio.events.eventReports import EventReports
Expand Down Expand Up @@ -37,7 +37,7 @@ def status_changes_for_object(self, key, object_id):
return PageFetcher(StatusChange, self.http_client, url, key=key, objectId=object_id)

def book(self, event_key_or_keys, object_or_objects, hold_token=None, order_id=None):
self.change_object_status(event_key_or_keys, object_or_objects, ObjectStatus.BOOKED, hold_token, order_id)
return self.change_object_status(event_key_or_keys, object_or_objects, ObjectStatus.BOOKED, hold_token, order_id)

def book_best_available(self, event_key, number, categories=None, hold_token=None, order_id=None):
return self.change_best_available_object_status(
Expand Down Expand Up @@ -73,14 +73,15 @@ def change_best_available_object_status(
return BestAvailableObjects(response.json())

def release(self, event_key_or_keys, object_or_objects, hold_token=None, order_id=None):
self.change_object_status(event_key_or_keys, object_or_objects, ObjectStatus.FREE, hold_token, order_id)
return self.change_object_status(event_key_or_keys, object_or_objects, ObjectStatus.FREE, hold_token, order_id)

def hold(self, event_key_or_keys, object_or_objects, hold_token, order_id=None):
self.change_object_status(event_key_or_keys, object_or_objects, ObjectStatus.HELD, hold_token, order_id)
return self.change_object_status(event_key_or_keys, object_or_objects, ObjectStatus.HELD, hold_token, order_id)

def change_object_status(self, event_key_or_keys, object_or_objects, status, hold_token=None, order_id=None):
request = ChangeObjectStatusRequest(object_or_objects, status, hold_token, order_id, event_key_or_keys)
self.http_client.url("/seasons/actions/change-object-status").post(request)
response = self.http_client.url("/seasons/actions/change-object-status", query_params={"expand": "labels"}).post(request)
return ChangeObjectStatusResult(response.json())

def retrieve_object_status(self, key, object_key):
return self.http_client.url("/events/{key}/objects/{object}", key=key, object=object_key).get_as(ObjectStatus)
Expand Down
4 changes: 3 additions & 1 deletion tests/events/bookObjectsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test(self):
chart_key = self.create_test_chart()
event = self.client.events.create(chart_key)

self.client.events.book(event.key, ["A-1", "A-2"])
res = self.client.events.book(event.key, ["A-1", "A-2"])

a1_status = self.client.events.retrieve_object_status(event.key, "A-1").status
a2_status = self.client.events.retrieve_object_status(event.key, "A-2").status
Expand All @@ -19,6 +19,8 @@ def test(self):
assert_that(a2_status).is_equal_to(ObjectStatus.BOOKED)
assert_that(a3_status).is_equal_to(ObjectStatus.FREE)

assert_that(res.labels).is_equal_to({"A-1": {"own": "1", "row": "A"}, "A-2": {"own": "2", "row": "A"}})

def test_withHoldToken(self):
chart_key = self.create_test_chart()
event = self.client.events.create(chart_key)
Expand Down
6 changes: 6 additions & 0 deletions tests/events/changeBestAvailableObjectStatusTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def test_number(self):
assert_that(result.next_to_each_other).is_true()
assert_that(result.objects).contains_exactly("B-4", "B-5", "B-6")

def test_labels(self):
chart_key = self.create_test_chart()
event = self.client.events.create(chart_key)
result = self.client.events.change_best_available_object_status(event.key, 2, "myStatus")
assert_that(result.labels).is_equal_to({"B-4": {"own": "4", "row": "B"}, "B-5": {"own": "5", "row": "B"}})

def test_categories(self):
chart_key = self.create_test_chart()
event = self.client.events.create(chart_key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ def test(self):
chart_key = self.create_test_chart()
event = self.client.events.create(chart_key)

self.client.events.change_object_status(event.key, ["A-1", "A-2"], "status_foo")
res = self.client.events.change_object_status(event.key, ["A-1", "A-2"], "status_foo")

assert_that(self.client.events.retrieve_object_status(event.key, "A-1").status).is_equal_to("status_foo")
assert_that(self.client.events.retrieve_object_status(event.key, "A-2").status).is_equal_to("status_foo")
assert_that(self.client.events.retrieve_object_status(event.key, "A-3").status).is_equal_to("free")
assert_that(res.labels).is_equal_to({"A-1": {"own": "1", "row": "A"}, "A-2": {"own": "2", "row": "A"}})

def test_hold_token(self):
chart_key = self.create_test_chart()
Expand Down
4 changes: 3 additions & 1 deletion tests/events/holdObjectsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_withHoldToken(self):
event = self.client.events.create(chart_key)
hold_token = self.client.hold_tokens.create()

self.client.events.hold(event.key, ["A-1", "A-2"], hold_token.hold_token)
res = self.client.events.hold(event.key, ["A-1", "A-2"], hold_token.hold_token)

status1 = self.client.events.retrieve_object_status(event.key, "A-1")
assert_that(status1.status).is_equal_to(ObjectStatus.HELD)
Expand All @@ -20,6 +20,8 @@ def test_withHoldToken(self):
assert_that(status2.status).is_equal_to(ObjectStatus.HELD)
assert_that(status2.hold_token).is_equal_to(hold_token.hold_token)

assert_that(res.labels).is_equal_to({"A-1": {"own": "1", "row": "A"}, "A-2": {"own": "2", "row": "A"}})

def test_withOrderId(self):
chart_key = self.create_test_chart()
event = self.client.events.create(chart_key)
Expand Down
4 changes: 3 additions & 1 deletion tests/events/releaseObjectsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test(self):
event = self.client.events.create(chart_key)
self.client.events.book(event.key, ["A-1", "A-2"])

self.client.events.release(event.key, ["A-1", "A-2"])
res = self.client.events.release(event.key, ["A-1", "A-2"])

a1_status = self.client.events.retrieve_object_status(event.key, "A-1").status
a2_status = self.client.events.retrieve_object_status(event.key, "A-2").status
Expand All @@ -20,6 +20,8 @@ def test(self):
assert_that(a2_status).is_equal_to(ObjectStatus.FREE)
assert_that(a3_status).is_equal_to(ObjectStatus.FREE)

assert_that(res.labels).is_equal_to({"A-1": {"own": "1", "row": "A"}, "A-2": {"own": "2", "row": "A"}})

def test_withHoldToken(self):
chart_key = self.create_test_chart()
event = self.client.events.create(chart_key)
Expand Down

0 comments on commit d33ffc0

Please sign in to comment.