mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-28 04:21:07 +00:00
Updates unit tests for new username handling
still some failing tho
This commit is contained in:
parent
e89bfdc572
commit
7e987fc446
14 changed files with 68 additions and 39 deletions
|
@ -20,7 +20,8 @@ class BaseActivity(TestCase):
|
|||
def setUp(self):
|
||||
''' we're probably going to re-use this so why copy/paste '''
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
self.user.remote_id = 'http://example.com/a/b'
|
||||
self.user.save()
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ class BaseModel(TestCase):
|
|||
def test_remote_id_with_user(self):
|
||||
''' format of remote id when there's a user object '''
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
instance = base_model.BookWyrmModel()
|
||||
instance.user = user
|
||||
instance.id = 1
|
||||
|
@ -51,7 +52,8 @@ class BaseModel(TestCase):
|
|||
def test_to_create_activity(self):
|
||||
''' wrapper for ActivityPub "create" action '''
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
|
||||
object_activity = {
|
||||
'to': 'to field', 'cc': 'cc field',
|
||||
|
@ -81,7 +83,8 @@ class BaseModel(TestCase):
|
|||
def test_to_delete_activity(self):
|
||||
''' wrapper for Delete activity '''
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
|
||||
MockSelf = namedtuple('Self', ('remote_id', 'to_activity'))
|
||||
mock_self = MockSelf(
|
||||
|
@ -105,7 +108,8 @@ class BaseModel(TestCase):
|
|||
def test_to_update_activity(self):
|
||||
''' ditto above but for Update '''
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
|
||||
MockSelf = namedtuple('Self', ('remote_id', 'to_activity'))
|
||||
mock_self = MockSelf(
|
||||
|
@ -129,7 +133,8 @@ class BaseModel(TestCase):
|
|||
def test_to_undo_activity(self):
|
||||
''' and again, for Undo '''
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
|
||||
MockSelf = namedtuple('Self', ('remote_id', 'to_activity'))
|
||||
mock_self = MockSelf(
|
||||
|
@ -173,7 +178,8 @@ class BaseModel(TestCase):
|
|||
book = models.Edition.objects.create(
|
||||
title='Test Edition', remote_id='http://book.com/book')
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
user.remote_id = 'http://example.com/a/b'
|
||||
user.save()
|
||||
|
||||
|
|
|
@ -173,7 +173,8 @@ class ActivitypubFields(TestCase):
|
|||
def test_privacy_field_set_activity_from_field(self):
|
||||
''' translate between to/cc fields and privacy '''
|
||||
user = User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||
'rat', 'rat@rat.rat', 'ratword',
|
||||
local=True, localname='rat')
|
||||
public = 'https://www.w3.org/ns/activitystreams#Public'
|
||||
followers = '%s/followers' % user.remote_id
|
||||
|
||||
|
@ -230,7 +231,8 @@ class ActivitypubFields(TestCase):
|
|||
|
||||
# it shouldn't match with this unrelated user:
|
||||
unrelated_user = User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||
'rat', 'rat@rat.rat', 'ratword',
|
||||
local=True, localname='rat')
|
||||
|
||||
# test receiving an unknown remote id and loading data
|
||||
responses.add(
|
||||
|
@ -258,7 +260,8 @@ class ActivitypubFields(TestCase):
|
|||
|
||||
# it shouldn't match with this unrelated user:
|
||||
unrelated_user = User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||
'rat', 'rat@rat.rat', 'ratword',
|
||||
local=True, localname='rat')
|
||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||
value = instance.field_from_activity(userdata)
|
||||
self.assertIsInstance(value, User)
|
||||
|
@ -276,11 +279,13 @@ class ActivitypubFields(TestCase):
|
|||
)
|
||||
userdata = json.loads(datafile.read_bytes())
|
||||
user = User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
user.remote_id = 'https://example.com/user/mouse'
|
||||
user.save()
|
||||
User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||
'rat', 'rat@rat.rat', 'ratword',
|
||||
local=True, localname='rat')
|
||||
|
||||
value = instance.field_from_activity(userdata)
|
||||
self.assertEqual(value, user)
|
||||
|
@ -290,9 +295,11 @@ class ActivitypubFields(TestCase):
|
|||
''' test receiving a remote id of an existing object in the db '''
|
||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||
user = User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||
'rat', 'rat@rat.rat', 'ratword',
|
||||
local=True, localname='rat')
|
||||
|
||||
value = instance.field_from_activity(user.remote_id)
|
||||
self.assertEqual(value, user)
|
||||
|
@ -382,7 +389,8 @@ class ActivitypubFields(TestCase):
|
|||
def test_image_field(self):
|
||||
''' storing images '''
|
||||
user = User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
'../../static/images/default_avi.jpg')
|
||||
image = Image.open(image_file)
|
||||
|
|
|
@ -52,7 +52,8 @@ class ImportJob(TestCase):
|
|||
unknown_read_data['Date Read'] = ''
|
||||
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
job = models.ImportJob.objects.create(user=user)
|
||||
models.ImportItem.objects.create(
|
||||
job=job, index=1, data=currently_reading_data)
|
||||
|
|
|
@ -16,7 +16,8 @@ class Relationship(TestCase):
|
|||
outbox='https://example.com/users/rat/outbox',
|
||||
)
|
||||
self.local_user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
self.local_user.remote_id = 'http://local.com/user/mouse'
|
||||
self.local_user.save()
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ class Shelf(TestCase):
|
|||
def setUp(self):
|
||||
''' look, a shelf '''
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
self.shelf = models.Shelf.objects.create(
|
||||
name='Test Shelf', identifier='test-shelf', user=self.user)
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ class Status(TestCase):
|
|||
def setUp(self):
|
||||
''' useful things for creating a status '''
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
self.book = models.Edition.objects.create(title='Test Edition')
|
||||
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
|
|
|
@ -9,7 +9,8 @@ from bookwyrm.settings import DOMAIN
|
|||
class User(TestCase):
|
||||
def setUp(self):
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse@%s' % DOMAIN, 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
|
||||
def test_computed_fields(self):
|
||||
''' username instead of id here '''
|
||||
|
|
|
@ -7,10 +7,12 @@ from bookwyrm import models, broadcast
|
|||
class Book(TestCase):
|
||||
def setUp(self):
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
|
||||
local_follower = models.User.objects.create_user(
|
||||
'joe', 'joe@mouse.mouse', 'jeoword', local=True)
|
||||
'joe', 'joe@mouse.mouse', 'jeoword',
|
||||
local=True, localname='joe')
|
||||
self.user.followers.add(local_follower)
|
||||
|
||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||
|
|
|
@ -19,7 +19,8 @@ class Incoming(TestCase):
|
|||
def setUp(self):
|
||||
''' we need basic things, like users '''
|
||||
self.local_user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
self.local_user.remote_id = 'https://example.com/user/mouse'
|
||||
self.local_user.save()
|
||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||
|
|
|
@ -23,7 +23,8 @@ class Outgoing(TestCase):
|
|||
outbox='https://example.com/users/rat/outbox',
|
||||
)
|
||||
self.local_user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True,
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse',
|
||||
remote_id='https://example.com/users/mouse',
|
||||
)
|
||||
|
||||
|
|
|
@ -31,11 +31,14 @@ Sender = namedtuple('Sender', ('remote_id', 'key_pair'))
|
|||
class Signature(TestCase):
|
||||
def setUp(self):
|
||||
self.mouse = User.objects.create_user(
|
||||
'mouse', 'mouse@example.com', '', local=True)
|
||||
'mouse@%s' % DOMAIN, 'mouse@example.com', '',
|
||||
local=True, localname='mouse')
|
||||
self.rat = User.objects.create_user(
|
||||
'rat', 'rat@example.com', '', local=True)
|
||||
'rat@%s' % DOMAIN, 'rat@example.com', '',
|
||||
local=True, localname='rat')
|
||||
self.cat = User.objects.create_user(
|
||||
'cat', 'cat@example.com', '', local=True)
|
||||
'cat@%s' % DOMAIN, 'cat@example.com', '',
|
||||
local=True, localname='cat')
|
||||
|
||||
private_key, public_key = create_key_pair()
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ class TemplateTags(TestCase):
|
|||
def setUp(self):
|
||||
''' create some filler objects '''
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
'mouse@example.com', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword',
|
||||
|
|
|
@ -18,7 +18,8 @@ class ViewActions(TestCase):
|
|||
def setUp(self):
|
||||
''' we need basic things, like users '''
|
||||
self.local_user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
self.local_user.remote_id = 'https://example.com/user/mouse'
|
||||
self.local_user.save()
|
||||
self.group = Group.objects.create(name='editor')
|
||||
|
@ -51,7 +52,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nutria-user.user_nutria',
|
||||
'localname': 'nutria-user.user_nutria',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.cccc'
|
||||
})
|
||||
|
@ -69,7 +70,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nutria ',
|
||||
'localname': 'nutria ',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.ccc'
|
||||
})
|
||||
|
@ -88,7 +89,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nutria',
|
||||
'localname': 'nutria',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa'
|
||||
})
|
||||
|
@ -102,7 +103,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nut@ria',
|
||||
'localname': 'nut@ria',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.ccc'
|
||||
})
|
||||
|
@ -113,7 +114,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nutr ia',
|
||||
'localname': 'nutr ia',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.ccc'
|
||||
})
|
||||
|
@ -124,7 +125,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nut@ria',
|
||||
'localname': 'nut@ria',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.ccc'
|
||||
})
|
||||
|
@ -140,7 +141,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nutria ',
|
||||
'localname': 'nutria ',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.ccc'
|
||||
})
|
||||
|
@ -158,7 +159,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nutria',
|
||||
'localname': 'nutria',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.ccc',
|
||||
'invite_code': 'testcode'
|
||||
|
@ -173,7 +174,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nutria2',
|
||||
'localname': 'nutria2',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.ccc',
|
||||
'invite_code': 'testcode'
|
||||
|
@ -185,7 +186,7 @@ class ViewActions(TestCase):
|
|||
request = self.factory.post(
|
||||
'register/',
|
||||
{
|
||||
'username': 'nutria3',
|
||||
'localname': 'nutria3',
|
||||
'password': 'mouseword',
|
||||
'email': 'aa@bb.ccc',
|
||||
'invite_code': 'dkfkdjgdfkjgkdfj'
|
||||
|
|
Loading…
Reference in a new issue