def test_get_topic_hub_url(self): link = '<http://example.com/dataset1/change/>;rel="self",\ <http://hub.example.org/pubsubhubbub/>;rel="hub"' resourcesync_push = ResourceSyncPuSH() t, h = resourcesync_push.get_topic_hub_url(link) assert t == "http://example.com/dataset1/change/" assert h == "http://hub.example.org/pubsubhubbub/"
def test_resourcesync_push_config(self): print("Reading hub config") resourcesync_push = ResourceSyncPuSH() resourcesync_push.get_config(classname='hub') assert resourcesync_push.config['my_url'] is not None print("Reading publisher config") resourcesync_push = ResourceSyncPuSH() resourcesync_push.get_config(classname='publisher') assert resourcesync_push.config['my_url'] is not None print("Reading subscriber config") resourcesync_push = ResourceSyncPuSH() resourcesync_push.get_config(classname='subscriber') assert resourcesync_push.config['my_url'] is not None
def handle_resourcesync_request(self, content_type="application/xml"): """ ResourceSync payload. Gets the topic and hub url from the link header and broadcasts to the subscribers. """ payload = self._env['wsgi.input'].read() if not payload: return self.respond(code=400, msg="Payload of size > 0 expected.") link_header = self._env.get('HTTP_LINK', None) if not link_header: return self.respond(code=400, msg="ResourceSync Link Headers required.") topic, hub_url = ResourceSyncPuSH.get_topic_hub_url(link_header) if not topic and not hub_url: return self.respond(code=400, msg="ResourceSync Link header spec not met.") if self.config['trusted_topics'] and \ topic.strip() not in self.config['trusted_topics']: return self.respond(code=403, msg="Topic is not registered with the hub.") subscriptions = self.read_subscriptions() if not subscriptions: return self.respond(code=500, msg="Error reading subscriptions.") subscribers = subscriptions.get(topic, None) if not subscribers: return self.respond(code=204) headers = { 'Content-Type': content_type, 'Link': link_header, 'Content-Length': str(len(payload)) } self.log_msg['msg'].append("""Posting change notification to %s \ subscriber(s)""" % len(subscribers)) self.log_msg['msg'].append("Payload size: %s bytes." % str(len(payload))) self.log_msg['link_header'] = link_header self.log_msg['payload'] = payload self.log() for subscriber in subscribers: self.send(subscriber, data=payload, headers=headers) # success return self.respond(code=204)
import unittest from resourcesync_push import ResourceSyncPuSH resourcesync_push = ResourceSyncPuSH() class TestResourceSyncPuSH(unittest.TestCase): def test_resourcesync_push_config(self): print("Reading hub config") resourcesync_push = ResourceSyncPuSH() resourcesync_push.get_config(classname='hub') assert resourcesync_push.config['my_url'] is not None print("Reading publisher config") resourcesync_push = ResourceSyncPuSH() resourcesync_push.get_config(classname='publisher') assert resourcesync_push.config['my_url'] is not None print("Reading subscriber config") resourcesync_push = ResourceSyncPuSH() resourcesync_push.get_config(classname='subscriber') assert resourcesync_push.config['my_url'] is not None def test_send_get(self): f = resourcesync_push.send("http://httpbin.org/get", method='GET') r = f.result() assert r.status_code == 200 def test_send_post(self): f = resourcesync_push.send("http://httpbin.org/post", data="test") r = f.result()
def __init__(self, env, start_response): ResourceSyncPuSH.__init__(self) self._env = env self._start_response = start_response self.get_config()
def test_topic_url(self): from resourcesync_push import ResourceSyncPuSH resourcesync_push = ResourceSyncPuSH() resourcesync_push.get_config(classname='publisher') app.get(resourcesync_push.config['topic_url'], status=204)
def __init__(self): ResourceSyncPuSH.__init__(self) self.get_config("hub")