Test fixes

This commit is contained in:
Mouse Reeve 2020-12-03 17:18:23 -08:00
parent bbbfbe721e
commit 646ced80ce
7 changed files with 29 additions and 36 deletions

View file

@ -15,7 +15,7 @@ class BaseModel(TestCase):
def test_remote_id_with_user(self): def test_remote_id_with_user(self):
user = models.User.objects.create_user( user = models.User.objects.create_user(
'mouse', 'mouse@mouse.com', 'mouseword') 'mouse', 'mouse@mouse.com', 'mouseword', local=True)
instance = BookWyrmModel() instance = BookWyrmModel()
instance.user = user instance.user = user
instance.id = 1 instance.id = 1

View file

@ -24,7 +24,7 @@ class Book(TestCase):
def test_remote_id(self): def test_remote_id(self):
remote_id = 'https://%s/book/%d' % (settings.DOMAIN, self.work.id) remote_id = 'https://%s/book/%d' % (settings.DOMAIN, self.work.id)
self.assertEqual(self.work.get_remote_id(), remote_id) self.assertEqual(self.work.get_remote_id(), remote_id)
self.assertEqual(self.work.remote_id, 'https://example.com/book/1') self.assertEqual(self.work.remote_id, remote_id)
def test_create_book(self): def test_create_book(self):
''' you shouldn't be able to create Books (only editions and works) ''' ''' you shouldn't be able to create Books (only editions and works) '''
@ -59,7 +59,7 @@ class Book(TestCase):
class Shelf(TestCase): class Shelf(TestCase):
def setUp(self): def setUp(self):
user = models.User.objects.create_user( user = models.User.objects.create_user(
'mouse', 'mouse@mouse.mouse', 'mouseword') 'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
models.Shelf.objects.create( models.Shelf.objects.create(
name='Test Shelf', identifier='test-shelf', user=user) name='Test Shelf', identifier='test-shelf', user=user)

View file

@ -52,7 +52,7 @@ class ImportJob(TestCase):
unknown_read_data['Date Read'] = '' unknown_read_data['Date Read'] = ''
user = models.User.objects.create_user( user = models.User.objects.create_user(
'mouse', 'mouse@mouse.mouse', 'mouseword') 'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
job = models.ImportJob.objects.create(user=user) job = models.ImportJob.objects.create(user=user)
models.ImportItem.objects.create( models.ImportItem.objects.create(
job=job, index=1, data=currently_reading_data) job=job, index=1, data=currently_reading_data)

View file

@ -1,4 +1,5 @@
''' testing models ''' ''' testing models '''
from unittest.mock import patch
from django.test import TestCase from django.test import TestCase
from bookwyrm import models from bookwyrm import models
@ -6,15 +7,16 @@ from bookwyrm import models
class Relationship(TestCase): class Relationship(TestCase):
def setUp(self): def setUp(self):
self.remote_user = models.User.objects.create_user( with patch('bookwyrm.models.user.set_remote_server.delay'):
'rat', 'rat@rat.com', 'ratword', self.remote_user = models.User.objects.create_user(
local=False, 'rat', 'rat@rat.com', 'ratword',
remote_id='https://example.com/users/rat', local=False,
inbox='https://example.com/users/rat/inbox', remote_id='https://example.com/users/rat',
outbox='https://example.com/users/rat/outbox', inbox='https://example.com/users/rat/inbox',
) outbox='https://example.com/users/rat/outbox',
)
self.local_user = models.User.objects.create_user( self.local_user = models.User.objects.create_user(
'mouse', 'mouse@mouse.com', 'mouseword') 'mouse', 'mouse@mouse.com', 'mouseword', local=True)
self.local_user.remote_id = 'http://local.com/user/mouse' self.local_user.remote_id = 'http://local.com/user/mouse'
self.local_user.save() self.local_user.save()

View file

@ -7,7 +7,7 @@ from bookwyrm import models, settings
class Status(TestCase): class Status(TestCase):
def setUp(self): def setUp(self):
user = models.User.objects.create_user( user = models.User.objects.create_user(
'mouse', 'mouse@mouse.mouse', 'mouseword') 'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
book = models.Edition.objects.create(title='Example Edition') book = models.Edition.objects.create(title='Example Edition')
models.Status.objects.create(user=user, content='Blah blah') models.Status.objects.create(user=user, content='Blah blah')
@ -40,13 +40,3 @@ class Status(TestCase):
expected_id = 'https://%s/user/mouse/review/%d' % \ expected_id = 'https://%s/user/mouse/review/%d' % \
(settings.DOMAIN, review.id) (settings.DOMAIN, review.id)
self.assertEqual(review.remote_id, expected_id) self.assertEqual(review.remote_id, expected_id)
class Tag(TestCase):
def test_tag(self):
book = models.Edition.objects.create(title='Example Edition')
user = models.User.objects.create_user(
'mouse', 'mouse@mouse.mouse', 'mouseword')
tag = models.Tag.objects.create(user=user, book=book, name='t/est tag')
self.assertEqual(tag.identifier, 't%2Fest+tag')

View file

@ -8,7 +8,7 @@ from bookwyrm.settings import DOMAIN
class User(TestCase): class User(TestCase):
def setUp(self): def setUp(self):
self.user = models.User.objects.create_user( self.user = models.User.objects.create_user(
'mouse', 'mouse@mouse.mouse', 'mouseword') 'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
def test_computed_fields(self): def test_computed_fields(self):
''' username instead of id here ''' ''' username instead of id here '''
@ -53,7 +53,6 @@ class User(TestCase):
self.assertEqual(activity['name'], self.user.name) self.assertEqual(activity['name'], self.user.name)
self.assertEqual(activity['inbox'], self.user.inbox) self.assertEqual(activity['inbox'], self.user.inbox)
self.assertEqual(activity['outbox'], self.user.outbox) self.assertEqual(activity['outbox'], self.user.outbox)
self.assertEqual(activity['followers'], self.user.ap_followers)
self.assertEqual(activity['bookwyrmUser'], True) self.assertEqual(activity['bookwyrmUser'], True)
self.assertEqual(activity['discoverable'], True) self.assertEqual(activity['discoverable'], True)
self.assertEqual(activity['type'], 'Person') self.assertEqual(activity['type'], 'Person')

View file

@ -2,17 +2,19 @@ from unittest.mock import patch
from django.test import TestCase from django.test import TestCase
from bookwyrm import models, outgoing from bookwyrm import models, outgoing
from bookwyrm.settings import DOMAIN
class Following(TestCase): class Following(TestCase):
def setUp(self): def setUp(self):
self.remote_user = models.User.objects.create_user( with patch('bookwyrm.models.user.set_remote_server'):
'rat', 'rat@rat.com', 'ratword', self.remote_user = models.User.objects.create_user(
local=False, 'rat', 'rat@rat.com', 'ratword',
remote_id='https://example.com/users/rat', local=False,
inbox='https://example.com/users/rat/inbox', remote_id='https://example.com/users/rat',
outbox='https://example.com/users/rat/outbox', inbox='https://example.com/users/rat/inbox',
) outbox='https://example.com/users/rat/outbox',
)
self.local_user = models.User.objects.create_user( self.local_user = models.User.objects.create_user(
'mouse', 'mouse@mouse.com', 'mouseword', 'mouse', 'mouse@mouse.com', 'mouseword',
local=True, local=True,
@ -23,7 +25,7 @@ class Following(TestCase):
def test_handle_follow(self): def test_handle_follow(self):
self.assertEqual(models.UserFollowRequest.objects.count(), 0) self.assertEqual(models.UserFollowRequest.objects.count(), 0)
with patch('bookwyrm.broadcast.broadcast_task.delay') as _: with patch('bookwyrm.broadcast.broadcast_task.delay'):
outgoing.handle_follow(self.local_user, self.remote_user) outgoing.handle_follow(self.local_user, self.remote_user)
rel = models.UserFollowRequest.objects.get() rel = models.UserFollowRequest.objects.get()
@ -36,7 +38,7 @@ class Following(TestCase):
def test_handle_unfollow(self): def test_handle_unfollow(self):
self.remote_user.followers.add(self.local_user) self.remote_user.followers.add(self.local_user)
self.assertEqual(self.remote_user.followers.count(), 1) self.assertEqual(self.remote_user.followers.count(), 1)
with patch('bookwyrm.broadcast.broadcast_task.delay') as _: with patch('bookwyrm.broadcast.broadcast_task.delay'):
outgoing.handle_unfollow(self.local_user, self.remote_user) outgoing.handle_unfollow(self.local_user, self.remote_user)
self.assertEqual(self.remote_user.followers.count(), 0) self.assertEqual(self.remote_user.followers.count(), 0)
@ -49,7 +51,7 @@ class Following(TestCase):
) )
rel_id = rel.id rel_id = rel.id
with patch('bookwyrm.broadcast.broadcast_task.delay') as _: with patch('bookwyrm.broadcast.broadcast_task.delay'):
outgoing.handle_accept(rel) outgoing.handle_accept(rel)
# request should be deleted # request should be deleted
self.assertEqual( self.assertEqual(
@ -66,7 +68,7 @@ class Following(TestCase):
) )
rel_id = rel.id rel_id = rel.id
with patch('bookwyrm.broadcast.broadcast_task.delay') as _: with patch('bookwyrm.broadcast.broadcast_task.delay'):
outgoing.handle_reject(rel) outgoing.handle_reject(rel)
# request should be deleted # request should be deleted
self.assertEqual( self.assertEqual(