Skip to content

Commit

Permalink
tableBookingConfig can be passed in when creating or updating an event
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Nov 2, 2020
1 parent ccdc0d3 commit 04dd446
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 73 deletions.
46 changes: 40 additions & 6 deletions seatsio/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def __init__(self, data):
self.id = data.get("id")
self.key = data.get("key")
self.chart_key = data.get("chartKey")
self.book_whole_tables = data.get("bookWholeTables")
self.table_booking_modes = data.get("tableBookingModes")
self.table_booking_config = TableBookingConfig.create(data.get("tableBookingConfig"))
self.supports_best_available = data.get("supportsBestAvailable")
self.for_sale_config = ForSaleConfig.create(data.get("forSaleConfig"))
self.created_on = parse_date(data.get("createdOn"))
Expand Down Expand Up @@ -64,6 +63,39 @@ def create(cls, param):
return ForSaleConfig(param)


class TableBookingConfig:
def __init__(self, mode, tables=None):
self.mode = mode
self.tables = tables

def __eq__(self, other):
return self.mode == other.mode and \
self.tables == other.tables

def __hash__(self):
return hash((self.mode, self.tables))

@classmethod
def inherit(cls):
return TableBookingConfig('INHERIT')

@classmethod
def all_by_table(cls):
return TableBookingConfig('ALL_BY_TABLE')

@classmethod
def all_by_seat(cls):
return TableBookingConfig('ALL_BY_SEAT')

@classmethod
def custom(cls, tables):
return TableBookingConfig('CUSTOM', tables)

@classmethod
def create(cls, data):
return TableBookingConfig(data.get("mode"), data.get("tables"))


class Channel:
def __init__(self, name, color, index, key=None, objects=None):
self.key = key
Expand Down Expand Up @@ -118,11 +150,12 @@ def fixed(cls, name, disabled_seats=[], index=0):

@classmethod
def rule_based(cls, name, number_of_disabled_seats_to_the_sides=0, disable_seats_in_front_and_behind=False,
number_of_disabled_aisle_seats=0, max_group_size=0, max_occupancy_absolute=0,
max_occupancy_percentage=0, one_group_per_table=False, disabled_seats=[], enabled_seats=[], index=0):
number_of_disabled_aisle_seats=0, max_group_size=0, max_occupancy_absolute=0,
max_occupancy_percentage=0, one_group_per_table=False, disabled_seats=[], enabled_seats=[], index=0):
return SocialDistancingRuleset(name, number_of_disabled_seats_to_the_sides, disable_seats_in_front_and_behind,
number_of_disabled_aisle_seats, max_group_size, max_occupancy_absolute,
max_occupancy_percentage, one_group_per_table, False, disabled_seats, enabled_seats, index)
max_occupancy_percentage, one_group_per_table, False, disabled_seats,
enabled_seats, index)

def __eq__(self, other):
return self.name == other.name and \
Expand All @@ -142,7 +175,8 @@ def __hash__(self):
return hash((self.name, self.number_of_disabled_seats_to_the_sides, self.disable_seats_in_front_and_behind,
self.number_of_disabled_aisle_seats,
self.max_group_size, self.max_occupancy_absolute, self.max_occupancy_percentage,
self.fixed_group_layout, self.one_group_per_table, self.disabled_seats, self.enabled_seats, self.index))
self.fixed_group_layout, self.one_group_per_table, self.disabled_seats, self.enabled_seats,
self.index))

@classmethod
def create(cls, param):
Expand Down
8 changes: 3 additions & 5 deletions seatsio/events/createSingleEventRequest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
class CreateSingleEventRequest:
def __init__(self, chart_key, event_key=None, book_whole_tables=None, table_booking_modes=None, social_distancing_ruleset_key=None):
def __init__(self, chart_key, event_key=None, table_booking_config=None, social_distancing_ruleset_key=None):
if chart_key:
self.chartKey = chart_key
if event_key:
self.eventKey = event_key
if book_whole_tables is not None:
self.bookWholeTables = book_whole_tables
if table_booking_modes is not None:
self.tableBookingModes = table_booking_modes
if table_booking_config is not None:
self.tableBookingConfig = table_booking_config
if social_distancing_ruleset_key is not None:
self.socialDistancingRulesetKey = social_distancing_ruleset_key
8 changes: 3 additions & 5 deletions seatsio/events/eventProperties.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
class EventProperties:
def __init__(self, event_key=None, book_whole_tables=None, table_booking_modes=None, social_distancing_ruleset_key=None):
def __init__(self, event_key=None, table_booking_config=None, social_distancing_ruleset_key=None):
if event_key:
self.eventKey = event_key
if book_whole_tables is not None:
self.bookWholeTables = book_whole_tables
if table_booking_modes is not None:
self.tableBookingModes = table_booking_modes
if table_booking_config is not None:
self.tableBookingConfig = table_booking_config
if social_distancing_ruleset_key is not None:
self.socialDistancingRulesetKey = social_distancing_ruleset_key
8 changes: 4 additions & 4 deletions seatsio/events/eventsClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ def __init__(self, http_client):
ListableObjectsClient.__init__(self, http_client, Event, "/events")
self.reports = EventReports(self.http_client)

