mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-03 22:08:43 +00:00
a couple more assertions for testing fk field
This commit is contained in:
parent
7c43fa1f7c
commit
804066c523
1 changed files with 19 additions and 7 deletions
|
@ -100,16 +100,18 @@ class ActivitypubFields(TestCase):
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_foreign_key_from_activity_str(self):
|
def test_foreign_key_from_activity_str(self):
|
||||||
''' this is the important stuff '''
|
''' create a new object from a foreign key '''
|
||||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||||
'../data/ap_user.json'
|
'../data/ap_user.json')
|
||||||
)
|
|
||||||
userdata = json.loads(datafile.read_bytes())
|
userdata = json.loads(datafile.read_bytes())
|
||||||
# don't try to load the user icon
|
# don't try to load the user icon
|
||||||
del userdata['icon']
|
del userdata['icon']
|
||||||
|
|
||||||
|
# it shouldn't match with this unrelated user:
|
||||||
|
unrelated_user = User.objects.create_user(
|
||||||
|
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||||
|
|
||||||
# test receiving an unknown remote id and loading data
|
# test receiving an unknown remote id and loading data
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET,
|
responses.GET,
|
||||||
|
@ -120,6 +122,7 @@ class ActivitypubFields(TestCase):
|
||||||
value = instance.field_from_activity(
|
value = instance.field_from_activity(
|
||||||
'https://example.com/user/mouse')
|
'https://example.com/user/mouse')
|
||||||
self.assertIsInstance(value, User)
|
self.assertIsInstance(value, User)
|
||||||
|
self.assertNotEqual(value, unrelated_user)
|
||||||
self.assertEqual(value.remote_id, 'https://example.com/user/mouse')
|
self.assertEqual(value.remote_id, 'https://example.com/user/mouse')
|
||||||
self.assertEqual(value.name, 'MOUSE?? MOUSE!!')
|
self.assertEqual(value.name, 'MOUSE?? MOUSE!!')
|
||||||
|
|
||||||
|
@ -127,16 +130,19 @@ class ActivitypubFields(TestCase):
|
||||||
def test_foreign_key_from_activity_dict(self):
|
def test_foreign_key_from_activity_dict(self):
|
||||||
''' test recieving activity json '''
|
''' test recieving activity json '''
|
||||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||||
'../data/ap_user.json'
|
'../data/ap_user.json')
|
||||||
)
|
|
||||||
userdata = json.loads(datafile.read_bytes())
|
userdata = json.loads(datafile.read_bytes())
|
||||||
# don't try to load the user icon
|
# don't try to load the user icon
|
||||||
del userdata['icon']
|
del userdata['icon']
|
||||||
|
|
||||||
|
# it shouldn't match with this unrelated user:
|
||||||
|
unrelated_user = User.objects.create_user(
|
||||||
|
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||||
value = instance.field_from_activity(userdata)
|
value = instance.field_from_activity(userdata)
|
||||||
self.assertIsInstance(value, User)
|
self.assertIsInstance(value, User)
|
||||||
|
self.assertNotEqual(value, unrelated_user)
|
||||||
self.assertEqual(value.remote_id, 'https://example.com/user/mouse')
|
self.assertEqual(value.remote_id, 'https://example.com/user/mouse')
|
||||||
self.assertEqual(value.name, 'MOUSE?? MOUSE!!')
|
self.assertEqual(value.name, 'MOUSE?? MOUSE!!')
|
||||||
# et cetera but we're not testing serializing user json
|
# et cetera but we're not testing serializing user json
|
||||||
|
@ -153,6 +159,9 @@ class ActivitypubFields(TestCase):
|
||||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||||
user.remote_id = 'https://example.com/user/mouse'
|
user.remote_id = 'https://example.com/user/mouse'
|
||||||
user.save()
|
user.save()
|
||||||
|
User.objects.create_user(
|
||||||
|
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||||
|
|
||||||
value = instance.field_from_activity(userdata)
|
value = instance.field_from_activity(userdata)
|
||||||
self.assertEqual(value, user)
|
self.assertEqual(value, user)
|
||||||
|
|
||||||
|
@ -162,6 +171,9 @@ class ActivitypubFields(TestCase):
|
||||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
user = User.objects.create_user(
|
user = User.objects.create_user(
|
||||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||||
|
User.objects.create_user(
|
||||||
|
'rat', 'rat@rat.rat', 'ratword', local=True)
|
||||||
|
|
||||||
value = instance.field_from_activity(user.remote_id)
|
value = instance.field_from_activity(user.remote_id)
|
||||||
self.assertEqual(value, user)
|
self.assertEqual(value, user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue