Ejemplo n.º 1
0
    def test_load(self):
        in_data = ("{properties: {a: 'b'}, children: ["
                   "    {properties: {c: 'd'}, children: []},"
                   "    {properties: {e: 'f'}, children: ["
                   "        {properties: {g: 'h'}, children: []},"
                   "        {properties: {i: 'j'}, children: []}]},"
                   "    {properties: {k: 'l'}, children: []}]}")
        root = yaml_storage.load(in_data)
        self.assertTrue(root.parent is None)
        self.assertEqual(dict(root), {'a': 'b'})

        root_children = list(root.children())
        self.assertEqual(len(root_children), 3)
        self.assertEqual(dict(root_children[0]), {'c': 'd'})
        self.assertEqual(dict(root_children[1]), {'e': 'f'})
        self.assertEqual(dict(root_children[2]), {'k': 'l'})
        self.assertTrue(root_children[0].parent is root)
        self.assertTrue(root_children[1].parent is root)
        self.assertTrue(root_children[2].parent is root)
        self.assertEqual(len(list(root_children[0].children())), 0)
        self.assertEqual(len(list(root_children[1].children())), 2)
        self.assertEqual(len(list(root_children[2].children())), 0)

        sub_children = list(root_children[1].children())
        self.assertEqual(len(sub_children), 2)
        self.assertEqual(dict(sub_children[0]), {'g': 'h'})
        self.assertEqual(dict(sub_children[1]), {'i': 'j'})
        self.assertTrue(sub_children[0].parent is root_children[1])
        self.assertTrue(sub_children[1].parent is root_children[1])
        self.assertEqual(len(list(sub_children[0].children())), 0)
        self.assertEqual(len(list(sub_children[1].children())), 0)
Ejemplo n.º 2
0
def load_fixture_app(environ, start_response):
    global root_note
    request = webob.Request(environ)
    root_note = yaml_storage.load(request.POST['fixture'])
    return webob.Response('loaded')(environ, start_response)