From 34b6c59e3042b0bccf353bf8c719b6e134c86ea2 Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Wed, 29 May 2019 09:15:39 +0100 Subject: [PATCH] create_person() always creates an Actor object, even with no extra data for it. test_message() split into test_message() and test_message_body_and_headers(). --- tests/__init__.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 072be9d..d8492b5 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -65,15 +65,11 @@ def create_person(name, result = create(spec) - if actor_fields: - # XXX kepi should allow us to create - # XXX this using create(), as part of - # XXX the Thing creation - actor = Actor( - thing=result, - **actor_fields, - ) - actor.save() + actor = Actor( + thing=result, + **actor_fields, + ) + actor.save() return result @@ -100,16 +96,19 @@ def mock_remote_object( status, content) -def test_message(secret='', **fields): +def test_message_body_and_headers(secret='', + path=INBOX_PATH, + host=INBOX_HOST, + **fields): body = dict([(f[2:],v) for f,v in fields.items() if f.startswith('f_')]) body['@context'] = MESSAGE_CONTEXT - body['Host'] = INBOX_HOST + body['Host'] = host, headers = { 'content-type': "application/activity+json", 'date': "Thu, 04 Apr 2019 21:12:11 GMT", - 'host': INBOX_HOST, + 'host': host, } if 'key_id' in fields: @@ -127,13 +126,22 @@ def test_message(secret='', **fields): headers = signer.sign( headers, method='POST', - path=INBOX_PATH, + path=path, ) SIGNATURE = 'Signature' if headers['Authorization'].startswith(SIGNATURE): headers['Signature'] = headers['Authorization'][len(SIGNATURE)+1:] + return body, headers + +def test_message(secret='', **fields): + + body, headers = test_message_body_and_headers( + secret, + **fields, + ) + result = IncomingMessage( content_type = headers['content-type'], date = headers['date'],