2024-05-16 18:27:06 +00:00
|
|
|
from pprint import pprint
|
2024-05-16 19:11:02 +00:00
|
|
|
from time import sleep
|
2024-05-16 18:27:06 +00:00
|
|
|
import requests
|
2024-05-16 19:11:02 +00:00
|
|
|
from .fixtures import ensure_follow, msg_inc, sign
|
2024-05-14 19:23:37 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
def test_actor(client, actor_url):
|
|
|
|
resp = client.get(actor_url, headers={"Content-Type": "application/activity+json"})
|
|
|
|
assert resp.status_code == 200
|
|
|
|
data = resp.json()
|
|
|
|
assert "id" in data
|
|
|
|
assert "type" in data
|
|
|
|
assert "inbox" in data
|
|
|
|
assert "outbox" in data
|
|
|
|
assert "followers" in data
|
|
|
|
assert "preferredUsername" in data
|
|
|
|
assert "publicKey" in data
|
|
|
|
assert len(data["publicKey"])
|
|
|
|
|
|
|
|
pubKey = data["publicKey"]
|
|
|
|
assert "id" in pubKey
|
|
|
|
assert "owner" in pubKey
|
|
|
|
assert "publicKeyPem" in pubKey
|
|
|
|
|
|
|
|
assert pubKey["owner"] == data["id"]
|
|
|
|
assert pubKey["id"] != data["id"]
|
|
|
|
assert "-----BEGIN RSA PUBLIC KEY-----" in pubKey["publicKeyPem"]
|
2024-05-16 18:27:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_following(client, inbox_url, followers_url, actor_url):
|
2024-05-16 19:11:02 +00:00
|
|
|
with msg_inc(1):
|
|
|
|
req = sign(
|
|
|
|
"POST",
|
|
|
|
inbox_url,
|
|
|
|
{
|
|
|
|
"@context": "https://www.w3.org/ns/activitystreams",
|
|
|
|
"id": "http://mock_masto:8000/d0b5768b-a15b-4ed6-bc84-84c7e2b57588",
|
|
|
|
"type": "Follow",
|
|
|
|
"actor": "http://mock_masto:8000/users/h4kor",
|
|
|
|
"object": actor_url,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
resp = requests.Session().send(req)
|
2024-05-16 18:27:06 +00:00
|
|
|
|
2024-05-16 19:11:02 +00:00
|
|
|
assert resp.status_code == 200
|
2024-05-16 18:27:06 +00:00
|
|
|
|
2024-05-16 19:11:02 +00:00
|
|
|
resp = client.get(
|
|
|
|
followers_url, headers={"Content-Type": "application/activity+json"}
|
|
|
|
)
|
|
|
|
assert resp.status_code == 200
|
|
|
|
data = resp.json()
|
|
|
|
pprint(data)
|
|
|
|
assert "items" in data
|
|
|
|
assert len(data["items"]) == 1
|
2024-05-16 18:27:06 +00:00
|
|
|
|
|
|
|
|
2024-05-16 19:11:02 +00:00
|
|
|
def test_unfollow(client, inbox_url, followers_url, actor_url):
|
|
|
|
ensure_follow(client, inbox_url, actor_url)
|
|
|
|
with msg_inc(1):
|
|
|
|
req = sign(
|
|
|
|
"POST",
|
|
|
|
inbox_url,
|
|
|
|
{
|
|
|
|
"@context": "https://www.w3.org/ns/activitystreams",
|
|
|
|
"id": "http://mock_masto:8000/users/h4kor#follows/3632040/undo",
|
|
|
|
"type": "Undo",
|
|
|
|
"actor": "http://mock_masto:8000/users/h4kor",
|
|
|
|
"object": {
|
|
|
|
"id": "http://mock_masto:8000/d0b5768b-a15b-4ed6-bc84-84c7e2b57588",
|
|
|
|
"type": "Follow",
|
|
|
|
"actor": "http://mock_masto:8000/users/h4kor",
|
|
|
|
"object": actor_url,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
resp = requests.Session().send(req)
|
|
|
|
assert resp.status_code == 200
|
2024-05-16 18:27:06 +00:00
|
|
|
|
2024-05-16 19:11:02 +00:00
|
|
|
resp = client.get(
|
|
|
|
followers_url, headers={"Content-Type": "application/activity+json"}
|
|
|
|
)
|
|
|
|
assert resp.status_code == 200
|
|
|
|
data = resp.json()
|
|
|
|
pprint(data)
|
|
|
|
assert "totalItems" in data
|
|
|
|
assert data["totalItems"] == 0
|