Skip to content

Commit

Permalink
Allow for-sale config to be specified when events and seasons are cre…
Browse files Browse the repository at this point in the history
…ated (#63)

Co-authored-by: Steve Chaloner <steve@seats.io>
schaloner and Steve Chaloner authored Oct 16, 2023
1 parent ac6f054 commit 86fac7a
Showing 8 changed files with 64 additions and 8 deletions.
22 changes: 22 additions & 0 deletions seatsio/domain.py
Original file line number Diff line number Diff line change
@@ -113,11 +113,33 @@ def __init__(self, data):
self.area_places = data.get("areaPlaces")
self.categories = data.get("categories")

def __eq__(self, other):
return self.for_sale == other.for_sale and \
self.objects == other.objects and \
self.area_places == other.area_places and \
self.categories == other.categories

def __hash__(self):
return hash((self.for_sale, self.objects, self.area_places, self.categories))

@classmethod
def create(cls, param):
if param is not None:
return ForSaleConfig(param)

def to_json(self):
json = {"forSale": self.for_sale}
if self.objects is not None:
json["objects"] = self.objects
if self.area_places is not None:
json["areaPlaces"] = self.area_places
if self.categories is not None:
json["categories"] = self.categories
return json

@classmethod
def create_new(cls, for_sale, objects=None, area_places=None, categories=None):
return ForSaleConfig({"forSale": for_sale, "objects": objects, "areaPlaces": area_places, "categories": categories})

class TableBookingConfig:
def __init__(self, mode, tables=None):
4 changes: 3 additions & 1 deletion seatsio/events/createSingleEventRequest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CreateSingleEventRequest:
def __init__(self, chart_key, event_key=None, name=None, date=None, table_booking_config=None,
object_categories=None, categories=None, channels=None):
object_categories=None, categories=None, channels=None, for_sale_config=None):
if chart_key:
self.chartKey = chart_key
if event_key:
@@ -17,4 +17,6 @@ def __init__(self, chart_key, event_key=None, name=None, date=None, table_bookin
self.categories = categories
if channels is not None:
self.channels = channels
if for_sale_config is not None:
self.forSaleConfig = for_sale_config.to_json()

4 changes: 3 additions & 1 deletion seatsio/events/eventProperties.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class EventProperties:
def __init__(self, event_key=None, name=None, date=None, table_booking_config=None, object_categories=None, categories=None, channels=None):
def __init__(self, event_key=None, name=None, date=None, table_booking_config=None, object_categories=None, categories=None, channels=None, for_sale_config=None):
if event_key:
self.eventKey = event_key
if name:
@@ -14,3 +14,5 @@ def __init__(self, event_key=None, name=None, date=None, table_booking_config=No
self.categories = categories
if channels is not None:
self.channels = channels
if for_sale_config is not None:
self.forSaleConfig = for_sale_config.to_json()
4 changes: 2 additions & 2 deletions seatsio/events/eventsClient.py
Original file line number Diff line number Diff line change
@@ -24,10 +24,10 @@ def __init__(self, http_client):
self.channels = ChannelsClient(self.http_client)

def create(self, chart_key, event_key=None, name=None, date=None, table_booking_config=None,
object_categories=None, categories=None, channels=None):
object_categories=None, categories=None, channels=None, for_sale_config=None):
response = self.http_client.url("/events").post(
CreateSingleEventRequest(chart_key, event_key, name, date, table_booking_config,
object_categories, categories, channels))
object_categories, categories, channels, for_sale_config))
return Event(response.json())

def create_multiple(self, chart_key, events_properties):
4 changes: 3 additions & 1 deletion seatsio/seasons/seasonsClient.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ def __init__(self, http_client, seatsio_client):
self.http_client = http_client
self.seatsio_client = seatsio_client

def create(self, chart_key, key=None, number_of_events=None, event_keys=None, table_booking_config=None, channels=None):
def create(self, chart_key, key=None, number_of_events=None, event_keys=None, table_booking_config=None, channels=None, for_sale_config=None):
request = {}
if chart_key:
request['chartKey'] = chart_key
@@ -21,6 +21,8 @@ def create(self, chart_key, key=None, number_of_events=None, event_keys=None, ta
request['tableBookingConfig'] = table_booking_config.to_json()
if channels is not None:
request['channels'] = channels
if for_sale_config is not None:
request['forSaleConfig'] = for_sale_config.to_json()

response = self.http_client.url("/seasons").post(request)
return Season(response.json())
10 changes: 9 additions & 1 deletion tests/events/testCreateEvent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, date

from seatsio import TableBookingConfig, Category, Channel
from seatsio import TableBookingConfig, Category, Channel, ForSaleConfig
from tests.seatsioClientTest import SeatsioClientTest
from tests.util.asserts import assert_that

@@ -90,3 +90,11 @@ def test_channels_are_optional(self):
event = self.client.events.create(chart_key, channels=channels)

assert_that(event.channels).is_equal_to(channels)

def test_for_sale_config_is_optional(self):
chart_key = self.create_test_chart()
for_sale_config = ForSaleConfig.create_new(False, ["A-1", "A-2"], {"GA1": 5}, ["Cat1"])

event = self.client.events.create(chart_key, for_sale_config=for_sale_config)

assert_that(event.for_sale_config).is_equal_to(for_sale_config)
14 changes: 13 additions & 1 deletion tests/events/testCreateEvents.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, date

from seatsio import TableBookingConfig, Category, Channel
from seatsio import TableBookingConfig, Category, Channel, ForSaleConfig
from seatsio.events.eventProperties import EventProperties
from seatsio.exceptions import SeatsioException
from tests.seatsioClientTest import SeatsioClientTest
@@ -106,3 +106,15 @@ def test_channel_can_be_passed_in(self):
])

assert_that(events).extracting("channels").contains_exactly(channels)

def test_for_sale_config_can_be_passed_in(self):
chart_key = self.create_test_chart()
for_sale_config_1 = ForSaleConfig.create_new(False, ["A-1"], {"GA1": 3}, ["Cat1"])
for_sale_config_2 = ForSaleConfig.create_new(False, ["A-2"], {"GA1": 7}, ["Cat1"])

events = self.client.events.create_multiple(chart_key, [
EventProperties(for_sale_config=for_sale_config_1),
EventProperties(for_sale_config=for_sale_config_2)
])

assert_that(events).extracting("for_sale_config").contains_exactly(for_sale_config_1, for_sale_config_2)
10 changes: 9 additions & 1 deletion tests/seasons/testCreateSeason.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime

from seatsio import TableBookingConfig, Channel
from seatsio import TableBookingConfig, Channel, ForSaleConfig
from tests.seatsioClientTest import SeatsioClientTest
from tests.util.asserts import assert_that

@@ -66,3 +66,11 @@ def test_channels_are_optional(self):
season = self.client.seasons.create(chart_key, channels=channels)

assert_that(season.channels).is_equal_to(channels)

def test_for_sale_config_optional(self):
chart_key = self.create_test_chart()
for_sale_config = ForSaleConfig.create_new(False, ["A-1", "A-2"], {"GA1": 5}, ["Cat1"])

season = self.client.seasons.create(chart_key, for_sale_config=for_sale_config)

assert_that(season.for_sale_config).is_equal_to(for_sale_config)

0 comments on commit 86fac7a

Please sign in to comment.