comparison tests/unit/test_ap-gateway.py @ 4285:f1d0cde61af7

tests (unit): fix tests + black reformatting.
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2024 17:42:53 +0200
parents 49019947cc76
children
comparison
equal deleted inserted replaced
4284:3a550e9a2b55 4285:f1d0cde61af7
716 assert first_item["@context"] == ["https://www.w3.org/ns/activitystreams"] 716 assert first_item["@context"] == ["https://www.w3.org/ns/activitystreams"]
717 assert ( 717 assert (
718 first_item["id"] == "https://test.example/_ap/item/some_user@test.example/4" 718 first_item["id"] == "https://test.example/_ap/item/some_user@test.example/4"
719 ) 719 )
720 assert ( 720 assert (
721 first_item["actor"] 721 first_item["actor"] == "https://test.example/_ap/actor/some_user@test.example"
722 == "https://test.example/_ap/actor/some_user@test.example"
723 ) 722 )
724 assert first_item["type"] == "Create" 723 assert first_item["type"] == "Create"
725 first_item_obj = first_item["object"] 724 first_item_obj = first_item["object"]
726 assert first_item_obj["id"] == first_item["id"] 725 assert first_item_obj["id"] == first_item["id"]
727 assert first_item_obj["type"] == "Note" 726 assert first_item_obj["type"] == "Note"
801 following = await ap_gateway.server.resource.ap_following_request( 800 following = await ap_gateway.server.resource.ap_following_request(
802 **self.ap_request_params(ap_gateway, "following") 801 **self.ap_request_params(ap_gateway, "following")
803 ) 802 )
804 assert following["@context"] == ["https://www.w3.org/ns/activitystreams"] 803 assert following["@context"] == ["https://www.w3.org/ns/activitystreams"]
805 assert ( 804 assert (
806 following["id"] 805 following["id"] == "https://test.example/_ap/following/some_user@test.example"
807 == "https://test.example/_ap/following/some_user@test.example"
808 ) 806 )
809 assert following["totalItems"] == len(subscriptions) 807 assert following["totalItems"] == len(subscriptions)
810 assert following["type"] == "OrderedCollection" 808 assert following["type"] == "OrderedCollection"
811 assert following.get("first") 809 assert following.get("first")
812 810
839 followers = await ap_gateway.server.resource.ap_followers_request( 837 followers = await ap_gateway.server.resource.ap_followers_request(
840 **self.ap_request_params(ap_gateway, "followers") 838 **self.ap_request_params(ap_gateway, "followers")
841 ) 839 )
842 assert followers["@context"] == ["https://www.w3.org/ns/activitystreams"] 840 assert followers["@context"] == ["https://www.w3.org/ns/activitystreams"]
843 assert ( 841 assert (
844 followers["id"] 842 followers["id"] == "https://test.example/_ap/followers/some_user@test.example"
845 == "https://test.example/_ap/followers/some_user@test.example"
846 ) 843 )
847 assert followers["totalItems"] == len(subscribers) 844 assert followers["totalItems"] == len(subscribers)
848 assert followers["type"] == "OrderedCollection" 845 assert followers["type"] == "OrderedCollection"
849 assert followers.get("first") 846 assert followers.get("first")
850 847
1396 ) 1393 )
1397 1394
1398 assert ap_post.called 1395 assert ap_post.called
1399 url, actor_id, doc = ap_post.call_args.args 1396 url, actor_id, doc = ap_post.call_args.args
1400 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"] 1397 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"]
1401 assert actor_id == ap_gateway.build_apurl(ap_const.TYPE_ACTOR, TEST_JID.userhost()) 1398 assert actor_id == ap_gateway.build_apurl(
1399 ap_const.TYPE_ACTOR, TEST_JID.userhost()
1400 )
1402 assert doc["type"] == "Announce" 1401 assert doc["type"] == "Announce"
1403 assert ap_const.NS_AP_PUBLIC in doc["to"] 1402 assert ap_const.NS_AP_PUBLIC in doc["to"]
1404 assert doc["object"] == ap_item["id"] 1403 assert doc["object"] == ap_item["id"]
1405 1404
1406 @ed 1405 @ed
1432 get_items.return_value = ([mock_pubsub_item], {}) 1431 get_items.return_value = ([mock_pubsub_item], {})
1433 with patch.object( 1432 with patch.object(
1434 ap_gateway.host.memory.storage, "cache_pubsub_items" 1433 ap_gateway.host.memory.storage, "cache_pubsub_items"
1435 ) as cache_pubsub_items: 1434 ) as cache_pubsub_items:
1436 await ap_gateway.server.resource.handle_announce_activity( 1435 await ap_gateway.server.resource.handle_announce_activity(
1437 TEST_AP_ACTOR_ID, Request(MagicMock()), announce, None, None, None, 1436 TEST_AP_ACTOR_ID,
1438 "", TEST_AP_ACTOR_ID 1437 Request(MagicMock()),
1438 announce,
1439 None,
1440 None,
1441 None,
1442 "",
1443 TEST_AP_ACTOR_ID,
1439 ) 1444 )
1440 1445
1441 assert cache_pubsub_items.called 1446 assert cache_pubsub_items.called
1442 # the microblog data put in cache correspond to the item sent to subscribers 1447 # the microblog data put in cache correspond to the item sent to subscribers
1443 __, __, __, [mb_data] = cache_pubsub_items.call_args.args 1448 __, __, __, [mb_data] = cache_pubsub_items.call_args.args
1444 extra = mb_data["extra"] 1449 extra = mb_data["extra"]
1445 assert "repeated" in extra 1450 assert "repeated" in extra
1446 repeated = extra["repeated"] 1451 repeated = extra["repeated"]
1447 assert repeated["by"] == ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT).full() 1452 assert (
1453 repeated["by"]
1454 == ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT).full()
1455 )
1448 xmpp_item_xmpp_url = xmpp_uri.build_xmpp_uri( 1456 xmpp_item_xmpp_url = xmpp_uri.build_xmpp_uri(
1449 "pubsub", 1457 "pubsub",
1450 path=TEST_JID.full(), 1458 path=TEST_JID.full(),
1451 node=ap_gateway._m.namespace, 1459 node=ap_gateway._m.namespace,
1452 item=xmpp_item["id"], 1460 item=xmpp_item["id"],
1485 await ap_gateway._items_received(ap_gateway.client, items_event) 1493 await ap_gateway._items_received(ap_gateway.client, items_event)
1486 1494
1487 assert ap_post.called 1495 assert ap_post.called
1488 url, actor_id, doc = ap_post.call_args.args 1496 url, actor_id, doc = ap_post.call_args.args
1489 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"] 1497 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"]
1490 assert actor_id == ap_gateway.build_apurl(ap_const.TYPE_ACTOR, TEST_JID.userhost()) 1498 assert actor_id == ap_gateway.build_apurl(
1499 ap_const.TYPE_ACTOR, TEST_JID.userhost()
1500 )
1491 assert doc["type"] == "Like" 1501 assert doc["type"] == "Like"
1492 assert ap_const.NS_AP_PUBLIC in doc["cc"] 1502 assert ap_const.NS_AP_PUBLIC in doc["cc"]
1493 assert doc["object"] == ap_item["id"] 1503 assert doc["object"] == ap_item["id"]
1494 1504
1495 @ed 1505 @ed
1746 assert event_data["start"] == 1664222400 1756 assert event_data["start"] == 1664222400
1747 assert event_data["end"] == 1664226000 1757 assert event_data["end"] == 1664226000
1748 assert event_data["head-picture"] == { 1758 assert event_data["head-picture"] == {
1749 "sources": [{"url": "https://example.org/head_picture.jpg"}] 1759 "sources": [{"url": "https://example.org/head_picture.jpg"}]
1750 } 1760 }
1751 assert event_data["descriptions"] == [{ 1761 assert event_data["descriptions"] == [
1752 "description": "<p>meeting for test</p>", "type": "xhtml" 1762 {"description": "<p>meeting for test</p>", "type": "xhtml"}
1753 }] 1763 ]
1754 assert event_data["categories"] == [{"term": "test"}] 1764 assert event_data["categories"] == [{"term": "test"}]
1755 assert event_data["locations"] == [{"description": "somewhere in the world"}] 1765 assert event_data["locations"] == [{"description": "somewhere in the world"}]
1756 assert event_data["rsvp"] == [ 1766 assert event_data["rsvp"] == [
1757 { 1767 {
1758 "fields": [ 1768 "fields": [