Beispiel #1
0
class TestDatabase(unittest.TestCase):
    def setUp(self):
        self.sql = SkyFront("sqlite", "test.sqlite")
        self.sql.executeQuery(table_create)

    def tearDown(self):
        os.unlink("test.sqlite")
Beispiel #2
0
 def setUp(self):
     self.sql = SkyFront("sqlite", "test.sqlite")
     self.sql.executeQuery(table_create)
Beispiel #3
0
 def setUp(self):
     self.sql = SkyFront()
Beispiel #4
0
class TestGenerator(unittest.TestCase):
    def setUp(self):
        self.sql = SkyFront()

    def test_generation(self):
        self.assertEquals(
            self.sql.insertNew("test", None, name="Alabama", title="AL", text="Audemus jura nostra defendere"),
            u"INSERT INTO `test` (text, name, title) VALUES('Audemus jura nostra defendere', 'Alabama', 'AL')",
        )
        self.assertEquals(self.sql.getRecords("test"), u"SELECT DISTINCT * FROM `test`")
        self.assertEquals(
            self.sql.getRecords("test", ["name", "title"], limit=3, limstart=2, order="text"),
            u"SELECT DISTINCT name,title FROM `test` ORDER BY text LIMIT 2,3",
        )
        self.assertEquals(
            self.sql.getRecords("test", ["name", "title"], limit=2, id=[2, ">"]),
            u"SELECT DISTINCT name,title FROM `test` WHERE id > '2' LIMIT 0,2",
        )
        self.assertEquals(
            self.sql.updateRecords(
                "test", {"name": "Connecticut", "title": "CT", "text": "Qui transtulit sustinet"}, id=5
            ),
            u"UPDATE `test` SET text='Qui transtulit sustinet', name='Connecticut', title='CT' WHERE id = '5'",
        )
        self.assertEquals(self.sql.delete("test", id=5), u"DELETE FROM test WHERE id = '5'")
        self.assertEquals(self.sql.getCount("test", id=[2, ">"]), u"SELECT COUNT(*) FROM `test` WHERE id > '2'")

    def test_clause(self):
        self.assertEquals(self.sql.createClause(one=1), u"WHERE one = '1'")
        self.assertEquals(self.sql.createClause(one=[1, ">"]), u"WHERE one > '1'")
        self.assertEquals(
            self.sql.createClause(one=[1, ">", 40, "<", "%3%", "LIKE"]),
            u"WHERE one > '1' AND one < '40' AND one LIKE '%3%'",
        )
        self.assertEquals(
            self.sql.createClause(one=[["%3", "LIKE"], "OR", ["2", "NOT"], "AND"]),
            u"WHERE (one LIKE '%3') AND (one NOT '2')",
        )
        self.assertEquals(self.sql.createClause(False, one=[1, ">", 40, "<"]), u"WHERE one > '1' OR one < '40'")
        self.assertEquals(
            self.sql.createClause(
                one="1",
                two=["2"],
                three=["3", ">"],
                four=[["4_1", ">", "4_2", "<"], "AND", "4"],
                five=[
                    [["%5_1_1", "LIKE"], "OR", ["5_1_3", "NOT"], "AND"],
                    "AND",
                    ["5_2_1", ">", "5_2_2"],
                    "OR",
                    "5_3",
                    "NOT",
                ],
            ),
            u"WHERE (four > '4_1' AND four < '4_2') AND four = '4' AND three > '3' \
AND ((five LIKE '%5_1_1') AND (five NOT '5_1_3')) AND (five > '5_2_1' OR five = '5_2_2') \
AND five NOT '5_3' AND two = '2' AND one = '1'",
        )