From 5e297303700d33019fcf6fdcb7a49a91dcc5db54 Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Tue, 5 May 2020 19:11:43 +0100 Subject: [PATCH] New sombrero test: test_send. The tests are mostly skipped; the test for "follow" is implemented properly and it currently fails. Also, some small fiddling on sombrero's test_deliver to remove code rot. --- kepi/sombrero_sendpub/delivery.py | 3 +- kepi/sombrero_sendpub/tests/test_deliver.py | 6 +- kepi/sombrero_sendpub/tests/test_send.py | 80 +++++++++++++++++++++ 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 kepi/sombrero_sendpub/tests/test_send.py diff --git a/kepi/sombrero_sendpub/delivery.py b/kepi/sombrero_sendpub/delivery.py index 7eca83b..e36df96 100644 --- a/kepi/sombrero_sendpub/delivery.py +++ b/kepi/sombrero_sendpub/delivery.py @@ -11,7 +11,7 @@ to their audiences. from __future__ import absolute_import, unicode_literals from celery import shared_task -from kepi.bowler_pub.find import find, find_local, is_local +from kepi.bowler_pub.utils import is_local import kepi.bowler_pub.models from httpsig.verify import HeaderVerifier from urllib.parse import urlparse @@ -26,7 +26,6 @@ import datetime import pytz import httpsig from collections.abc import Iterable -from . import PUBLIC_IDS logger = logging.getLogger(name='kepi') diff --git a/kepi/sombrero_sendpub/tests/test_deliver.py b/kepi/sombrero_sendpub/tests/test_deliver.py index 36f7106..2d7cfb0 100644 --- a/kepi/sombrero_sendpub/tests/test_deliver.py +++ b/kepi/sombrero_sendpub/tests/test_deliver.py @@ -9,10 +9,8 @@ from django.test import TestCase, Client from django.conf import settings -from kepi.bowler_pub.delivery import deliver -from kepi.bowler_pub.create import create -from kepi.bowler_pub.models import AcObject -import kepi.bowler_pub.views as bowler_pub_views +from kepi.sombrero_sendpub.delivery import deliver +import kepi.sombrero_sendpub.views as sombrero_views from unittest.mock import Mock, patch from . import * import logging diff --git a/kepi/sombrero_sendpub/tests/test_send.py b/kepi/sombrero_sendpub/tests/test_send.py new file mode 100644 index 0000000..6a4079c --- /dev/null +++ b/kepi/sombrero_sendpub/tests/test_send.py @@ -0,0 +1,80 @@ +# test_send.py +# +# Part of kepi. +# Copyright (c) 2018-2020 Marnanel Thurman. +# Licensed under the GNU Public License v2. + +from unittest import skip +from django.test import TestCase +from rest_framework.test import force_authenticate, APIClient +from django.conf import settings +from kepi.sombrero_sendpub.delivery import deliver +from kepi.trilby_api.models import Person +from kepi.trilby_api.tests import create_local_person +import httpretty + +REMOTE_URL = 'https://remote.example.net/users/zachary' + +class TestSend(TestCase): + + def setUp(self): + httpretty.register_uri( + httpretty.POST, + REMOTE_URL, + '', # body is ignored + ) + + self._zachary = Person( + remote_url = REMOTE_URL, + remote_username = 'zachary', + ) + self._zachary.save() + + self._alice = create_local_person('alice') + + self._client = APIClient() + self._client.force_authenticate(self._alice.local_user) + + @skip("TODO - mentions aren't yet implemented") + @httpretty.activate + def test_send_direct_message(self): + + result = self._client.post( + path='api/v1/statuses', + format='json', + data = { + 'status': '@zachary@remote.example.net Hello world', + 'visibility': 'direct', + }, + ) + + self.assertEqual(result.status_code, + 200) + + @skip("TODO") + def test_irrelevant(self): + pass + + @skip("TODO - mentions aren't implemented") + def test_mention(self): + pass + + @httpretty.activate + def test_follow(self): + + result = self._client.post( + path='api/v1/accounts/%d/follow' % ( + self._zachary.id,), + format='json', + ) + + self.assertEqual(result.status_code, + 200) + + @skip("TODO") + def test_accept_follow(self): + pass + + @skip("TODO") + def test_reject_follow(self): + pass