mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-01 21:08:42 +00:00
Fixes tests
This commit is contained in:
parent
b0202eb8e8
commit
76ce20a5e0
2 changed files with 5 additions and 32 deletions
|
@ -1,27 +0,0 @@
|
||||||
import json
|
|
||||||
import pathlib
|
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
from bookwyrm import models, remote_user
|
|
||||||
|
|
||||||
|
|
||||||
class RemoteUser(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',
|
|
||||||
local=False,
|
|
||||||
remote_id='https://example.com/users/rat',
|
|
||||||
inbox='https://example.com/users/rat/inbox',
|
|
||||||
outbox='https://example.com/users/rat/outbox',
|
|
||||||
)
|
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
|
||||||
'data/ap_user.json'
|
|
||||||
)
|
|
||||||
self.user_data = json.loads(datafile.read_bytes())
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_remote_user(self):
|
|
||||||
actor = 'https://example.com/users/rat'
|
|
||||||
user = remote_user.get_or_create_remote_user(actor)
|
|
||||||
self.assertEqual(user, self.remote_user)
|
|
|
@ -107,7 +107,7 @@ class Signature(TestCase):
|
||||||
status=200
|
status=200
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch('bookwyrm.remote_user.get_remote_reviews.delay') as _:
|
with patch('bookwyrm.models.user.get_remote_reviews.delay') as _:
|
||||||
response = self.send_test_request(sender=self.fake_remote)
|
response = self.send_test_request(sender=self.fake_remote)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ class Signature(TestCase):
|
||||||
json=data,
|
json=data,
|
||||||
status=200)
|
status=200)
|
||||||
|
|
||||||
with patch('bookwyrm.remote_user.get_remote_reviews.delay') as _:
|
with patch('bookwyrm.models.user.get_remote_reviews.delay') as _:
|
||||||
# Key correct:
|
# Key correct:
|
||||||
response = self.send_test_request(sender=self.fake_remote)
|
response = self.send_test_request(sender=self.fake_remote)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
@ -177,7 +177,7 @@ class Signature(TestCase):
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_changed_data(self):
|
def test_changed_data(self):
|
||||||
'''Message data must match the digest header.'''
|
'''Message data must match the digest header.'''
|
||||||
with patch('bookwyrm.remote_user.fetch_user_data') as _:
|
with patch('bookwyrm.activitypub.resolve_remote_id') as _:
|
||||||
response = self.send_test_request(
|
response = self.send_test_request(
|
||||||
self.mouse,
|
self.mouse,
|
||||||
send_data=get_follow_data(self.mouse, self.cat))
|
send_data=get_follow_data(self.mouse, self.cat))
|
||||||
|
@ -185,7 +185,7 @@ class Signature(TestCase):
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_invalid_digest(self):
|
def test_invalid_digest(self):
|
||||||
with patch('bookwyrm.remote_user.fetch_user_data') as _:
|
with patch('bookwyrm.activitypub.resolve_remote_id') as _:
|
||||||
response = self.send_test_request(
|
response = self.send_test_request(
|
||||||
self.mouse,
|
self.mouse,
|
||||||
digest='SHA-256=AAAAAAAAAAAAAAAAAA')
|
digest='SHA-256=AAAAAAAAAAAAAAAAAA')
|
||||||
|
@ -194,7 +194,7 @@ class Signature(TestCase):
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_old_message(self):
|
def test_old_message(self):
|
||||||
'''Old messages should be rejected to prevent replay attacks.'''
|
'''Old messages should be rejected to prevent replay attacks.'''
|
||||||
with patch('bookwyrm.remote_user.fetch_user_data') as _:
|
with patch('bookwyrm.activitypub.resolve_remote_id') as _:
|
||||||
response = self.send_test_request(
|
response = self.send_test_request(
|
||||||
self.mouse,
|
self.mouse,
|
||||||
date=http_date(time.time() - 301)
|
date=http_date(time.time() - 301)
|
||||||
|
|
Loading…
Reference in a new issue