From 694de44f3f0eeb0860d3c1706a73ff11efb1ca6e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 16 Oct 2020 14:04:06 -0700 Subject: [PATCH] reorganize incoming/outgoing tests --- bookwyrm/tests/incoming/__init__.py | 1 + .../test_favorite.py} | 3 +- .../test_follow.py} | 4 +- .../test_follow_accept.py} | 2 - bookwyrm/tests/outgoing/__init__.py | 1 + bookwyrm/tests/outgoing/test_follow.py | 37 +++++++++++++++++++ 6 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 bookwyrm/tests/incoming/__init__.py rename bookwyrm/tests/{test_incoming_favorite.py => incoming/test_favorite.py} (95%) rename bookwyrm/tests/{test_incoming_follow.py => incoming/test_follow.py} (96%) rename bookwyrm/tests/{test_incoming_follow_accept.py => incoming/test_follow_accept.py} (95%) create mode 100644 bookwyrm/tests/outgoing/__init__.py create mode 100644 bookwyrm/tests/outgoing/test_follow.py diff --git a/bookwyrm/tests/incoming/__init__.py b/bookwyrm/tests/incoming/__init__.py new file mode 100644 index 000000000..b6e690fd5 --- /dev/null +++ b/bookwyrm/tests/incoming/__init__.py @@ -0,0 +1 @@ +from . import * diff --git a/bookwyrm/tests/test_incoming_favorite.py b/bookwyrm/tests/incoming/test_favorite.py similarity index 95% rename from bookwyrm/tests/test_incoming_favorite.py rename to bookwyrm/tests/incoming/test_favorite.py index 035021452..eeba9000a 100644 --- a/bookwyrm/tests/test_incoming_favorite.py +++ b/bookwyrm/tests/incoming/test_favorite.py @@ -6,7 +6,6 @@ from bookwyrm import models, incoming class Favorite(TestCase): - ''' not too much going on in the books model but here we are ''' def setUp(self): self.remote_user = models.User.objects.create_user( 'rat', 'rat@rat.com', 'ratword', @@ -25,7 +24,7 @@ class Favorite(TestCase): ) datafile = pathlib.Path(__file__).parent.joinpath( - 'data/ap_user.json' + '../data/ap_user.json' ) self.user_data = json.loads(datafile.read_bytes()) diff --git a/bookwyrm/tests/test_incoming_follow.py b/bookwyrm/tests/incoming/test_follow.py similarity index 96% rename from bookwyrm/tests/test_incoming_follow.py rename to bookwyrm/tests/incoming/test_follow.py index b5fbec008..51ab3c43a 100644 --- a/bookwyrm/tests/test_incoming_follow.py +++ b/bookwyrm/tests/incoming/test_follow.py @@ -1,11 +1,9 @@ -import json from django.test import TestCase from bookwyrm import models, incoming -class Follow(TestCase): - ''' not too much going on in the books model but here we are ''' +class IncomingFollow(TestCase): def setUp(self): self.remote_user = models.User.objects.create_user( 'rat', 'rat@rat.com', 'ratword', diff --git a/bookwyrm/tests/test_incoming_follow_accept.py b/bookwyrm/tests/incoming/test_follow_accept.py similarity index 95% rename from bookwyrm/tests/test_incoming_follow_accept.py rename to bookwyrm/tests/incoming/test_follow_accept.py index c30dc2486..ba88bb40d 100644 --- a/bookwyrm/tests/test_incoming_follow_accept.py +++ b/bookwyrm/tests/incoming/test_follow_accept.py @@ -1,11 +1,9 @@ -import json from django.test import TestCase from bookwyrm import models, incoming class IncomingFollowAccept(TestCase): - ''' not too much going on in the books model but here we are ''' def setUp(self): self.remote_user = models.User.objects.create_user( 'rat', 'rat@rat.com', 'ratword', diff --git a/bookwyrm/tests/outgoing/__init__.py b/bookwyrm/tests/outgoing/__init__.py new file mode 100644 index 000000000..b6e690fd5 --- /dev/null +++ b/bookwyrm/tests/outgoing/__init__.py @@ -0,0 +1 @@ +from . import * diff --git a/bookwyrm/tests/outgoing/test_follow.py b/bookwyrm/tests/outgoing/test_follow.py new file mode 100644 index 000000000..7932d9c17 --- /dev/null +++ b/bookwyrm/tests/outgoing/test_follow.py @@ -0,0 +1,37 @@ +from django.test import TestCase + +from bookwyrm import models, outgoing + + +class OutgoingFollow(TestCase): + def setUp(self): + self.remote_user = models.User.objects.create_user( + 'rat', 'rat@rat.com', 'ratword', + local=False, + remote_id='https://example.com/users/rat', + inbox='https://example.com/users/rat/inbox', + outbox='https://example.com/users/rat/outbox', + ) + self.local_user = models.User.objects.create_user( + 'mouse', 'mouse@mouse.com', 'mouseword', + local=True, + remote_id='http://local.com/users/mouse', + ) + + + def test_handle_follow(self): + self.assertEqual(models.UserFollowRequest.objects.count(), 0) + + outgoing.handle_follow(self.local_user, self.remote_user) + rel = models.UserFollowRequest.objects.get() + + self.assertEqual(rel.user_subject, self.local_user) + self.assertEqual(rel.user_object, self.remote_user) + self.assertEqual(rel.status, 'follow_request') + + def test_handle_unfollow(self): + self.remote_user.followers.add(self.local_user) + self.assertEqual(self.remote_user.followers.count(), 1) + outgoing.handle_unfollow(self.local_user, self.remote_user) + + self.assertEqual(self.remote_user.followers.count(), 0)