Ejemplo n.º 1
0
 def __init__(self, worker_class, options, config):
     self.options = options
     self.config = config
     self.spec = get_spec(make_vumi_path_abs(options['specfile']))
     self.delegate = TwistedDelegate()
     self.worker = None
     self.worker_class = worker_class
Ejemplo n.º 2
0
    def test_fake_amqclient(self):
        spec = get_spec(make_vumi_path_abs("config/amqp-spec-0-8.xml"))
        amq_client = fake_amqp.FakeAMQClient(spec, {}, self.broker)
        d = Deferred()

        class TestWorker(Worker):
            @inlineCallbacks
            def startWorker(self):
                self.pub = yield self.publish_to('test.pub')
                self.conpub = yield self.publish_to('test.con')
                self.con = yield self.consume('test.con', self.consume_msg)

            def consume_msg(self, msg):
                # NOTE: One-shot.
                d.callback(msg)

        worker = TestWorker(amq_client, {})
        yield worker.startWorker()
        yield worker.pub.publish_json({'message': 'foo'})
        yield worker.conpub.publish_json({'message': 'bar'})
        msg = yield d
        self.assertEqual({'message': 'bar'}, msg.payload)
Ejemplo n.º 3
0
def get_stubbed_channel(broker=None, id=0):
    spec = get_spec(make_vumi_path_abs("config/amqp-spec-0-8.xml"))
    amq_client = FakeAMQClient(spec, {}, broker)
    return amq_client.channel(id)
Ejemplo n.º 4
0
def get_stubbed_worker(worker_class, config=None, broker=None):
    spec = get_spec(make_vumi_path_abs("config/amqp-spec-0-8.xml"))
    amq_client = FakeAMQClient(spec, {}, broker)
    worker = worker_class(amq_client, config)
    return worker
Ejemplo n.º 5
0
 def test_make_campaign_path_abs(self):
     vumi_tests_path = os.path.dirname(__file__)
     vumi_path = os.path.dirname(os.path.dirname(vumi_tests_path))
     self.assertEqual('/foo/bar', make_vumi_path_abs('/foo/bar'))
     self.assertEqual(os.path.join(vumi_path, 'foo/bar'),
                      make_vumi_path_abs('foo/bar'))