Mercurial > libervia-backend
changeset 3908:d43b197735d1
tests (unit/AP gateway): add tests for events:
rel 372
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 22 Sep 2022 00:01:48 +0200 |
parents | 755920bd30da |
children | 3c3275a6dc8f |
files | tests/unit/test_ap-gateway.py |
diffstat | 1 files changed, 133 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/unit/test_ap-gateway.py Thu Sep 22 00:01:48 2022 +0200 +++ b/tests/unit/test_ap-gateway.py Thu Sep 22 00:01:48 2022 +0200 @@ -686,7 +686,7 @@ outbox = await ap_gateway.server.resource.APOutboxRequest( **self.ap_request_params(ap_gateway, "outbox") ) - assert outbox["@context"] == ["https://www.w3.org/ns/activitystreams"] + assert outbox["@context"] == ["https://www.w3.org/ns/activitystreams"] assert outbox["id"] == "https://test.example/_ap/outbox/some_user%40test.example" assert outbox["totalItems"] == len(XMPP_ITEMS) assert outbox["type"] == "OrderedCollection" @@ -793,7 +793,7 @@ following = await ap_gateway.server.resource.APFollowingRequest( **self.ap_request_params(ap_gateway, "following") ) - assert following["@context"] == ["https://www.w3.org/ns/activitystreams"] + assert following["@context"] == ["https://www.w3.org/ns/activitystreams"] assert ( following["id"] == "https://test.example/_ap/following/some_user%40test.example" @@ -831,7 +831,7 @@ followers = await ap_gateway.server.resource.APFollowersRequest( **self.ap_request_params(ap_gateway, "followers") ) - assert followers["@context"] == ["https://www.w3.org/ns/activitystreams"] + assert followers["@context"] == ["https://www.w3.org/ns/activitystreams"] assert ( followers["id"] == "https://test.example/_ap/followers/some_user%40test.example" @@ -865,7 +865,7 @@ assert url == "https://example.org/users/test_user/inbox" assert actor_id == "https://test.example/_ap/actor/some_user%40test.example" obj = doc["object"] - assert doc["@context"] == ["https://www.w3.org/ns/activitystreams"] + assert doc["@context"] == ["https://www.w3.org/ns/activitystreams"] assert doc["actor"] == "https://test.example/_ap/actor/some_user%40test.example" assert obj["type"] == "Note" assert obj["content"] == "This is a test message." @@ -1629,3 +1629,132 @@ assert parsed_item["from"] == si_client.jid.full() assert "reactions" in parsed_item assert parsed_item["reactions"]["reactions"] == ["🐅"] + + @ed + async def test_xmpp_event_2_ap_event(self, ap_gateway): + """XMPP events are converted to AP events""" + # we use internal event data + event_data = { + "id": "event_123", + "name": {"": "test event"}, + "start": 1664222400.0, + "end": 1664226000.0, + "head-picture": { + "sources": [{"url": "https://example.org/head_picture.jpg"}] + }, + "descriptions": [{"description": "meeting for test", "type": "text"}], + "categories": [{"term": "test", "wikidata_id": "Q1003030"}], + "locations": [{"description": "somewhere in the world"}], + "rsvp": [ + { + "fields": [ + { + "type": "list-single", + "name": "attending", + "label": "Attending", + "options": [ + {"value": "maybe", "label": "maybe"}, + {"value": "yes", "label": "yes"}, + {"value": "no", "label": "no"}, + ], + } + ], + "namespace": "urn:xmpp:events:rsvp:0", + } + ], + "extra": { + "status": "confirmed", + }, + } + + ap_item = await ap_gateway.ap_events.event_data_2_ap_item(event_data, TEST_JID) + ap_object = ap_item["object"] + actor_id = ( + "https://test.example/_ap/actor/" + "___urn.3Axmpp.3Aevents.3A0---some_user%40test.example" + ) + event_id = ( + "https://test.example/_ap/item/" + "___urn.3Axmpp.3Aevents.3A0---some_user%40test.example/event_123" + ) + assert ap_object["name"] == "test event" + assert ap_object["actor"] == actor_id + assert ap_object["attributedTo"] == actor_id + assert ap_object["type"] == "Event" + assert ap_object["startTime"] == "2022-09-26T20:00:00Z" + assert ap_object["endTime"] == "2022-09-26T21:00:00Z" + assert ap_object["id"] == event_id + assert ap_object["url"] == event_id + assert ap_object["attachment"] == [ + { + "name": "Banner", + "type": "Document", + "mediaType": "image/jpeg", + "url": "https://example.org/head_picture.jpg", + } + ] + assert ap_object["content"] == "<p>meeting for test</p>" + assert ap_object["tag"] == [{"name": "#test", "type": "Hashtag"}] + assert ap_object["location"] == {"name": "somewhere in the world"} + assert ap_object["ical:status"] == "CONFIRMED" + assert ap_item["type"] == "Create" + + @ed + async def test_ap_event_2_xmpp_event(self, ap_gateway): + """AP events are converted to XMPP events""" + test_actor = "___urn.3Axmpp.3Aevents.3A0---some_user%40test.example" + ap_object = { + "actor": f"https://test.example/_ap/actor/{test_actor}", + "attachment": [ + { + "mediaType": "image/jpeg", + "name": "Banner", + "type": "Document", + "url": "https://example.org/head_picture.jpg", + } + ], + "attributedTo": f"https://test.example/_ap/actor/{test_actor}", + "content": "<p>meeting for test</p>", + "endTime": "2022-09-26T21:00:00Z", + "ical:status": "CONFIRMED", + "id": f"https://test.example/_ap/item/{test_actor}/event_123", + "location": {"name": "somewhere in the world"}, + "name": "test event", + "startTime": "2022-09-26T20:00:00Z", + "tag": [{"name": "#test", "type": "Hashtag"}], + "to": ["https://www.w3.org/ns/activitystreams#Public"], + "type": "Event", + "url": f"https://test.example/_ap/item/{test_actor}/event_123", + } + + event_data = await ap_gateway.ap_events.ap_item_2_event_data(ap_object) + + assert event_data["id"] == ap_object["id"] + assert event_data["name"] == {"": "test event"} + assert event_data["start"] == 1664222400 + assert event_data["end"] == 1664226000 + assert event_data["head-picture"] == { + "sources": [{"url": "https://example.org/head_picture.jpg"}] + } + assert event_data["descriptions"] == [{ + "description": "<p>meeting for test</p>", "type": "xhtml" + }] + assert event_data["categories"] == [{"term": "test"}] + assert event_data["locations"] == [{"description": "somewhere in the world"}] + assert event_data["rsvp"] == [ + { + "fields": [ + { + "label": "Attending", + "name": "attending", + "options": [ + {"label": "yes", "value": "yes"}, + {"label": "no", "value": "no"}, + ], + "required": True, + "type": "list-single", + } + ] + } + ] + assert event_data["extra"] == {"status": "confirmed"}