def create(self, chart_key, event_key=None, book_whole_tables=None, table_booking_modes=None, social_distancing_ruleset_key=None):
def create(self, chart_key, event_key=None, table_booking_config=None, social_distancing_ruleset_key=None):
response = self.http_client.url("/events").post(
CreateSingleEventRequest(chart_key, event_key, book_whole_tables, table_booking_modes, social_distancing_ruleset_key))
CreateSingleEventRequest(chart_key, event_key, table_booking_config, social_distancing_ruleset_key))
return Event(response.json())

def create_multiple(self, chart_key, events_properties):
response = self.http_client.url("/events/actions/create-multiple").post(
CreateMultipleEventsRequest(chart_key, events_properties))
return Event.create_list(response.json().get("events"))

def update(self, key, chart_key=None, event_key=None, book_whole_tables=None, table_booking_modes=None, social_distancing_ruleset_key=None):
def update(self, key, chart_key=None, event_key=None, table_booking_config=None, social_distancing_ruleset_key=None):
self.http_client.url("/events/{key}", key=key).post(
CreateSingleEventRequest(chart_key, event_key, book_whole_tables, table_booking_modes, social_distancing_ruleset_key))
CreateSingleEventRequest(chart_key, event_key, table_booking_config, social_distancing_ruleset_key))

def delete(self, key):
self.http_client.url("/events/{key}", key=key).delete()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='seatsio',
version='v55.0.0',
version='v56.0.0',
description='The official Seats.io Python client library',
author='The seats.io dev team',
author_email='[email protected]',
Expand Down
20 changes: 5 additions & 15 deletions tests/events/createEventTest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime

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

Expand All @@ -14,7 +14,7 @@ def test_chart_key_is_required(self):
assert_that(event.id).is_not_zero()
assert_that(event.key).is_not_none()
assert_that(event.chart_key).is_equal_to(chart_key)
assert_that(event.book_whole_tables).is_false()
assert_that(event.table_booking_config).is_equal_to(TableBookingConfig.inherit())
assert_that(event.supports_best_available).is_true()
assert_that(event.for_sale_config).is_none()
assert_that(event.created_on).is_between_now_minus_and_plus_minutes(datetime.utcnow(), 1)
Expand All @@ -26,25 +26,15 @@ def test_event_key_is_optional(self):
event = self.client.events.create(chart.key, event_key="eventje")

assert_that(event.key).is_equal_to("eventje")
assert_that(event.book_whole_tables).is_false()

def test_book_whole_tables_is_optional(self):
chart = self.client.charts.create()

event = self.client.events.create(chart.key, book_whole_tables=True)

assert_that(event.key).is_not_blank()
assert_that(event.book_whole_tables).is_true()

def test_table_booking_modes_is_optional(self):
chart_key = self.create_test_chart_with_tables()
table_booking_modes = {"T1": "BY_TABLE", "T2": "BY_SEAT"}
table_booking_config = TableBookingConfig.custom({"T1": "BY_TABLE", "T2": "BY_SEAT"})

event = self.client.events.create(chart_key, table_booking_modes=table_booking_modes)
event = self.client.events.create(chart_key, table_booking_config=table_booking_config)

assert_that(event.key).is_not_blank()
assert_that(event.book_whole_tables).is_false()
assert_that(event.table_booking_modes).is_equal_to(table_booking_modes)
assert_that(event.table_booking_config).is_equal_to(table_booking_config)

def test_social_distancing_ruleset_key_is_optional(self):
chart_key = self.create_test_chart()
Expand Down
24 changes: 8 additions & 16 deletions tests/events/createEventsTest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime

from seatsio import SocialDistancingRuleset
from seatsio import SocialDistancingRuleset, TableBookingConfig
from seatsio.events.eventProperties import EventProperties
from seatsio.exceptions import SeatsioException
from tests.seatsioClientTest import SeatsioClientTest
Expand All @@ -23,7 +23,7 @@ def test_single_event(self):
assert_that(event.id).is_not_zero()
assert_that(event.key).is_not_none()
assert_that(event.chart_key).is_equal_to(chart_key)
assert_that(event.book_whole_tables).is_false()
assert_that(event.table_booking_config).is_equal_to(TableBookingConfig.inherit())
assert_that(event.supports_best_available).is_none()
assert_that(event.for_sale_config).is_none()
assert_that(event.created_on).is_between_now_minus_and_plus_minutes(datetime.utcnow(), 1)
Expand All @@ -36,24 +36,16 @@ def test_event_key_can_be_passed_in(self):
])
assert_that(events).extracting("key").contains_exactly_in_any_order("event1", "event2")

