reorganize incoming/outgoing tests

This commit is contained in:
Mouse Reeve 2020-10-16 14:04:06 -07:00
parent cae7bbf834
commit 694de44f3f
6 changed files with 41 additions and 7 deletions

View file

@ -0,0 +1 @@
from . import *

View file

@ -6,7 +6,6 @@ from bookwyrm import models, incoming
class Favorite(TestCase): class Favorite(TestCase):
''' not too much going on in the books model but here we are '''
def setUp(self): def setUp(self):
self.remote_user = models.User.objects.create_user( self.remote_user = models.User.objects.create_user(
'rat', 'rat@rat.com', 'ratword', 'rat', 'rat@rat.com', 'ratword',
@ -25,7 +24,7 @@ class Favorite(TestCase):
) )
datafile = pathlib.Path(__file__).parent.joinpath( datafile = pathlib.Path(__file__).parent.joinpath(
'data/ap_user.json' '../data/ap_user.json'
) )
self.user_data = json.loads(datafile.read_bytes()) self.user_data = json.loads(datafile.read_bytes())

View file

@ -1,11 +1,9 @@
import json
from django.test import TestCase from django.test import TestCase
from bookwyrm import models, incoming from bookwyrm import models, incoming
class Follow(TestCase): class IncomingFollow(TestCase):
''' not too much going on in the books model but here we are '''
def setUp(self): def setUp(self):
self.remote_user = models.User.objects.create_user( self.remote_user = models.User.objects.create_user(
'rat', 'rat@rat.com', 'ratword', 'rat', 'rat@rat.com', 'ratword',

View file

@ -1,11 +1,9 @@
import json
from django.test import TestCase from django.test import TestCase
from bookwyrm import models, incoming from bookwyrm import models, incoming
class IncomingFollowAccept(TestCase): class IncomingFollowAccept(TestCase):
''' not too much going on in the books model but here we are '''
def setUp(self): def setUp(self):
self.remote_user = models.User.objects.create_user( self.remote_user = models.User.objects.create_user(
'rat', 'rat@rat.com', 'ratword', 'rat', 'rat@rat.com', 'ratword',

View file

@ -0,0 +1 @@
from . import *

View file

@ -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)