forked from forks/microblog.pub
Improve tests
This commit is contained in:
parent
1e3d9279ee
commit
166fc91c54
1 changed files with 12 additions and 2 deletions
|
@ -3,6 +3,7 @@ import os
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from html2text import html2text
|
from html2text import html2text
|
||||||
|
from utils import activitypub_utils
|
||||||
|
|
||||||
|
|
||||||
def resp2plaintext(resp):
|
def resp2plaintext(resp):
|
||||||
|
@ -18,6 +19,15 @@ class Instance(object):
|
||||||
self.docker_url = docker_url or host_url
|
self.docker_url = docker_url or host_url
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
|
|
||||||
|
def _do_req(self, url, headers):
|
||||||
|
url = url.replace(self.docker_url, self.host_url)
|
||||||
|
resp = requests.get(url, headers=headers)
|
||||||
|
resp.raise_for_status()
|
||||||
|
return resp.json()
|
||||||
|
|
||||||
|
def _parse_collection(self, payload=None, url=None):
|
||||||
|
return activitypub_utils.parse_collection(url=url, payload=payload, do_req=self._do_req)
|
||||||
|
|
||||||
def ping(self):
|
def ping(self):
|
||||||
"""Ensures the homepage is reachable."""
|
"""Ensures the homepage is reachable."""
|
||||||
resp = self.session.get(f'{self.host_url}/')
|
resp = self.session.get(f'{self.host_url}/')
|
||||||
|
@ -55,7 +65,7 @@ class Instance(object):
|
||||||
|
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
|
|
||||||
return resp.json()['first']['orderedItems']
|
return self._parse_collection(payload=data)
|
||||||
|
|
||||||
def following(self):
|
def following(self):
|
||||||
resp = self.session.get(f'{self.host_url}/following', headers={'Accept': 'application/activity+json'})
|
resp = self.session.get(f'{self.host_url}/following', headers={'Accept': 'application/activity+json'})
|
||||||
|
@ -63,7 +73,7 @@ class Instance(object):
|
||||||
|
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
|
|
||||||
return resp.json()['first']['orderedItems']
|
return self._parse_collection(payload=data)
|
||||||
|
|
||||||
def outbox(self):
|
def outbox(self):
|
||||||
resp = self.session.get(f'{self.host_url}/following', headers={'Accept': 'application/activity+json'})
|
resp = self.session.get(f'{self.host_url}/following', headers={'Accept': 'application/activity+json'})
|
||||||
|
|
Loading…
Reference in a new issue