Skip to content

Commit

Permalink
Added method to list event log items (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Jan 17, 2024
1 parent 37d4837 commit 8bbd6f6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
2 changes: 2 additions & 0 deletions seatsio/client.py
@@ -1,4 +1,5 @@
from seatsio.charts.chartsClient import ChartsClient
from seatsio.eventlog.eventLogClient import EventLogClient
from seatsio.events.eventsClient import EventsClient
from seatsio.holdtokens.HoldTokenClient import HoldTokensClient
from seatsio.httpClient import HttpClient
Expand All @@ -18,3 +19,4 @@ def __init__(self, region, secret_key, workspace_key=None, max_retries=5):
self.workspaces = WorkspacesClient(self.http_client)
self.hold_tokens = HoldTokensClient(self.http_client)
self.usage_reports = UsageReports(self.http_client)
self.event_log = EventLogClient(self.http_client)
40 changes: 28 additions & 12 deletions seatsio/domain.py
Expand Up @@ -29,17 +29,17 @@ def __init__(self, data):

class Category:

def __init__(self, key, label, color, accessible = False):
def __init__(self, key, label, color, accessible=False):
self.key = key
self.label = label
self.color = color
self.accessible = accessible

def __eq__(self, other):
return self.key == other.key and \
self.label == other.label and \
self.color == other.color and \
self.accessible == other.accessible
self.label == other.label and \
self.color == other.color and \
self.accessible == other.accessible

def __hash__(self):
return hash((self.key, self.label, self.color, self.accessible))
Expand Down Expand Up @@ -116,9 +116,9 @@ def __init__(self, data):

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
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))
Expand All @@ -142,14 +142,15 @@ def to_json(self):
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):
self.mode = mode
self.tables = tables

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

def __hash__(self):
return hash((self.mode, self.tables))
Expand Down Expand Up @@ -191,10 +192,10 @@ def __init__(self, name, color, index, key=None, objects=None):

def __eq__(self, other):
return self.key == other.key and \
self.name == other.name and \
self.color == other.color and \
self.index == other.index and \
self.objects == other.objects
self.name == other.name and \
self.color == other.color and \
self.index == other.index and \
self.objects == other.objects

def __hash__(self):
return hash((self.key, self.name, self.color, self.index, self.objects))
Expand Down Expand Up @@ -400,6 +401,21 @@ def create(cls, param):
return Workspace(param)


class EventLogItem:

def __init__(self, data):
self.id = data.get("id")
self.workspace_key = data.get("workspaceKey")
self.type = data.get("type")
self.date = parse_date(data.get("date"))
self.data = data.get("data")

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


class HoldToken:

def __init__(self, data):
Expand Down
Empty file added seatsio/eventlog/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions seatsio/eventlog/eventLogClient.py
@@ -0,0 +1,8 @@
from seatsio.domain import EventLogItem
from seatsio.pagination.listableObjectsClient import ListableObjectsClient


class EventLogClient(ListableObjectsClient):

def __init__(self, http_client):
ListableObjectsClient.__init__(self, http_client, EventLogItem, "/event-log")
30 changes: 30 additions & 0 deletions tests/eventLog/testListEventLogItems.py
@@ -0,0 +1,30 @@
import time

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


class ListEventLogItems(SeatsioClientTest):

def test(self):
chart = self.client.charts.create()
self.client.charts.update(chart.key, 'a chart')

time.sleep(2)

event_log_items = self.client.event_log.list()

assert_that(event_log_items).extracting("type").contains_exactly("chart.created", "chart.published")

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

time.sleep(2)

event_log_item = self.client.event_log.list().current()

assert_that(event_log_item.id > 0).is_true()
assert_that(event_log_item.type).is_equal_to("chart.created")
assert_that(event_log_item.workspace_key).is_equal_to(self.workspace.key)
assert_that(event_log_item.date).is_not_none()
assert_that(event_log_item.data).is_equal_to({"key": chart.key})

0 comments on commit 8bbd6f6

Please sign in to comment.