From 166fc91c54e840401c2b9637c5632dbec1a31814 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 27 May 2018 12:02:14 +0200 Subject: [PATCH] Improve tests --- tests/federation_test.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/federation_test.py b/tests/federation_test.py index 7614327..dc3d17d 100644 --- a/tests/federation_test.py +++ b/tests/federation_test.py @@ -3,6 +3,7 @@ import os import requests from html2text import html2text +from utils import activitypub_utils def resp2plaintext(resp): @@ -18,6 +19,15 @@ class Instance(object): self.docker_url = docker_url or host_url 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): """Ensures the homepage is reachable.""" resp = self.session.get(f'{self.host_url}/') @@ -55,7 +65,7 @@ class Instance(object): data = resp.json() - return resp.json()['first']['orderedItems'] + return self._parse_collection(payload=data) def following(self): resp = self.session.get(f'{self.host_url}/following', headers={'Accept': 'application/activity+json'}) @@ -63,7 +73,7 @@ class Instance(object): data = resp.json() - return resp.json()['first']['orderedItems'] + return self._parse_collection(payload=data) def outbox(self): resp = self.session.get(f'{self.host_url}/following', headers={'Accept': 'application/activity+json'})