kopia lustrzana https://gitlab.com/marnanel/chapeau
post_test_message()
rodzic
dadff3a45d
commit
038d0ca2d1
|
@ -1,6 +1,7 @@
|
|||
from django_kepi.models import create
|
||||
from django_kepi.validation import IncomingMessage, validate
|
||||
from django_kepi.models.actor import Actor
|
||||
import django.test
|
||||
import httpretty
|
||||
import logging
|
||||
import httpsig
|
||||
|
@ -155,6 +156,43 @@ def test_message(secret='', **fields):
|
|||
result.save()
|
||||
return result
|
||||
|
||||
def post_test_message(
|
||||
path, host,
|
||||
secret,
|
||||
f_id, f_type, f_actor, f_object,
|
||||
client = None,
|
||||
):
|
||||
|
||||
if client is None:
|
||||
client = django.test.Client()
|
||||
|
||||
body, headers = test_message_body_and_headers(
|
||||
f_id=f_id,
|
||||
f_type=f_type,
|
||||
f_actor=f_actor,
|
||||
f_object=f_object,
|
||||
secret = secret,
|
||||
path = path,
|
||||
host = host,
|
||||
)
|
||||
|
||||
logger.debug("Test message is %s",
|
||||
body)
|
||||
logger.debug(" -- with headers %s",
|
||||
headers)
|
||||
|
||||
client.post(
|
||||
path = path,
|
||||
content_type = headers['content-type'], # XXX why twice?
|
||||
data = json.dumps(body),
|
||||
CONTENT_TYPE = headers['content-type'],
|
||||
HTTP_DATE = headers['date'],
|
||||
HOST = headers['host'],
|
||||
HTTP_SIGNATURE = headers['signature'],
|
||||
)
|
||||
|
||||
return client
|
||||
|
||||
def remote_user(url, name,
|
||||
publicKey='',
|
||||
inbox=None,
|
||||
|
|
|
@ -30,32 +30,18 @@ class TestInbox(TestCase):
|
|||
publicKey = keys['public'],
|
||||
)),
|
||||
)
|
||||
|
||||
body, headers = test_message_body_and_headers(
|
||||
f_id=ACTIVITY_ID,
|
||||
f_type="Follow",
|
||||
f_actor=REMOTE_FRED,
|
||||
f_object=LOCAL_ALICE,
|
||||
secret = keys['private'],
|
||||
path = ALICE_INBOX,
|
||||
host = 'europa.example.com',
|
||||
)
|
||||
|
||||
logger.debug("Test message is %s",
|
||||
body)
|
||||
logger.debug(" -- with headers %s",
|
||||
headers)
|
||||
|
||||
c = Client()
|
||||
c.post(
|
||||
ALICE_INBOX,
|
||||
content_type = 'application/activity+json',
|
||||
data = json.dumps(body),
|
||||
CONTENT_TYPE = headers['content-type'],
|
||||
HTTP_DATE = headers['date'],
|
||||
HOST = headers['host'],
|
||||
HTTP_SIGNATURE = headers['signature'],
|
||||
)
|
||||
|
||||
post_test_message(
|
||||
client = c,
|
||||
path = ALICE_INBOX,
|
||||
host = 'europa.example.com',
|
||||
secret = keys['private'],
|
||||
f_id = ACTIVITY_ID,
|
||||
f_type = "Follow",
|
||||
f_actor = REMOTE_FRED,
|
||||
f_object = LOCAL_ALICE,
|
||||
)
|
||||
|
||||
@httpretty.activate
|
||||
def test_shared_post(self):
|
||||
|
|
Ładowanie…
Reference in New Issue