From ea02b82f39a7e4cf8f993166bc8083ca18a0a8b0 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Thu, 19 Jan 2023 15:25:56 -0800 Subject: [PATCH] test_pages: add tests for followers/following UI pages --- tests/test_pages.py | 46 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/tests/test_pages.py b/tests/test_pages.py index 6078c0a..637ef28 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -6,8 +6,14 @@ from granary import as2, atom, microformats2, rss import common from models import Activity, Follower, User from . import testutil -from .test_activitypub import LIKE, MENTION, NOTE, REPLY - +from .test_activitypub import ( + FOLLOW_WITH_ACTOR, + FOLLOW_WITH_OBJECT, + LIKE, + MENTION, + NOTE, + REPLY, +) def contents(activities): return [a['object']['content'] for a in activities] @@ -56,10 +62,46 @@ class PagesTest(testutil.TestCase): self.assert_equals(301, got.status_code) self.assert_equals('/user/foo.com', got.headers['Location']) + def test_followers(self): + User.get_or_create('bar.com') + Follower.get_or_create('bar.com', 'https://no/stored/follow') + Follower.get_or_create('bar.com', 'https://masto/user', + last_follow=json_dumps(FOLLOW_WITH_ACTOR)) + got = self.client.get('/user/bar.com/followers') + self.assert_equals(200, got.status_code) + + body = got.get_data(as_text=True) + self.assertIn('no/stored/follow', body) + self.assertIn('masto/user', body) + + def test_followers_empty(self): + User.get_or_create('bar.com') + got = self.client.get('/user/bar.com/followers') + self.assert_equals(200, got.status_code) + self.assertNotIn('class="follower', got.get_data(as_text=True)) + def test_followers_user_not_found(self): got = self.client.get('/user/bar.com/followers') self.assert_equals(404, got.status_code) + def test_following(self): + Follower.get_or_create('https://no/stored/follow', 'bar.com') + Follower.get_or_create('https://masto/user', 'bar.com', + last_follow=json_dumps(FOLLOW_WITH_OBJECT)) + User.get_or_create('bar.com') + got = self.client.get('/user/bar.com/following') + self.assert_equals(200, got.status_code) + + body = got.get_data(as_text=True) + self.assertIn('no/stored/follow', body) + self.assertIn('masto/user', body) + + def test_following_empty(self): + User.get_or_create('bar.com') + got = self.client.get('/user/bar.com/following') + self.assert_equals(200, got.status_code) + self.assertNotIn('class="follower', got.get_data(as_text=True)) + def test_following_user_not_found(self): got = self.client.get('/user/bar.com/following') self.assert_equals(404, got.status_code)