本文整理汇总了Python中vumi.tests.utils.get_stubbed_worker函数的典型用法代码示例。如果您正苦于以下问题:Python get_stubbed_worker函数的具体用法?Python get_stubbed_worker怎么用?Python get_stubbed_worker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_stubbed_worker函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _setup_workers
def _setup_workers(self, bucketters, aggregators, bucket_size):
broker = FakeAMQPBroker()
self.broker = BrokerWrapper(broker)
bucket_config = {
'buckets': aggregators,
'bucket_size': bucket_size,
}
for _i in range(bucketters):
worker = get_stubbed_worker(metrics.MetricTimeBucket,
config=bucket_config,
broker=broker)
yield worker.startWorker()
self.bucket_workers.append(worker)
aggregator_config = {
'bucket_size': bucket_size,
}
for i in range(aggregators):
config = aggregator_config.copy()
config['bucket'] = i
worker = get_stubbed_worker(metrics.MetricAggregator,
config=config, broker=broker)
worker._time = self.fake_time
yield worker.startWorker()
self.aggregator_workers.append(worker)
示例2: setUp
def setUp(self):
self.config = {
'web_port': 9999,
'web_receive_path': '/t/receive',
'web_receipt_path': '/t/receipt',
'url': 'http://localhost:9998/t/send',
}
self.worker = get_stubbed_worker(TestFakeVas2NetsWorker, self.config)
self.test_worker = get_stubbed_worker(TestWorker, self.config)
self.today = datetime.utcnow().date()
示例3: setUp
def setUp(self):
self.transport_name = 'test'
self.config = {'transport_name': self.transport_name}
self.worker = get_stubbed_worker(DummyApplicationWorker,
config=self.config)
self.broker = self.worker._amqp_client.broker
yield self.worker.startWorker()
示例4: get_worker
def get_worker(self):
worker = get_stubbed_worker(RockPaperScissorsWorkerStub, {
'transport_name': 'foo',
'ussd_code': '99999',
})
worker.startWorker()
return worker
示例5: mk_failure_worker
def mk_failure_worker(self, config, broker, redis):
w = get_stubbed_worker(Vas2NetsFailureWorker, config, broker)
self.workers.append(w)
yield w.startWorker()
w.retry_publisher = yield self.worker.publish_to("foo")
w.r_server = redis
returnValue(w)
示例6: get_application
def get_application(self, config, cls=None, start=True):
"""
Get an instance of a worker class.
:param config: Config dict.
:param cls: The Application class to instantiate.
Defaults to :attr:`application_class`
:param start: True to start the application (default), False otherwise.
Some default config values are helpfully provided in the
interests of reducing boilerplate:
* ``transport_name`` defaults to :attr:`self.transport_name`
* ``send_to`` defaults to a dictionary with config for each tag
defined in worker's SEND_TO_TAGS attribute. Each tag's config
contains a transport_name set to ``<tag>_outbound``.
"""
if cls is None:
cls = self.application_class
config.setdefault('transport_name', self.transport_name)
if 'send_to' not in config and cls.SEND_TO_TAGS:
config['send_to'] = {}
for tag in cls.SEND_TO_TAGS:
config['send_to'][tag] = {
'transport_name': '%s_outbound' % tag}
worker = get_stubbed_worker(cls, config, self._amqp)
self._workers.append(worker)
if start:
yield worker.startWorker()
returnValue(worker)
示例7: test_bucketing
def test_bucketing(self):
config = {'buckets': 4, 'bucket_size': 5}
worker = get_stubbed_worker(metrics.MetricTimeBucket, config=config)
broker = BrokerWrapper(worker._amqp_client.broker)
yield worker.startWorker()
datapoints = [
("vumi.test.foo", ("agg",), [(1230, 1.5), (1235, 2.0)]),
("vumi.test.bar", ("sum",), [(1240, 1.0)]),
]
broker.send_datapoints("vumi.metrics", "vumi.metrics", datapoints)
yield broker.kick_delivery()
buckets = [broker.recv_datapoints("vumi.metrics.buckets",
"bucket.%d" % i) for i in range(4)]
expected_buckets = [
[],
[[[u'vumi.test.bar', ['sum'], [[1240, 1.0]]]]],
[[[u'vumi.test.foo', ['agg'], [[1230, 1.5]]]],
[[u'vumi.test.foo', ['agg'], [[1235, 2.0]]]]],
[],
]
self.assertEqual(buckets, expected_buckets)
yield worker.stopWorker()
示例8: test_send_to_with_no_send_to_tags
def test_send_to_with_no_send_to_tags(self):
config = {'transport_name': 'notags_app'}
notags_worker = get_stubbed_worker(ApplicationWorker,
config=config)
yield notags_worker.startWorker()
self.assertRaises(ValueError, notags_worker.send_to,
'+12345', "Hi!")
示例9: get_worker
def get_worker(self, **config_extras):
if getattr(self, 'worker', None) is not None:
yield self.worker.stopWorker()
config = {
"transport_names": [
"transport1",
"transport2",
"transport3",
],
"exposed_names": [
"app1",
"app2",
"app3",
],
"router_class": "vumi.dispatchers.base.SimpleDispatchRouter",
"route_mappings": {
"transport1": ["app1"],
"transport2": ["app2"],
"transport3": ["app1", "app3"]
},
}
config.update(config_extras)
self.worker = get_stubbed_worker(BaseDispatchWorker, config)
self._amqp = self.worker._amqp_client.broker
yield self.worker.startWorker()
示例10: get_worker
def get_worker(self):
worker = get_stubbed_worker(MemoWorker, {
# 'transport_name': 'foo',
# 'ussd_code': '99999',
})
yield worker.startWorker()
returnValue(worker)
示例11: mk_resource_worker
def mk_resource_worker(self, body, headers=None, code=http.OK):
w = get_stubbed_worker(TestResourceWorker, {}, self.broker)
self.workers.append(w)
w.set_resources([(self.path, BadVas2NetsResource,
(body, headers, code))])
yield w.startWorker()
returnValue(w)
示例12: make_resource_worker
def make_resource_worker(self, code=http.OK, content='',
headers={}, callback=None):
w = get_stubbed_worker(TestResourceWorker, {})
w.set_resources([
(self.path, TestResource, (code, content, headers, callback))])
self._workers.append(w)
yield w.startWorker()
returnValue(w)
示例13: get_worker
def get_worker(self):
worker = get_stubbed_worker(RockPaperScissorsWorker, {
'transport_name': 'foo',
'ussd_code': '99999',
}, self._amqp)
self._workers.append(worker)
worker.startWorker()
return worker
示例14: test_start_publisher
def test_start_publisher(self):
"""The publisher should publish"""
worker = get_stubbed_worker(Worker)
publisher = yield worker.publish_to('test.routing.key')
self.assertEquals(publisher.routing_key, 'test.routing.key')
publisher.publish_message(Message(key="value"))
[published_msg] = publisher.channel.broker.get_dispatched(
'vumi', 'test.routing.key')
self.assertEquals(published_msg.body, '{"key": "value"}')
self.assertEquals(published_msg.properties, {'delivery mode': 2})
示例15: get_worker
def get_worker(self, config=None):
if not config:
config = {
'worker_name': 'wikitest',
'sms_transport': 'sphex',
}
config.setdefault('transport_name', self.transport_name)
worker = get_stubbed_worker(WikipediaWorker, config, self.broker)
self._workers.append(worker)
yield worker.startWorker()
returnValue(worker)