diff --git a/seatsio/domain.py b/seatsio/domain.py index 1872828..8bce250 100644 --- a/seatsio/domain.py +++ b/seatsio/domain.py @@ -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")) @@ -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 @@ -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 \ @@ -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): diff --git a/seatsio/events/createSingleEventRequest.py b/seatsio/events/createSingleEventRequest.py index b4bf2e0..ef8e4e1 100644 --- a/seatsio/events/createSingleEventRequest.py +++ b/seatsio/events/createSingleEventRequest.py @@ -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 diff --git a/seatsio/events/eventProperties.py b/seatsio/events/eventProperties.py index c4353cd..25bcb99 100644 --- a/seatsio/events/eventProperties.py +++ b/seatsio/events/eventProperties.py @@ -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 diff --git a/seatsio/events/eventsClient.py b/seatsio/events/eventsClient.py index ea692f7..17e772b 100644 --- a/seatsio/events/eventsClient.py +++ b/seatsio/events/eventsClient.py @@ -18,9 +18,9 @@ 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): @@ -28,9 +28,9 @@ def create_multiple(self, chart_key, events_properties): 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() diff --git a/setup.py b/setup.py index c79f200..847b909 100644 --- a/setup.py +++ b/setup.py @@ -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='hello@seats.io', diff --git a/tests/events/createEventTest.py b/tests/events/createEventTest.py index 844cfcf..97f69ee 100644 --- a/tests/events/createEventTest.py +++ b/tests/events/createEventTest.py @@ -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 @@ -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) @@ -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() diff --git a/tests/events/createEventsTest.py b/tests/events/createEventsTest.py index 294d827..3fa0d2d 100644 --- a/tests/events/createEventsTest.py +++ b/tests/events/createEventsTest.py @@ -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 @@ -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) @@ -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): diff --git a/tests/events/retrieveEventTest.py b/tests/events/retrieveEventTest.py index 222637f..bd33514 100644 --- a/tests/events/retrieveEventTest.py +++ b/tests/events/retrieveEventTest.py @@ -1,5 +1,6 @@ from datetime import datetime +from seatsio import TableBookingConfig from tests.seatsioClientTest import SeatsioClientTest from tests.util.asserts import assert_that @@ -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) diff --git a/tests/events/updateEventTest.py b/tests/events/updateEventTest.py index fe89a46..bfc9b4d 100644 --- a/tests/events/updateEventTest.py +++ b/tests/events/updateEventTest.py @@ -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 @@ -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):