Skip to content

Commit

Permalink
Objects can be released in batch (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Oct 18, 2024
1 parent bd88e6d commit 6de5776
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 66 deletions.
8 changes: 5 additions & 3 deletions seatsio/events/changeObjectStatusRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@


class ChangeObjectStatusRequest:
def __init__(self, object_or_objects, status, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys, allowed_previous_statuses=None, rejected_previous_statuses=None):
def __init__(self, type, object_or_objects, status, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys, allowed_previous_statuses=None, rejected_previous_statuses=None):
self.objects = self.__normalize_objects(object_or_objects)
self.type = 'CHANGE_STATUS_TO'
self.status = status
if type is not None:
self.type = type
if type is not 'RELEASE':
self.status = status
if hold_token:
self.holdToken = hold_token
if order_id:
Expand Down
13 changes: 6 additions & 7 deletions seatsio/events/eventsClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from seatsio.events.extraDataRequest import ExtraDataRequest
from seatsio.events.forSaleRequest import ForSaleRequest
from seatsio.events.overrideSeasonObjectStatusRequest import OverrideSeasonObjectStatusRequest
from seatsio.events.releaseObjectsRequest import ReleaseObjectsRequest
from seatsio.events.updateEventRequest import UpdateEventRequest
from seatsio.pagination.listableObjectsClient import ListableObjectsClient
from seatsio.pagination.lister import Lister
Expand Down Expand Up @@ -135,8 +134,8 @@ def change_best_available_object_status(self, event_key, number, status, categor

def release(self, event_key_or_keys, object_or_objects, hold_token=None, order_id=None, keep_extra_data=None,
ignore_channels=None, channel_keys=None):
request = ReleaseObjectsRequest(
object_or_objects, hold_token, order_id, event_key_or_keys,
request = ChangeObjectStatusRequest(
'RELEASE', object_or_objects, None, hold_token, order_id, event_key_or_keys,
keep_extra_data, ignore_channels, channel_keys)
return self.__do_change_status(request)

Expand All @@ -149,7 +148,7 @@ def change_object_status(self, event_key_or_keys, object_or_objects, status, hol
keep_extra_data=None, ignore_channels=None, channel_keys=None,
allowed_previous_statuses=None,
rejected_previous_statuses=None):
request = ChangeObjectStatusRequest(object_or_objects, status, hold_token, order_id, event_key_or_keys,
request = ChangeObjectStatusRequest('CHANGE_STATUS_TO', object_or_objects, status, hold_token, order_id, event_key_or_keys,
keep_extra_data, ignore_channels, channel_keys,
allowed_previous_statuses, rejected_previous_statuses)
return self.__do_change_status(request)
Expand All @@ -161,7 +160,7 @@ def __do_change_status(self, request):

def change_object_status_in_batch(self, status_change_requests):
requests = list(
map(lambda r: self.__change_object_status_in_batch_request(r.event_key, r.object_or_objects, r.status,
map(lambda r: self.__change_object_status_in_batch_request(r.type, r.event_key, r.object_or_objects, r.status,
r.hold_token, r.order_id, r.keep_extra_data,
r.ignore_channels, r.channel_keys,
r.allowed_previous_statuses,
Expand All @@ -171,10 +170,10 @@ def change_object_status_in_batch(self, status_change_requests):
query_params={"expand": "objects"}).post({"statusChanges": requests})
return list(map(lambda r: ChangeObjectStatusResult(r), response.json().get("results")))

def __change_object_status_in_batch_request(self, event_key, object_or_objects, status, hold_token, order_id,
def __change_object_status_in_batch_request(self, type, event_key, object_or_objects, status, hold_token, order_id,
keep_extra_data, ignore_channels, channel_keys,
allowed_previous_statuses, rejected_previous_statuses):
request = ChangeObjectStatusRequest(object_or_objects, status, hold_token, order_id, "", keep_extra_data,
request = ChangeObjectStatusRequest(type, object_or_objects, status, hold_token, order_id, "", keep_extra_data,
ignore_channels, channel_keys, allowed_previous_statuses,
rejected_previous_statuses)
request.event = event_key
Expand Down
42 changes: 0 additions & 42 deletions seatsio/events/releaseObjectsRequest.py

This file was deleted.

26 changes: 15 additions & 11 deletions seatsio/events/statusChangeRequest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
class StatusChangeRequest:
def __init__(self, event_key, object_or_objects, status, hold_token=None, order_id=None, keep_extra_data=None, ignore_channels=None, channel_keys=None, allowed_previous_statuses=None, rejected_previous_statuses=None):
self.event_key = event_key
self.object_or_objects = object_or_objects
self.status = status
self.hold_token = hold_token
self.order_id = order_id
self.keep_extra_data = keep_extra_data
self.ignore_channels = ignore_channels
self.channel_keys = channel_keys
self.allowed_previous_statuses = allowed_previous_statuses
self.rejected_previous_statuses = rejected_previous_statuses
TYPE_CHANGE_STATUS_TO = "CHANGE_STATUS_TO"
RELEASE = "RELEASE"

def __init__(self, event_key, object_or_objects, status=None, hold_token=None, order_id=None, keep_extra_data=None, ignore_channels=None, channel_keys=None, allowed_previous_statuses=None, rejected_previous_statuses=None, type=None):
self.type = type
self.event_key = event_key
self.object_or_objects = object_or_objects
self.status = status
self.hold_token = hold_token
self.order_id = order_id
self.keep_extra_data = keep_extra_data
self.ignore_channels = ignore_channels
self.channel_keys = channel_keys
self.allowed_previous_statuses = allowed_previous_statuses
self.rejected_previous_statuses = rejected_previous_statuses
18 changes: 15 additions & 3 deletions tests/events/testChangeObjectStatusInBatch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from seatsio import Channel
from seatsio import Channel, EventObjectInfo
from seatsio.events.statusChangeRequest import StatusChangeRequest
from seatsio.exceptions import SeatsioException
from tests.seatsioClientTest import SeatsioClientTest
Expand All @@ -14,8 +14,8 @@ def test(self):
event2 = self.client.events.create(chart_key2)

res = self.client.events.change_object_status_in_batch([
StatusChangeRequest(event1.key, ["A-1"], "lolzor"),
StatusChangeRequest(event2.key, ["A-2"], "lolzor")
StatusChangeRequest(event1.key, ["A-1"], "lolzor", type=StatusChangeRequest.TYPE_CHANGE_STATUS_TO),
StatusChangeRequest(event2.key, ["A-2"], "lolzor", type=StatusChangeRequest.TYPE_CHANGE_STATUS_TO)
])

assert_that(self.client.events.retrieve_object_info(event1.key, "A-1").status).is_equal_to("lolzor")
Expand Down Expand Up @@ -77,3 +77,15 @@ def test_reject_previous_statuses(self):
"code": "ILLEGAL_STATUS_CHANGE",
"message": "Cannot change from [free] to [lolzor]: free is in the list of rejected previous statuses"
}])

def test_release(self):
chart_key = self.create_test_chart()
event = self.client.events.create(chart_key)
self.client.events.book(event.key, ["A-1"])

res = self.client.events.change_object_status_in_batch([
StatusChangeRequest(event.key, ["A-1"], type=StatusChangeRequest.RELEASE)
])

assert_that(self.client.events.retrieve_object_info(event.key, "A-1").status).is_equal_to(EventObjectInfo.FREE)
assert_that(res[0].objects["A-1"].status).is_equal_to(EventObjectInfo.FREE)

0 comments on commit 6de5776

Please sign in to comment.