owl-blogs/e2e_tests/conftest.py

50 lines
1.1 KiB
Python
Raw Permalink Normal View History

2024-05-14 19:23:37 +00:00
import pytest
from requests import Session
from urllib.parse import urljoin
from tests.fixtures import ACCT_NAME
class LiveServerSession(Session):
def __init__(self, base_url=None):
super().__init__()
self.base_url = base_url
def request(self, method, url, *args, **kwargs):
joined_url = urljoin(self.base_url, url)
return super().request(method, joined_url, *args, **kwargs)
@pytest.fixture
def client():
return LiveServerSession("http://localhost:3000")
@pytest.fixture
def actor_url(client):
resp = client.get(f"/.well-known/webfinger?resource={ACCT_NAME}")
data = resp.json()
self_link = [x for x in data["links"] if x["rel"] == "self"][0]
return self_link["href"]
@pytest.fixture
2024-05-16 18:27:06 +00:00
def actor(client, actor_url):
2024-05-14 19:23:37 +00:00
resp = client.get(actor_url, headers={"Content-Type": "application/activity+json"})
assert resp.status_code == 200
return resp.json()
@pytest.fixture
2024-05-16 18:27:06 +00:00
def inbox_url(actor):
2024-05-14 19:23:37 +00:00
return actor["inbox"]
@pytest.fixture
2024-05-16 18:27:06 +00:00
def outbox_url(actor):
2024-05-14 19:23:37 +00:00
return actor["outbox"]
@pytest.fixture
2024-05-16 18:27:06 +00:00
def followers_url(actor):
2024-05-14 19:23:37 +00:00
return actor["followers"]