added begins_before

This commit is contained in:
Simone Robutti 2021-05-04 12:07:59 +02:00
parent 821f2a6435
commit e938ba709b
2 changed files with 30 additions and 0 deletions

View File

@ -1,3 +1,4 @@
from __future__ import annotations
from dataclasses import dataclass, asdict
from datetime import datetime
from typing import Optional
@ -18,6 +19,9 @@ class MobilizonEvent:
thumbnail_link: Optional[str] = None
location: Optional[str] = None
def begins_before(self, other: MobilizonEvent) -> bool:
return self.begin_datetime < other.begin_datetime
def _fill_template(self, pattern: Template) -> str:
return pattern.render(**asdict(self))

View File

@ -40,3 +40,29 @@ def test_format(event, simple_template):
event.format(simple_template)
== "test event|description of the event|location|2021-01-01, 11:30"
)
def test_is_newer():
older_event = MobilizonEvent(
name="test event",
description="description of the event",
begin_datetime=datetime(year=2021, month=1, day=1, hour=11, minute=30),
end_datetime=datetime(year=2021, month=1, day=1, hour=12, minute=30),
last_accessed=datetime.now(),
mobilizon_link="http://some_link.com/123",
mobilizon_id="12345",
thumbnail_link="http://some_link.com/123.jpg",
location="location",
)
newer_event = MobilizonEvent(
name="test event",
description="description of the event",
begin_datetime=datetime(year=2021, month=1, day=2, hour=11, minute=30),
end_datetime=datetime(year=2021, month=1, day=1, hour=12, minute=30),
last_accessed=datetime.now(),
mobilizon_link="http://some_link.com/123",
mobilizon_id="12345",
thumbnail_link="http://some_link.com/123.jpg",
location="location",
)
assert older_event.begins_before(newer_event)