kopia lustrzana https://gitlab.com/marnanel/chapeau
wild amounts of tinkering to make the tests use httpretty
rodzic
cd9ac8d27f
commit
73f8032791
|
@ -39,7 +39,7 @@ CELERY = {
|
|||
'task_ignore_result': True,
|
||||
}
|
||||
|
||||
DEBUG = False
|
||||
DEBUG = True
|
||||
|
||||
if DEBUG:
|
||||
LOGGING = {
|
||||
|
|
|
@ -1,23 +1,35 @@
|
|||
from django.test import TestCase, Client
|
||||
from django_kepi.models import Activity, QuarantinedMessage, QuarantinedMessageNeeds
|
||||
from django_kepi import create, resolve
|
||||
from things_for_testing import KepiTestCase
|
||||
import logging
|
||||
import httpretty
|
||||
import json
|
||||
|
||||
class TestAsyncResult(TestCase):
|
||||
logger = logging.Logger(name=__name__)
|
||||
|
||||
class TestAsyncResult(KepiTestCase):
|
||||
|
||||
@httpretty.activate
|
||||
def test_simple(self):
|
||||
|
||||
PERSON_URL = 'https://example.net/polly'
|
||||
ARTICLE_URL = 'https://example.com/articles/kettles-are-nice'
|
||||
|
||||
polly = create({
|
||||
'id': 'https://example.net/polly',
|
||||
'id': PERSON_URL,
|
||||
'type': 'Person',
|
||||
})
|
||||
|
||||
ARTICLE_URL = 'https://example.com/articles/kettles-are-nice'
|
||||
QUARANTINED_BODY = """{
|
||||
QUARANTINED_BODY = json.dumps({
|
||||
"id": "https://example.com/id/1",
|
||||
"type": "Like",
|
||||
"actor": "https://example.net/polly",
|
||||
"object": "%s"
|
||||
}""" % (ARTICLE_URL,)
|
||||
"actor": PERSON_URL,
|
||||
"object": ARTICLE_URL,
|
||||
})
|
||||
|
||||
self._mock_remote_object(PERSON_URL, ftype='Person')
|
||||
self._mock_remote_object(ARTICLE_URL, ftype='Article')
|
||||
|
||||
qlike = QuarantinedMessage(
|
||||
username=None,
|
||||
|
@ -50,16 +62,20 @@ class TestAsyncResult(TestCase):
|
|||
identifier=ARTICLE_URL,
|
||||
))
|
||||
|
||||
@httpretty.activate
|
||||
def test_partial(self):
|
||||
|
||||
PERSON_URL = 'https://example.net/mary'
|
||||
ARTICLE_URL = 'https://example.com/articles/lambs-are-nice'
|
||||
QUARANTINED_BODY = """{
|
||||
QUARANTINED_BODY = json.dumps({
|
||||
"id": "https://example.com/id/2",
|
||||
"type": "Like",
|
||||
"actor": "%s",
|
||||
"object": "%s"
|
||||
}""" % (PERSON_URL, ARTICLE_URL,)
|
||||
"actor": PERSON_URL,
|
||||
"object": ARTICLE_URL,
|
||||
})
|
||||
|
||||
self._mock_remote_object(PERSON_URL, ftype='Person')
|
||||
self._mock_remote_object(ARTICLE_URL, ftype='Article')
|
||||
|
||||
qlike = QuarantinedMessage(
|
||||
username=None,
|
||||
|
@ -108,6 +124,7 @@ class TestAsyncResult(TestCase):
|
|||
|
||||
# XXX assert that the activity now exists
|
||||
|
||||
@httpretty.activate
|
||||
def test_failure(self):
|
||||
|
||||
PERSON_URL = 'https://example.net/lucy'
|
||||
|
@ -119,6 +136,17 @@ class TestAsyncResult(TestCase):
|
|||
"object": "%s"
|
||||
}""" % (PERSON_URL, ARTICLE_URL,)
|
||||
|
||||
self._mock_remote_object(PERSON_URL, ftype='Person', status=404)
|
||||
self._mock_remote_object(ARTICLE_URL, ftype='Article')
|
||||
|
||||
# XXX For some reason, this allows Celery to
|
||||
# access /async_result in the test version;
|
||||
# without it, the socket library throws an error.
|
||||
httpretty.register_uri(
|
||||
httpretty.POST,
|
||||
'https://localhost/async_result',
|
||||
body='something')
|
||||
|
||||
qlike = QuarantinedMessage(
|
||||
username=None,
|
||||
headers='',
|
||||
|
@ -161,3 +189,4 @@ class TestAsyncResult(TestCase):
|
|||
QuarantinedMessageNeeds.objects.filter(needs_to_fetch=PERSON_URL).exists())
|
||||
|
||||
# XXX assert that the activity does NOT exist
|
||||
|
||||
|
|
|
@ -2,12 +2,20 @@ from django.test import TestCase, Client
|
|||
from django_kepi.views import InboxView
|
||||
from django_kepi.models import QuarantinedMessage, QuarantinedMessageNeeds, Activity
|
||||
from things_for_testing.models import ThingArticle, ThingUser
|
||||
from things_for_testing import KepiTestCase
|
||||
import json
|
||||
import httpretty
|
||||
|
||||
class TestInbox(TestCase):
|
||||
class TestInbox(KepiTestCase):
|
||||
|
||||
@httpretty.activate
|
||||
def test_specific_post(self):
|
||||
|
||||
QuarantinedMessage.objects.all().delete()
|
||||
HUMAN_URL = 'https://users.example.net/mary'
|
||||
ANIMAL_URL = 'https://things.example.org/lamb'
|
||||
|
||||
self._mock_remote_object(HUMAN_URL, ftype='Person')
|
||||
self._mock_remote_object(ANIMAL_URL, ftype='Person')
|
||||
|
||||
c = Client()
|
||||
|
||||
|
@ -15,8 +23,8 @@ class TestInbox(TestCase):
|
|||
content_type = 'application/activity+json',
|
||||
data = {
|
||||
"id": "https://example.net/hello-world",
|
||||
"actor": "https://users.example.net/mary",
|
||||
"object": "https://things.example.org/lamb",
|
||||
"actor": HUMAN_URL,
|
||||
"object": ANIMAL_URL,
|
||||
"type": "Like",
|
||||
},
|
||||
)
|
||||
|
@ -26,7 +34,11 @@ class TestInbox(TestCase):
|
|||
|
||||
def test_shared_post(self):
|
||||
|
||||
QuarantinedMessage.objects.all().delete()
|
||||
HUMAN_URL = 'https://users.example.net/mary'
|
||||
ANIMAL_URL = 'https://things.example.org/another-lamb'
|
||||
|
||||
self._mock_remote_object(HUMAN_URL, ftype='Person')
|
||||
self._mock_remote_object(ANIMAL_URL, ftype='Person')
|
||||
|
||||
c = Client()
|
||||
|
||||
|
@ -34,8 +46,8 @@ class TestInbox(TestCase):
|
|||
content_type = 'application/activity+json',
|
||||
data = {
|
||||
"id": "https://example.net/hello-world",
|
||||
"actor": "https://users.example.net/mary",
|
||||
"object": "https://things.example.org/lamb",
|
||||
"actor": HUMAN_URL,
|
||||
"object": ANIMAL_URL,
|
||||
"type": "Like",
|
||||
},
|
||||
)
|
||||
|
@ -59,16 +71,20 @@ class TestInbox(TestCase):
|
|||
|
||||
def test_malformed_json(self):
|
||||
|
||||
QuarantinedMessage.objects.all().delete()
|
||||
PERSON_URL = 'https://users.example.com/my-dame'
|
||||
ANIMAL_URL = 'https://animals.example.com/a-lame-tame-crane'
|
||||
|
||||
self._mock_remote_object(HUMAN_URL, ftype='Person')
|
||||
self._mock_remote_object(ANIMAL_URL, ftype='Person')
|
||||
|
||||
c = Client()
|
||||
|
||||
text = """{
|
||||
text = json.dumps({
|
||||
"id": "https://example.net/hello-world",
|
||||
"actor": "https://users.example.net/mary",
|
||||
"object": "https://things.example.org/lamb",
|
||||
"type": "Like"
|
||||
}"""
|
||||
"actor": PERSON_URL,
|
||||
"object": ANIMAL_URL,
|
||||
"type": "Like",
|
||||
})
|
||||
|
||||
c.post('/sharedInbox',
|
||||
content_type = 'application/activity+json',
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_settings')
|
||||
|
||||
app = Celery('things_for_testing',
|
||||
broker='amqp://localhost')
|
||||
|
||||
app.config_from_object('django.conf:settings')
|
||||
|
||||
app.autodiscover_tasks(packages=['django_kepi'])
|
||||
|
||||
app.config_from_object('django.conf:settings')
|
||||
def debug_task(self):
|
||||
print('Request: {0!r}'.format(self.request))
|
Ładowanie…
Reference in New Issue