def test_book_whole_tables_can_be_passed_in(self):
chart_key = self.create_test_chart()
events = self.client.events.create_multiple(chart_key, [
EventProperties(book_whole_tables=True), EventProperties(book_whole_tables=False)
])
assert_that(events).extracting("book_whole_tables").contains_exactly(True, False)

def test_table_booking_modes_can_be_passed_in(self):
def test_table_booking_config_can_be_passed_in(self):
chart_key = self.create_test_chart_with_tables()
events = self.client.events.create_multiple(chart_key, [
EventProperties(table_booking_modes={"T1": "BY_TABLE", "T2": "BY_SEAT"}),
EventProperties(table_booking_modes={"T1": "BY_SEAT", "T2": "BY_TABLE"})
EventProperties(table_booking_config=TableBookingConfig.custom({"T1": "BY_TABLE", "T2": "BY_SEAT"})),
EventProperties(table_booking_config=TableBookingConfig.custom({"T1": "BY_SEAT", "T2": "BY_TABLE"}))
])

assert_that(events).extracting("book_whole_tables").contains_exactly(False, False)
assert_that(events).extracting("table_booking_modes").contains_exactly(
{"T1": "BY_TABLE", "T2": "BY_SEAT"},
{"T1": "BY_SEAT", "T2": "BY_TABLE"}
assert_that(events).extracting("table_booking_config").contains_exactly(
TableBookingConfig.custom({"T1": "BY_TABLE", "T2": "BY_SEAT"}),
TableBookingConfig.custom({"T1": "BY_SEAT", "T2": "BY_TABLE"})
)

def test_social_distancing_ruleset_key_can_be_passed_in(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/events/retrieveEventTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime

from seatsio import TableBookingConfig
from tests.seatsioClientTest import SeatsioClientTest
from tests.util.asserts import assert_that

Expand All @@ -15,7 +16,7 @@ def test(self):
assert_that(retrieved_event.id).is_not_zero()
assert_that(retrieved_event.key).is_not_none()
assert_that(retrieved_event.chart_key).is_equal_to(chart_key)
assert_that(retrieved_event.book_whole_tables).is_false()
assert_that(retrieved_event.table_booking_config).is_equal_to(TableBookingConfig.inherit())
assert_that(retrieved_event.supports_best_available).is_true()
assert_that(retrieved_event.for_sale_config).is_none()
assert_that(retrieved_event.created_on).is_between_now_minus_and_plus_minutes(datetime.utcnow(), 1)
Expand Down
24 changes: 4 additions & 20 deletions tests/events/updateEventTest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime

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

Expand Down Expand Up @@ -30,30 +30,14 @@ def test_updateEventKey(self):
assert_that(retrieved_event.id).is_equal_to(event.id)
assert_that(retrieved_event.updated_on).is_between_now_minus_and_plus_minutes(datetime.utcnow(), 1)

def test_updateBookWholeTables(self):
chart = self.client.charts.create()
event = self.client.events.create(chart.key)

self.client.events.update(event.key, book_whole_tables=True)

retrieved_event = self.client.events.retrieve(event.key)
assert_that(retrieved_event.book_whole_tables).is_true()
assert_that(retrieved_event.updated_on).is_between_now_minus_and_plus_minutes(datetime.utcnow(), 1)

self.client.events.update(event.key, book_whole_tables=False)

retrieved_event = self.client.events.retrieve(event.key)
assert_that(retrieved_event.book_whole_tables).is_false()
assert_that(retrieved_event.updated_on).is_between_now_minus_and_plus_minutes(datetime.utcnow(), 1)

def test_updateTableBookingModes(self):
chart_key = self.create_test_chart_with_tables()
event = self.client.events.create(chart_key, table_booking_modes={"T1": "BY_TABLE"})
event = self.client.events.create(chart_key, table_booking_config=TableBookingConfig.custom({"T1": "BY_TABLE"}))

self.client.events.update(event.key, table_booking_modes={"T1": "BY_SEAT"})
self.client.events.update(event.key, table_booking_config=TableBookingConfig.custom({"T1": "BY_SEAT"}))

retrieved_event = self.client.events.retrieve(event.key)
assert_that(retrieved_event.table_booking_modes).is_equal_to({"T1": "BY_SEAT"})
assert_that(retrieved_event.table_booking_config).is_equal_to(TableBookingConfig.custom({"T1": "BY_SEAT"}))
assert_that(retrieved_event.updated_on).is_between_now_minus_and_plus_minutes(datetime.utcnow(), 1)

def test_updateSocialDistancingRulesetKey(self):
Expand Down

0 comments on commit 04dd446

Please sign in to comment.