def test_empty_func(self): def noop(doc): pass handler = FunctionHandler(noop) doc = Document() handler.modify_document(doc) if handler.failed: raise RuntimeError(handler.error) assert not doc.roots
def test_func_adds_roots(self): def add_roots(doc): doc.add_root(AnotherModelInTestFunction()) doc.add_root(SomeModelInTestFunction()) handler = FunctionHandler(add_roots) doc = Document() handler.modify_document(doc) if handler.failed: raise RuntimeError(handler.error) assert len(doc.roots) == 2
def test_pull_document(self): application = Application() def add_roots(doc): doc.add_root(AnotherModelInTestClientServer(bar=43)) doc.add_root(SomeModelInTestClientServer(foo=42)) handler = FunctionHandler(add_roots) application.add(handler) with ManagedServerLoop(application) as server: client_session = pull_session(session_id='test_pull_document', url=server.ws_url, io_loop=server.io_loop) assert len(client_session.document.roots) == 2 server_session = server.get_session('/', client_session.id) assert len(server_session.document.roots) == 2 results = {} for r in server_session.document.roots: if hasattr(r, 'foo'): results['foo'] = r.foo if hasattr(r, 'bar'): results['bar'] = r.bar assert results['foo'] == 42 assert results['bar'] == 43 client_session.close() client_session.loop_until_closed() assert not client_session.connected
def test_two_handlers(self): a = Application() def add_roots(doc): doc.add_root(AnotherModelInTestApplication()) doc.add_root(SomeModelInTestApplication()) def add_one_root(doc): doc.add_root(AnotherModelInTestApplication()) handler = FunctionHandler(add_roots) a.add(handler) handler2 = FunctionHandler(add_one_root) a.add(handler2) doc = a.create_document() assert len(doc.roots) == 3