def test_remove_valueerror(self): root = wsgi.String() child1 = wsgi.String() self.assertEqual(len(root.children), 0) root.remove(child1) self.assertEqual(len(root.children), 0) child1.append_to(root) self.assertEqual(len(root.children), 1) self.assertEqual(child1.parent, root)
def test_append(self): root = wsgi.String() child1 = wsgi.String() child2 = wsgi.String() root.append(child1) self.assertEqual(child1.parent, root) self.assertEqual(len(root.children), 1) root.prepend(child2) self.assertEqual(child2.parent, root) self.assertEqual(len(root.children), 2)
def test_append_parent(self): root = wsgi.String() child1 = wsgi.String() child2 = wsgi.String() root.append(child1) root.append(child2) self.assertEqual(len(root.children), 2) child1.append(root) self.assertEqual(child1.parent, None) self.assertEqual(root.parent, child1) self.assertEqual(len(root.children), 1) self.assertEqual(len(child1.children), 1)
def test_change_parent(self): root = wsgi.String() child1 = wsgi.String() child2 = wsgi.String() child3 = wsgi.String() root.append(child1) child1.append(child2) child1.append(child3) self.assertEqual(len(root.children), 1) self.assertEqual(len(child1.children), 2) root.append(child3) self.assertEqual(len(root.children), 2) self.assertEqual(len(child1.children), 1)
def test_append_parent_with_parent(self): root = wsgi.String() child1 = wsgi.String() child2 = wsgi.String() child3 = wsgi.String() root.append(child1) child1.append(child2) child1.append(child3) self.assertEqual(len(root.children), 1) self.assertEqual(len(child1.children), 2) child2.append(child1) self.assertEqual(len(root.children), 1) self.assertEqual(root.children[0], child2) self.assertEqual(len(child2.children), 1) self.assertEqual(child1.parent, child2) self.assertEqual(child2.parent, root)
def test_json_with_async_string(self): astr = wsgi.String('ciao') response = wsgi.Json({'bla': astr}) self.assertEqual(len(response.children), 1) self.assertEqual(response.content_type, 'application/json; charset=utf-8') self.assertEqual(response.render(), json.dumps({'bla': 'ciao'}))
async def test_json_with_async_string2(self): d = Future() astr = wsgi.String(d) response = wsgi.Json({'bla': astr}) self.assertEqual(len(response.children), 1) result = response.render() self.assertIsInstance(result, Future) d.set_result('ciao') result = await result self.assertEqual(result, json.dumps({'bla': 'ciao'}))
def test_string(self): a = wsgi.String('Hello') self.assertEqual(a.render(), 'Hello') self.assertRaises(RuntimeError, a.render)
def test_append_self(self): root = wsgi.String() self.assertEqual(root.parent, None) root.append(root) self.assertEqual(root.parent, None) self.assertEqual(len(root.children), 0)
def test_string(self): a = wsgi.String('Hello') self.assertEqual(a.to_string(), 'Hello')