Make `Event.mobilizon_id` a proper `UUIDField`. (#59)

This fixes #38.

Co-authored-by: Giacomo Leidi <goodoldpaul@autistici.org>
This commit is contained in:
tinoilcotechino 2021-08-29 14:51:52 +02:00 committed by GitHub
parent 489e3d66ad
commit 09124b6358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 27 additions and 19 deletions

View File

@ -1,6 +1,7 @@
from dataclasses import dataclass, asdict
from enum import IntEnum
from typing import Optional, Set
from uuid import UUID
import arrow
import tortoise.timezone
@ -26,7 +27,7 @@ class MobilizonEvent:
begin_datetime: arrow.Arrow
end_datetime: arrow.Arrow
mobilizon_link: str
mobilizon_id: str
mobilizon_id: UUID
thumbnail_link: Optional[str] = None
location: Optional[str] = None
publication_time: Optional[dict[str, arrow.Arrow]] = None

View File

@ -2,6 +2,7 @@ import json
import logging
from http import HTTPStatus
from typing import List, Optional
from uuid import UUID
import arrow
import requests
@ -35,7 +36,7 @@ def parse_event(data):
begin_datetime=arrow.get(data["beginsOn"]) if "beginsOn" in data else None,
end_datetime=arrow.get(data["endsOn"]) if "endsOn" in data else None,
mobilizon_link=data.get("url", None),
mobilizon_id=data["uuid"],
mobilizon_id=UUID(data["uuid"]),
thumbnail_link=parse_picture(data),
location=parse_location(data),
publication_time=None,

View File

@ -7,7 +7,7 @@ class Event(Model):
name = fields.TextField()
description = fields.TextField(null=True)
mobilizon_id = fields.TextField()
mobilizon_id = fields.UUIDField()
mobilizon_link = fields.TextField()
thumbnail_link = fields.TextField(null=True)

View File

@ -1,5 +1,6 @@
import os
from datetime import datetime, timedelta, timezone
from uuid import UUID
import arrow
import pytest
@ -34,7 +35,7 @@ def event_generator():
begin_date=arrow.Arrow(year=2021, month=1, day=1, hour=11, minute=30),
published=False,
publication_time=None,
mobilizon_id="12345",
mobilizon_id=UUID(int=12345),
):
return MobilizonEvent(
@ -72,7 +73,7 @@ def event() -> MobilizonEvent:
begin_datetime=begin_date,
end_datetime=begin_date.shift(hours=1),
mobilizon_link="http://some_link.com/123",
mobilizon_id="12345",
mobilizon_id=UUID(int=12345),
thumbnail_link="http://some_link.com/123.jpg",
location="location",
)
@ -110,7 +111,7 @@ def event_model_generator():
return Event(
name=f"event_{idx}",
description=f"desc_{idx}",
mobilizon_id=f"mobid_{idx}",
mobilizon_id=UUID(int=idx),
mobilizon_link=f"moblink_{idx}",
thumbnail_link=f"thumblink_{idx}",
location=f"loc_{idx}",

View File

@ -1,3 +1,5 @@
from uuid import UUID
import arrow
import pytest
@ -54,7 +56,7 @@ simple_event = MobilizonEvent(
begin_datetime=arrow.get("2021-05-23T12:15:00Z"),
end_datetime=arrow.get("2021-05-23T15:15:00Z"),
mobilizon_link="https://some_mobilizon/events/1e2e5943-4a5c-497a-b65d-90457b715d7b",
mobilizon_id="1e2e5943-4a5c-497a-b65d-90457b715d7b",
mobilizon_id=UUID("1e2e5943-4a5c-497a-b65d-90457b715d7b"),
thumbnail_link=None,
location=None,
)
@ -65,7 +67,7 @@ full_event = MobilizonEvent(
begin_datetime=arrow.get("2021-05-25T15:15:00+00:00]"),
end_datetime=arrow.get("2021-05-25T16:15:00+00:00"),
mobilizon_link="https://some_mobilizon/events/56e7ca43-1b6b-4c50-8362-0439393197e6",
mobilizon_id="56e7ca43-1b6b-4c50-8362-0439393197e6",
mobilizon_id=UUID("56e7ca43-1b6b-4c50-8362-0439393197e6"),
thumbnail_link=None,
location="http://some_location",
)

View File

@ -1,4 +1,5 @@
from datetime import datetime, timedelta, timezone
from uuid import UUID
import arrow
import pytest
@ -100,7 +101,7 @@ async def test_mobilizon_event_to_model(event):
assert event_db.begin_datetime == begin_date_utc
assert event_db.end_datetime == begin_date_utc + timedelta(hours=1)
assert event_db.mobilizon_link == "http://some_link.com/123"
assert event_db.mobilizon_id == "12345"
assert event_db.mobilizon_id == UUID(int=12345)
assert event_db.thumbnail_link == "http://some_link.com/123.jpg"
assert event_db.location == "location"
@ -145,7 +146,7 @@ async def test_mobilizon_event_from_model(
assert event.begin_datetime == begin_date_utc
assert event.end_datetime == begin_date_utc.shift(hours=2)
assert event.mobilizon_link == "moblink_1"
assert event.mobilizon_id == "mobid_1"
assert event.mobilizon_id == UUID(int=1)
assert event.thumbnail_link == "thumblink_1"
assert event.location == "loc_1"
assert event.publication_time[publisher_model.name] == publication.timestamp

View File

@ -1,4 +1,5 @@
from datetime import datetime, timedelta
from uuid import UUID
import pytest
@ -18,7 +19,7 @@ def test_event():
"begin_datetime": now,
"end_datetime": now + timedelta(hours=1),
"mobilizon_link": "",
"mobilizon_id": "",
"mobilizon_id": UUID(int=0),
}
)

