From 2e794e2a8a65965cc78e9fda13b3ae3e11ac6b4a Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Wed, 25 Nov 2020 20:20:55 +0000 Subject: [PATCH] bowler's tests gain BowlerClient, a subclass of django.test.Client which will set the Accept param correctly on get requests. Used throughout test_views instead of d.t.Client. --- kepi/bowler_pub/tests/__init__.py | 14 +++++++++++++- kepi/bowler_pub/tests/test_views.py | 11 ++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/kepi/bowler_pub/tests/__init__.py b/kepi/bowler_pub/tests/__init__.py index 877aadf..453425a 100644 --- a/kepi/bowler_pub/tests/__init__.py +++ b/kepi/bowler_pub/tests/__init__.py @@ -35,6 +35,18 @@ CONTEXT_URL = "https://www.w3.org/ns/activitystreams" logger = logging.getLogger(name='kepi') +MIME_TYPE = 'application/activity+json' + +class BowlerClient(django.test.Client): + + def get(self, *args, **kwargs): + + result = super().get(*args, **kwargs, + HTTP_ACCEPT = MIME_TYPE, + ) + + return result + class DummyMessage(object): fields = None @@ -276,7 +288,7 @@ def post_test_message( ): if client is None: - client = django.test.Client() + client = BowlerClient() body, headers = test_message_body_and_headers( secret = secret, diff --git a/kepi/bowler_pub/tests/test_views.py b/kepi/bowler_pub/tests/test_views.py index 51d2f7c..42d0575 100644 --- a/kepi/bowler_pub/tests/test_views.py +++ b/kepi/bowler_pub/tests/test_views.py @@ -1,4 +1,4 @@ -from django.test import TestCase, Client +from django.test import TestCase from . import * from kepi.trilby_api.tests import create_local_person, create_local_status import logging @@ -7,6 +7,7 @@ import json logger = logging.getLogger(name='kepi') ALICE_SUMMARY = 'Remember Alice? It\'s a song about Alice.' +ALICE_SUMMARY_HTML = f'

{ALICE_SUMMARY}

' def _response_to_dict(response): @@ -32,7 +33,7 @@ class Tests(TestCase): note = ALICE_SUMMARY, ) - c = Client() + c = BowlerClient() response = c.get('/users/alice') self.assertEqual(response.status_code, 200) result = _response_to_dict(response) @@ -74,7 +75,7 @@ class Tests(TestCase): 'BfTLbe/QMcssQ5rHv9oAMy/hWHGyaES3vbxzqT2qMxI5bIJRpOJfDlTpAY5AVqrn\n' '8sYx/1XA9YJOKFkQIQIDAQAB\n' '-----END PUBLIC KEY-----'}, - 'summary': ALICE_SUMMARY, + 'summary': ALICE_SUMMARY_HTML, 'tag': [], 'type': 'Person', 'url': 'https://testserver/users/alice', @@ -90,7 +91,7 @@ class Tests(TestCase): posted_by = alice, ) - c = Client() + c = BowlerClient() response = c.get('/users/alice/featured') self.assertEqual(response.status_code, 200) result = _response_to_dict(response) @@ -130,7 +131,7 @@ class TestTombstone(TestCase): queen_anne = create_local_person('queen_anne') - c = Client() + c = BowlerClient() response = c.get('/users/queen_anne') self.assertEqual(response.status_code, 200)