Example #1
0
    def test_orphans(self):

        clean_dir(_datapath + "/conn")

        # create new notebook
        conn = fs.NoteBookConnectionFS()
        conn.connect(_datapath + "/conn")
        rootid = new_nodeid()
        conn.create_node(rootid, {"nodeid": rootid,
                                  "parentids": [],
                                  "key": 12})

        # check orphan dir
        self.assertTrue(
            os.path.exists(_datapath + "/conn/__NOTEBOOK__/orphans"))

        # make orphan
        nodeid = new_nodeid()
        conn.create_node(nodeid, {"nodeid": nodeid,
                                  "aaa": 3.4})
        attr = conn.read_node(nodeid)
        print(attr)

        # check orphan node dir
        assert os.path.exists(
            _datapath + "/conn/__NOTEBOOK__/orphans/%s/%s"
            % (nodeid[:2], nodeid[2:]))

        # update orphan
        attr["aaa"] = 0
        conn.update_node(nodeid, attr)
        attr = conn.read_node(nodeid)
        print(attr)

        # check orphan node dir
        print(open(_datapath + "/conn/__NOTEBOOK__/orphans/%s/%s/node.xml"
                   % (nodeid[:2], nodeid[2:])).read())

        # move orphan out of orphandir
        attr["parentids"] = [rootid]
        conn.update_node(nodeid, attr)
        print(conn.read_node(nodeid))

        # check orphan node dir is gone
        assert not os.path.exists(
            _datapath + "/conn/__NOTEBOOK__/orphans/%s/%s"
            % (nodeid[:2], nodeid[2:]))

        # move node into orphandir
        attr["parentids"] = []
        conn.update_node(nodeid, attr)
        print(conn.read_node(nodeid))

        # check orphan node dir is gone
        self.assertTrue(os.path.exists(
            _datapath + "/conn/__NOTEBOOK__/orphans/%s/%s"
            % (nodeid[:2], nodeid[2:])))
    def test_orphans(self):

        clean_dir(_datapath + "/conn")

        # create new notebook
        conn = fs.NoteBookConnectionFS()
        conn.connect(_datapath + "/conn")
        rootid = new_nodeid()
        conn.create_node(rootid, {"nodeid": rootid,
                                  "parentids": [],
                                  "key": 12})

        # check orphan dir
        self.assertTrue(
            os.path.exists(_datapath + "/conn/__NOTEBOOK__/orphans"))

        # make orphan
        nodeid = new_nodeid()
        conn.create_node(nodeid, {"nodeid": nodeid,
                                  "aaa": 3.4})
        attr = conn.read_node(nodeid)
        print attr

        # check orphan node dir
        assert os.path.exists(
            _datapath + "/conn/__NOTEBOOK__/orphans/%s/%s"
            % (nodeid[:2], nodeid[2:]))

        # update orphan
        attr["aaa"] = 0
        conn.update_node(nodeid, attr)
        attr = conn.read_node(nodeid)
        print attr

        # check orphan node dir
        print open(_datapath + "/conn/__NOTEBOOK__/orphans/%s/%s/node.xml"
                   % (nodeid[:2], nodeid[2:])).read()

        # move orphan out of orphandir
        attr["parentids"] = [rootid]
        conn.update_node(nodeid, attr)
        print conn.read_node(nodeid)

        # check orphan node dir is gone
        assert not os.path.exists(
            _datapath + "/conn/__NOTEBOOK__/orphans/%s/%s"
            % (nodeid[:2], nodeid[2:]))

        # move node into orphandir
        attr["parentids"] = []
        conn.update_node(nodeid, attr)
        print conn.read_node(nodeid)

        # check orphan node dir is gone
        self.assertTrue(os.path.exists(
            _datapath + "/conn/__NOTEBOOK__/orphans/%s/%s"
            % (nodeid[:2], nodeid[2:])))
Example #3
0
    def create_node_view(self, nodeid=None):
        """
        Create new notebook node.
        """
        if nodeid is not None:
            nodeid = urllib.unquote(nodeid)
        else:
            nodeid = new_nodeid()

        data = request.body.read()
        attr = json.loads(data)

        try:
            self.conn.create_node(nodeid, attr)
        except connlib.NodeExists, e:
            keepnote.log_error()
            abort(FORBIDDEN, 'node already exists.' + str(e))
Example #4
0
    def create_node_view(self, nodeid=None):
        """
        Create new notebook node.
        """
        if nodeid is not None:
            nodeid = urllib.unquote(nodeid)
        else:
            nodeid = new_nodeid()

        data = request.body.read()
        attr = json.loads(data)

        try:
            self.conn.create_node(nodeid, attr)
        except connlib.NodeExists, e:
            keepnote.log_error()
            abort(FORBIDDEN, 'node already exists.' + str(e))
Example #5
0
    def create_node_view(self, nodeid=None):
        """
        Create new notebook node.
        """
        if nodeid is not None:
            nodeid = urllib.unquote(nodeid)
        else:
            nodeid = new_nodeid()

        data = request.body.read()
        attr = json.loads(data)

        # Enforce notebook scheme, nodeid is required.
        attr['nodeid'] = nodeid

        try:
            self.conn.create_node(nodeid, attr)
        except connlib.NodeExists as e:
            keepnote.log_error()
            abort(FORBIDDEN, 'node already exists.' + str(e))

        return self.json_response(attr)