def test_flush(): args = [] kwargs = {} async def do_flush(*a, **k): args.extend(a) kwargs.update(k) mm = MiddlewareManager.instance() mm.middlewares = [AutoSleep] flush = mm.get('flush', do_flush) run(flush(None, [lyr.Stack([lyr.Text('hello'), lyr.Text('wassup')])])) assert args == [ None, [ lyr.Stack([ lyr.RawText('hello'), ]), lyr.Stack([ lyr.Sleep(0.7), ]), lyr.Stack([ lyr.RawText('wassup'), ]), ] ] assert kwargs == {}
def test_stack(): l1 = layers.Text('hello') l2 = layers.Text('sup?') l3 = fbl.QuickRepliesList([ fbl.QuickRepliesList.TextOption('foo', 'Foo'), fbl.QuickRepliesList.TextOption('bar', 'Bar', intents.BAR), fbl.QuickRepliesList.LocationOption(), ]) stack = layers.Stack([l1]) assert stack.has_layer(layers.Text) assert not stack.has_layer(fbl.QuickRepliesList) assert stack.get_layer(layers.Text) == l1 with pytest.raises(KeyError): assert stack.get_layer(fbl.QuickRepliesList) is None stack.layers = [l1, l2, l3] assert stack.has_layer(fbl.QuickRepliesList) assert stack.get_layer(layers.Text) == l1 assert stack.get_layers(layers.Text) == [l1, l2] assert stack.get_layer(fbl.QuickRepliesList) == l3