def test_emit_process_completed():
    mocked_response = {
        'FailedEntryCount': 0,
        'Entries': [{
            'EventId': '00000000-0000-0000-0000-000000000000'
        }]
    }
    expected_params = {
        'Entries': [{
            'Source': 'scheduled-event-adjuster',
            'DetailType': 'ProcessCompleted',
            'Detail': '{"Updates": [{"foo": "bar"}]}',
            'EventBusName': 'default'
        }]
    }
    eventbridge_client = boto3.client('events')
    stubber = Stubber(eventbridge_client)
    stubber.add_response('put_events', mocked_response, expected_params)
    bus = EventBus(eventbridge_client)

    with stubber:
        response = bus.emit_process_completed([{'foo': 'bar'}])
        assert response == mocked_response
예제 #2
0
파일: server.py 프로젝트: cagerton/pixelpie
        pusher = event.obj
        data = json.dumps({'type': 'update', 'data': {pusher.mac: pusher.conf}})
        self.write_message(data)


class NocacheStaticFileHandler(web.StaticFileHandler):
    def set_extra_headers(self, path):
        # Disable cache
        self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')



if __name__ == '__main__':
    # Setup logging for the signal bus
    l = Listener('ws.open', lambda x:logging.error("open signal!"))
    EventBus.instance().register_listener(l)

    # listen for udp broadcasts & keep track of pushers.
    pusher_index = PusherIndex()

    # Setup web application

    static_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),'static')
    if not os.path.exists(static_path):
        logging.error("Can't find static path? %s", static_path)

    application = tornado.web.Application([
        (r'/ws', PusherWebSocket),
        #(r"/(.*)", web.StaticFileHandler, {"path": os.path.join(__file__, '..', 'static')}),
        (r"/static/(.*)", NocacheStaticFileHandler, {"path": static_path}),
예제 #3
0
 def setUp(self):
     self.bus = EventBus()
     super().setUp()
예제 #4
0
class SignalsTest(AsyncTestCase):

    def setUp(self):
        self.bus = EventBus()
        super().setUp()

    @gen_test(timeout=0.2)
    def test_basic_signal(self):
        res = []
        hit = lambda x: res.append(True)
        listener = Listener('pp.found', hit, async=False)

        res2 = []
        hit2 = lambda x: res2.append(True)
        listener2 = Listener('pp.found', hit2, async=True)

        self.bus.register_listener(listener)
        self.bus.register_listener(listener2)

        self.assertEqual(len(res), 0)
        signal = Event('pp.something-else')

        self.bus.trigger_signal(signal)
        self.assertEqual(len(res), 0)

        signal = Event('pp.found')
        self.bus.trigger_signal(signal)
        self.assertEqual(len(res), 1)
        self.assertEqual(len(res2), 0)
        yield gen.Task(self.io_loop.current().add_timeout, timedelta(milliseconds=2))
        self.assertEqual(len(res2), 1)

    def test_with_obj(self):
        obj = 1
        res = []
        hit = lambda x: res.append(True)
        signal = Event('pp', obj=obj)
        listener = Listener('pp', hit, obj=obj, async=False)

        obj2='foo'
        res2 = []
        hit2 = lambda x: res2.append(True)
        signal2 = Event('pp', obj=obj2)
        listener2 = Listener('pp', hit2, obj=obj2,  async=False)

        self.bus.register_listener(listener)
        self.bus.register_listener(listener2)

        self.bus.trigger_signal(signal)
        self.bus.trigger_signal(signal2)

        self.assertEqual(len(res), 1)
        self.assertEqual(len(res2), 1)

    def test_removal(self):
        res = []
        hit = lambda x:res.append(True)
        listener = Listener('pp.found', hit, async=False)
        self.bus.register_listener(listener)
        signal = Event('pp.found')
        self.bus.trigger_signal(signal)
        self.bus.remove_listener(listener)
        self.assertEqual(len(res), 1)
        self.bus.trigger_signal(signal)
        self.assertEqual(len(res), 1)

    @gen_test(timeout=0.2)
    def test_basic_mixin_and_decorator(self):
        tc = TestClass()
        self.assertEqual(tc.observed, 0)
        tc.ping()

        yield gen.Task(self.io_loop.current().add_timeout, timedelta(milliseconds=2))
        self.assertEqual(tc.observed, 1)