Exemple #1
0
    API.open()
    PAGE = {}
    PAGE["name"] = "Pagees"
    PAGE["column"] = []
    PAGE["column"].append({"name" : 'name', "type" : "String"})
    PAGE["column"].append({"name" : 'comment', "type" : "str"})
    PAGE["column"].append({"name" : 'status', "type" : "int"})
    API.create_table(PAGE)
    ITEM = {}
    ITEM["name"] = "aParameter1"
    ITEM["comment"] = "ThisIsAnUpdate"
    ITEM["status"] = "OK"
    API.write(table=PAGE["name"], item=ITEM)
    #API.write(table=PAGE["name"], item=ITEM)
    #ITEM = {}
    #ITEM["name"] = "aParameter2"
    #ITEM["comment"] = "ThisIsAnUpdate"
    #ITEM["status"] = "OK"
    #API.write(table=PAGE["name"], item=ITEM)
    #API.write(table=PAGE["name"], item=ITEM)
    #print API.read(table="Pagees", item=ITEM)
    ITEM = {}
    ITEM["name"] = "aParameter1"
    print API.read(PAGE["name"], item=ITEM)
    #ITEM["name"] = "aParameter1"
    #API.read(PAGE["name"], item=ITEM)
    #print API.read_column_info(PAGE["name"])
    API.exit()


Exemple #2
0
class TestRead(unittest.TestCase):
    """
    Testsuite 1 to test map function
    """
    def setUp(self):
        """
        Setup function launched before a testcase
        """
        self.dbpath = 'test/db.db3'
        self.unit = SQLiteAPI(verbose=1, dbpath=self.dbpath)
        self.unit.open()

    def tearDown(self):
        """
        tearDown function launched after a testcase
        """
        os.system("rm -fr " + self.dbpath)

    def test_read_single_filter_success(self):
        """
        Simple test to be sure write function alive
        """
        # Build a table to store into the database
        table = {}
        table["name"] = "Pagees"
        table["column"] = []
        table["column"].append({"name" : 'name', "type" : "String"})
        table["column"].append({"name" : 'comment', "type" : "str"})
        table["column"].append({"name" : 'status', "type" : "int"})
        self.unit.create_table(table)
        item = {}
        item["status"] = "OK"
        self.unit.write(table=table["name"], item=item)
        ret = self.unit.read(table=table["name"], filters=item)
        self.assertEqual(list, type(ret))


    def test_read_multi_filters_success(self):
        """
        Simple test to be sure write function alive
        """
        # Build a table to store into the database
        table = {}
        table["name"] = "Pagees"
        table["column"] = []
        table["column"].append({"name" : 'name', "type" : "String"})
        table["column"].append({"name" : 'comment', "type" : "str"})
        table["column"].append({"name" : 'status', "type" : "int"})
        self.unit.create_table(table)
        item = {}
        item["name"] = "aParameter1"
        item["comment"] = "a status"
        item["status"] = "OK"
        self.unit.write(table=table["name"], item=item)
        self.unit.write(table=table["name"], item=item)
        self.unit.write(table=table["name"], item=item)
        ret = self.unit.read(table=table["name"], filters=item)

        self.assertEqual(list, type(ret))
        for lines in ret:
            self.assertEqual(list, type(lines))