121 lines
3.7 KiB
Python
121 lines
3.7 KiB
Python
from uuid import UUID
|
|
|
|
import arrow
|
|
import pytest
|
|
|
|
from mobilizon_reshare.dataclasses import MobilizonEvent
|
|
from mobilizon_reshare.mobilizon.events import (
|
|
get_mobilizon_future_events,
|
|
MobilizonRequestFailed,
|
|
)
|
|
|
|
simple_event_element = {
|
|
"beginsOn": "2021-05-23T12:15:00Z",
|
|
"description": None,
|
|
"endsOn": "2021-05-23T15:15:00Z",
|
|
"onlineAddress": None,
|
|
"options": {"showEndTime": True, "showStartTime": True},
|
|
"physicalAddress": None,
|
|
"picture": None,
|
|
"title": "test event",
|
|
"url": "https://some_mobilizon/events/1e2e5943-4a5c-497a-b65d-90457b715d7b",
|
|
"uuid": "1e2e5943-4a5c-497a-b65d-90457b715d7b",
|
|
"updatedAt": "2021-05-23T12:15:00Z",
|
|
}
|
|
simple_event_response = {
|
|
"data": {"group": {"organizedEvents": {"elements": [simple_event_element]}}}
|
|
}
|
|
|
|
full_event_element = {
|
|
"beginsOn": "2021-05-25T15:15:00Z",
|
|
"description": "<p>a description</p>",
|
|
"endsOn": "2021-05-25T16:15:00Z",
|
|
"onlineAddress": "http://some_location",
|
|
"options": {"showEndTime": True, "showStartTime": True},
|
|
"physicalAddress": None,
|
|
"picture": None,
|
|
"title": "full event",
|
|
"url": "https://some_mobilizon/events/56e7ca43-1b6b-4c50-8362-0439393197e6",
|
|
"uuid": "56e7ca43-1b6b-4c50-8362-0439393197e6",
|
|
"updatedAt": "2021-05-25T15:15:00Z",
|
|
}
|
|
full_event_response = {
|
|
"data": {"group": {"organizedEvents": {"elements": [full_event_element]}}}
|
|
}
|
|
|
|
two_events_response = {
|
|
"data": {
|
|
"group": {
|
|
"organizedEvents": {"elements": [simple_event_element, full_event_element]}
|
|
}
|
|
}
|
|
}
|
|
|
|
simple_event = MobilizonEvent(
|
|
name="test event",
|
|
description=None,
|
|
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=UUID("1e2e5943-4a5c-497a-b65d-90457b715d7b"),
|
|
thumbnail_link=None,
|
|
location=None,
|
|
last_update_time=arrow.get("2021-05-23T12:15:00Z"),
|
|
)
|
|
|
|
full_event = MobilizonEvent(
|
|
name="full event",
|
|
description="<p>a description</p>",
|
|
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=UUID("56e7ca43-1b6b-4c50-8362-0439393197e6"),
|
|
thumbnail_link=None,
|
|
location="http://some_location",
|
|
last_update_time=arrow.get("2021-05-25T15:15:00+00:00"),
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"mobilizon_answer, expected_result",
|
|
[
|
|
[{"data": {"group": {"organizedEvents": {"elements": []}}}}, []],
|
|
[simple_event_response, [simple_event]],
|
|
[full_event_response, [full_event]],
|
|
[two_events_response, [simple_event, full_event]],
|
|
],
|
|
)
|
|
def test_event_response(mock_mobilizon_success_answer, expected_result):
|
|
"""
|
|
Testing the request and parsing logic
|
|
"""
|
|
assert get_mobilizon_future_events() == expected_result
|
|
|
|
|
|
def test_failure_404(mock_mobilizon_failure_answer):
|
|
with pytest.raises(MobilizonRequestFailed):
|
|
get_mobilizon_future_events()
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"mobilizon_answer",
|
|
[
|
|
{
|
|
"data": {"group": None},
|
|
"errors": [
|
|
{
|
|
"code": "group_not_found",
|
|
"field": None,
|
|
"locations": [{"column": 13, "line": 2}],
|
|
"message": "Group not found",
|
|
"path": ["group"],
|
|
"status_code": 404,
|
|
}
|
|
],
|
|
},
|
|
],
|
|
)
|
|
def test_failure_wrong_group(mock_mobilizon_success_answer):
|
|
with pytest.raises(MobilizonRequestFailed):
|
|
get_mobilizon_future_events()
|