View File

@ -32,7 +32,7 @@ async def _generate_events(specification):
id=UUID(int=i),
name=f"event_{i}",
description=f"desc_{i}",
mobilizon_id=f"mobid_{i}",
mobilizon_id=UUID(int=i),
mobilizon_link=f"moblink_{i}",
thumbnail_link=f"thumblink_{i}",
location=f"loc_{i}",

View File

@ -1,4 +1,5 @@
from datetime import timedelta
from uuid import UUID
import arrow
import pytest
@ -56,7 +57,7 @@ async def test_get_published_events(generate_models):
MobilizonEvent(
name="event_3",
description="desc_3",
mobilizon_id="mobid_3",
mobilizon_id=UUID(int=3),
mobilizon_link="moblink_3",
thumbnail_link="thumblink_3",
location="loc_3",
@ -87,7 +88,7 @@ async def test_get_unpublished_events(specification, expected_result, generate_m
Event(
name="event_1",
description="desc_1",
mobilizon_id="mobid_1",
mobilizon_id=UUID(int=101112),
mobilizon_link="moblink_1",
thumbnail_link="thumblink_1",
location="loc_1",
@ -97,7 +98,7 @@ async def test_get_unpublished_events(specification, expected_result, generate_m
Event(
name="test event",
description="description of the event",
mobilizon_id="12345",
mobilizon_id=UUID(int=12345),
mobilizon_link="http://some_link.com/123",
thumbnail_link="http://some_link.com/123.jpg",
location="location",
@ -107,7 +108,7 @@ async def test_get_unpublished_events(specification, expected_result, generate_m
Event(
name="test event",
description="description of the event",
mobilizon_id="67890",
mobilizon_id=UUID(int=67890),
mobilizon_link="http://some_link.com/123",
thumbnail_link="http://some_link.com/123.jpg",
location="location",
@ -126,7 +127,7 @@ async def test_create_unpublished_events(
await generate_models(complete_specification)
event_3 = event_generator(begin_date=arrow.get(today + timedelta(days=6)))
event_4 = event_generator(
begin_date=arrow.get(today + timedelta(days=12)), mobilizon_id="67890"
begin_date=arrow.get(today + timedelta(days=12)), mobilizon_id=UUID(int=67890)
)
models = await prefetch_event_relations(Event.filter(name="event_1"))
@ -209,7 +210,7 @@ async def test_get_publishers(
],
[
PublicationStatus.WAITING,
"mobid_1",
UUID(int=1),
None,
None,
[result_publication[3], result_publication[4]],

View File

@ -88,7 +88,7 @@ async def test_update_publishers(
MobilizonEvent(
name="event_1",
description="desc_1",
mobilizon_id="mobid_1",
mobilizon_id=UUID(int=1),
mobilizon_link="moblink_1",
thumbnail_link="thumblink_1",
location="loc_1",