Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sessions, updates and config better #25

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/zinolib/controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
def __init__(self, session=None):
self.session = session
self.events = {}
self.removed_ids = set()

def _get_event(self, event_or_id: EventOrId) -> Event:
if isinstance(event_or_id, Event):
Expand All @@ -29,12 +30,27 @@
return self.events[event_or_id]
raise ValueError("Unknown type")

def _get_event_id(self, event_or_id: EventOrId) -> int:
if isinstance(event_or_id, int):
return event_or_id
if isinstance(event_or_id, Event):
return event_or_id.id
raise ValueError("Unknown type")

Check warning on line 38 in src/zinolib/controllers/base.py

View check run for this annotation

Codecov / codecov/patch

src/zinolib/controllers/base.py#L36-L38

Added lines #L36 - L38 were not covered by tests

def _set_event(self, event: Event):
self.events[event.id] = event

def check_session(self):
def remove_event(self, event_or_id: EventOrId):
event_id = self._get_event_id(event_or_id)
self.events.pop(event_id)
self.removed_ids.add(event_id)

def _verify_session(self, quiet=False):
if not self.session:
if quiet:
return False

Check warning on line 51 in src/zinolib/controllers/base.py

View check run for this annotation

Codecov / codecov/patch

src/zinolib/controllers/base.py#L51

Added line #L51 was not covered by tests
raise ValueError # raise correct error
return True

Check warning on line 53 in src/zinolib/controllers/base.py

View check run for this annotation

Codecov / codecov/patch

src/zinolib/controllers/base.py#L53

Added line #L53 was not covered by tests

def set_history_for_event(self, event_or_id: EventOrId, history_list: List[HistoryEntry]) -> Event:
event = self._get_event(event_or_id)
Expand Down
Loading
Loading