本文整理汇总了Python中autopush.db.Router类的典型用法代码示例。如果您正苦于以下问题:Python Router类的具体用法?Python Router怎么用?Python Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Router类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_drop_user
def test_drop_user(self):
uaid = str(uuid.uuid4())
r = get_router_table()
router = Router(r, SinkMetrics())
# Register a node user
router.register_user(dict(uaid=uaid, node_id="asdf",
connected_at=1234))
router.drop_user(uaid)
示例2: test_incomplete_uaid
def test_incomplete_uaid(self):
uaid = str(uuid.uuid4())
r = get_router_table()
router = Router(r, SinkMetrics())
router.register_user(dict(uaid=uaid))
self.assertRaises(ItemNotFound, router.get_uaid, uaid)
self.assertRaises(ItemNotFound, router.table.get_item,
consistent=True, uaid=uaid)
示例3: test_save_new
def test_save_new(self):
r = get_router_table()
router = Router(r, SinkMetrics())
# Sadly, moto currently does not return an empty value like boto
# when not updating data.
router.table.connection = Mock()
router.table.connection.update_item.return_value = {}
result = router.register_user(dict(uaid="", node_id="me", connected_at=1234))
eq_(result[0], True)
示例4: test_save_uaid
def test_save_uaid(self):
uaid = str(uuid.uuid4())
r = get_router_table()
router = Router(r, SinkMetrics())
result = router.register_user(dict(uaid=uaid, node_id="me", connected_at=1234))
eq_(result[0], True)
eq_(result[1], {"uaid": uaid, "connected_at": 1234, "node_id": "me"})
result = router.get_uaid(uaid)
eq_(bool(result), True)
eq_(result["node_id"], "me")
示例5: test_drop_user
def test_drop_user(self):
uaid = str(uuid.uuid4())
r = get_router_table()
router = Router(r, SinkMetrics())
# Register a node user
router.register_user(dict(uaid=uaid, node_id="asdf", connected_at=1234))
result = router.drop_user(uaid)
eq_(result, True)
# Deleting already deleted record should return false.
result = router.drop_user(uaid)
eq_(result, False)
示例6: test_clear_node_provision_failed
def test_clear_node_provision_failed(self):
r = get_router_table()
router = Router(r, SinkMetrics())
router.table.connection.put_item = Mock()
def raise_error(*args, **kwargs):
raise ProvisionedThroughputExceededException(None, None)
router.table.connection.put_item.side_effect = raise_error
with self.assertRaises(ProvisionedThroughputExceededException):
router.clear_node(Item(r, dict(uaid="asdf", connected_at="1234", node_id="asdf")))
示例7: test_register_user_provision_failed
def test_register_user_provision_failed(self):
r = get_router_table()
router = Router(r, SinkMetrics())
router.table.connection = Mock()
def raise_error(*args, **kwargs):
raise ProvisionedThroughputExceededException(None, None)
router.table.connection.update_item.side_effect = raise_error
with self.assertRaises(ProvisionedThroughputExceededException):
router.register_user(dict(uaid="asdf", node_id="me", connected_at=1234))
示例8: test_uaid_provision_failed
def test_uaid_provision_failed(self):
r = get_router_table()
router = Router(r, SinkMetrics())
router.table = Mock()
def raise_error(*args, **kwargs):
raise ProvisionedThroughputExceededException(None, None)
router.table.get_item.side_effect = raise_error
with self.assertRaises(ProvisionedThroughputExceededException):
router.get_uaid(uaid="asdf")
示例9: test_node_clear_fail
def test_node_clear_fail(self):
r = get_router_table()
router = Router(r, SinkMetrics())
def raise_condition(*args, **kwargs):
raise ConditionalCheckFailedException(None, None)
router.table.connection.put_item = Mock()
router.table.connection.put_item.side_effect = raise_condition
data = dict(uaid="asdf", node_id="asdf", connected_at=1234)
result = router.clear_node(Item(r, data))
eq_(result, False)
示例10: test_save_fail
def test_save_fail(self):
r = get_router_table()
router = Router(r, SinkMetrics())
def raise_condition(*args, **kwargs):
raise ConditionalCheckFailedException(None, None)
router.table.connection = Mock()
router.table.connection.update_item.side_effect = raise_condition
router_data = dict(uaid="asdf", node_id="asdf", connected_at=1234)
result = router.register_user(router_data)
eq_(result, (False, {}, router_data))
示例11: test_preflight_check_fail
def test_preflight_check_fail(self):
router = Router(get_router_table(), SinkMetrics())
storage = Storage(get_storage_table(), SinkMetrics())
def raise_exc(*args, **kwargs): # pragma: no cover
raise Exception("Oops")
router.clear_node = Mock()
router.clear_node.side_effect = raise_exc
with self.assertRaises(Exception):
preflight_check(storage, router)
示例12: test_node_clear
def test_node_clear(self):
r = get_router_table()
router = Router(r, SinkMetrics())
# Register a node user
router.register_user(dict(uaid="asdf", node_id="asdf", connected_at=1234))
# Verify
user = router.get_uaid("asdf")
eq_(user["node_id"], "asdf")
# Clear
router.clear_node(user)
# Verify
user = router.get_uaid("asdf")
eq_(user.get("node_id"), None)
示例13: test_node_clear
def test_node_clear(self):
r = get_router_table()
router = Router(r, SinkMetrics())
# Register a node user
router.register_user(dict(uaid=dummy_uaid, node_id="asdf",
connected_at=1234,
router_key="webpush"))
# Verify
user = router.get_uaid(dummy_uaid)
eq_(user["node_id"], "asdf")
eq_(user["connected_at"], 1234)
eq_(user["router_key"], "webpush")
# Clear
router.clear_node(user)
# Verify
user = router.get_uaid(dummy_uaid)
eq_(user.get("node_id"), None)
eq_(user["connected_at"], 1234)
eq_(user["router_key"], "webpush")