sql-testing-tools 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sql_testing_tools-0.2.4/PKG-INFO +127 -0
- sql_testing_tools-0.2.4/README.md +117 -0
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/setup.py +1 -1
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools/Helper.py +121 -16
- sql_testing_tools-0.2.4/sql_testing_tools.egg-info/PKG-INFO +127 -0
- sql_testing_tools-0.2.3/PKG-INFO +0 -50
- sql_testing_tools-0.2.3/README.md +0 -40
- sql_testing_tools-0.2.3/sql_testing_tools.egg-info/PKG-INFO +0 -50
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/setup.cfg +0 -0
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools/BaseAccess.py +0 -0
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools/TokenProcessing.py +0 -0
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools/__init__.py +0 -0
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools.egg-info/SOURCES.txt +0 -0
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools.egg-info/dependency_links.txt +0 -0
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools.egg-info/requires.txt +0 -0
- {sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: sql_testing_tools
|
|
3
|
+
Version: 0.2.4
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
Requires-Dist: sqlparse>=0.5.1
|
|
6
|
+
Requires-Dist: requests>=2.32.3
|
|
7
|
+
Dynamic: description
|
|
8
|
+
Dynamic: description-content-type
|
|
9
|
+
Dynamic: requires-dist
|
|
10
|
+
|
|
11
|
+
A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
|
|
12
|
+
|
|
13
|
+
### [Beta in Development!]
|
|
14
|
+
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
|
|
15
|
+
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
|
|
16
|
+
|
|
17
|
+
- Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
|
|
18
|
+
- PyPi-Package available at: https://pypi.org/project/sql-testing-tools/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Getting started
|
|
23
|
+
|
|
24
|
+
Use the following code to import the SQL Testing Tools to your project:
|
|
25
|
+
``` python
|
|
26
|
+
# ensure to always use the latest version of sql_testing_tools
|
|
27
|
+
import os
|
|
28
|
+
os.system('pip install -U sql_testing_tools')
|
|
29
|
+
|
|
30
|
+
# import sql_testing_tools
|
|
31
|
+
import sql_testing_tools.BaseAccess as Ba
|
|
32
|
+
import sql_testing_tools.Helper as He
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
On global level of your test class, set the SQLite database you want to use (bases must be located in the repository of the test class, no DBs contained in sql_testing_tools).
|
|
36
|
+
``` python
|
|
37
|
+
import unittest
|
|
38
|
+
class TestClass(unittest.TestCase):
|
|
39
|
+
Ba.setDBName("databases/ladepunkte.db")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The following methods are available for use in test methods:
|
|
43
|
+
``` python
|
|
44
|
+
try:
|
|
45
|
+
Ba.runAndGetStringTable_fromFile("sqlfile.sql")
|
|
46
|
+
except Exception as e:
|
|
47
|
+
# the execution failed
|
|
48
|
+
# (usually due to syntax or database errors)
|
|
49
|
+
self.fail(e)
|
|
50
|
+
|
|
51
|
+
# (optional) set the files to be compared. The sql strings will
|
|
52
|
+
# be normalized and used for all following methods (to improve
|
|
53
|
+
# performance), until new files are set. Arguments that are
|
|
54
|
+
# None or "" are ignored and the sql string remains the same.
|
|
55
|
+
# Raises an Exception if one of the files is empty.
|
|
56
|
+
setup("sqlfile.sql","solution.sql")
|
|
57
|
+
|
|
58
|
+
# All following methods call setup(sql,sol) before executing
|
|
59
|
+
# anything else. Call without arguments to keep the last
|
|
60
|
+
# normalized sql strings (and improve performance).
|
|
61
|
+
# Each check was successfull if "" is returned. Returns a
|
|
62
|
+
# German error message if not.
|
|
63
|
+
# Each method compares the normalized string between the start
|
|
64
|
+
# keyword and the next keyword or ;
|
|
65
|
+
|
|
66
|
+
res = He.checkColumns() # starts to search at keyword "SELECT"
|
|
67
|
+
res = He.checkTables() # starts to search at keyword "FROM"
|
|
68
|
+
res = He.checkCondition() # starts to search at keyword "WHERE"
|
|
69
|
+
res = He.checkOrder() # starts to search at keyword "ORDER BY"
|
|
70
|
+
res = He.checkGroup() # starts to search at keyword "GROUP BY"
|
|
71
|
+
|
|
72
|
+
# can not be called with new sql files
|
|
73
|
+
res = checkKeywords("startKeyword",["end","keywords"])
|
|
74
|
+
|
|
75
|
+
# compares equality of the full normalized sql strings and if
|
|
76
|
+
# not equal uses the Cosette API (cosette.cs.washington.edu)
|
|
77
|
+
# for comparison. A file 'cosette_apikey.txt' with only the
|
|
78
|
+
# apikey in it on root level of the test repository is required
|
|
79
|
+
# to use this feature. If not existant, only the string comparison
|
|
80
|
+
# is performed.
|
|
81
|
+
# Warning: Cosette is not maintained!
|
|
82
|
+
res = checkEquality()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Changelog
|
|
94
|
+
|
|
95
|
+
##### V0.2.4
|
|
96
|
+
- Added more check methods for single parts of queries: checkColumns, checkTables, checkCondition, checkOrder, checkGroup, checkKeywords
|
|
97
|
+
|
|
98
|
+
##### V 0.2.3
|
|
99
|
+
- fix: ASC/DESC in ORDER BY (also with multiple columns and order directions), no direction treated as ASC
|
|
100
|
+
- Verified that ; and whitespaces, linebreaks at end of query are ignored
|
|
101
|
+
|
|
102
|
+
##### V 0.2.2
|
|
103
|
+
- Support LIKE
|
|
104
|
+
- Support '<=' and '>=' (geq and leq)
|
|
105
|
+
|
|
106
|
+
##### V 0.2.1
|
|
107
|
+
- Support LIMIT
|
|
108
|
+
|
|
109
|
+
##### V 0.1.9 + 0.2.0
|
|
110
|
+
- Support ORDER BY
|
|
111
|
+
|
|
112
|
+
##### V 0.1.8
|
|
113
|
+
- Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
|
|
114
|
+
|
|
115
|
+
##### V 0.1.6 + V 0.1.7
|
|
116
|
+
- Fixed import error to ensure imports working in different environments
|
|
117
|
+
|
|
118
|
+
##### V 0.1.4 + V 0.1.5
|
|
119
|
+
- Chained conditions (with AND,OR and Paranthesises) in WHERE statement
|
|
120
|
+
- Aggregate Functions
|
|
121
|
+
|
|
122
|
+
##### V 0.1.3
|
|
123
|
+
- SELECT: columns with our without table prefix
|
|
124
|
+
- FROM: one or more table from DB; no queries as tables!
|
|
125
|
+
- WHERE: single conditions; no Paranthesises!
|
|
126
|
+
- GROUP BY one or more columns
|
|
127
|
+
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
|
|
2
|
+
|
|
3
|
+
### [Beta in Development!]
|
|
4
|
+
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
|
|
5
|
+
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
|
|
6
|
+
|
|
7
|
+
- Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
|
|
8
|
+
- PyPi-Package available at: https://pypi.org/project/sql-testing-tools/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Getting started
|
|
13
|
+
|
|
14
|
+
Use the following code to import the SQL Testing Tools to your project:
|
|
15
|
+
``` python
|
|
16
|
+
# ensure to always use the latest version of sql_testing_tools
|
|
17
|
+
import os
|
|
18
|
+
os.system('pip install -U sql_testing_tools')
|
|
19
|
+
|
|
20
|
+
# import sql_testing_tools
|
|
21
|
+
import sql_testing_tools.BaseAccess as Ba
|
|
22
|
+
import sql_testing_tools.Helper as He
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
On global level of your test class, set the SQLite database you want to use (bases must be located in the repository of the test class, no DBs contained in sql_testing_tools).
|
|
26
|
+
``` python
|
|
27
|
+
import unittest
|
|
28
|
+
class TestClass(unittest.TestCase):
|
|
29
|
+
Ba.setDBName("databases/ladepunkte.db")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The following methods are available for use in test methods:
|
|
33
|
+
``` python
|
|
34
|
+
try:
|
|
35
|
+
Ba.runAndGetStringTable_fromFile("sqlfile.sql")
|
|
36
|
+
except Exception as e:
|
|
37
|
+
# the execution failed
|
|
38
|
+
# (usually due to syntax or database errors)
|
|
39
|
+
self.fail(e)
|
|
40
|
+
|
|
41
|
+
# (optional) set the files to be compared. The sql strings will
|
|
42
|
+
# be normalized and used for all following methods (to improve
|
|
43
|
+
# performance), until new files are set. Arguments that are
|
|
44
|
+
# None or "" are ignored and the sql string remains the same.
|
|
45
|
+
# Raises an Exception if one of the files is empty.
|
|
46
|
+
setup("sqlfile.sql","solution.sql")
|
|
47
|
+
|
|
48
|
+
# All following methods call setup(sql,sol) before executing
|
|
49
|
+
# anything else. Call without arguments to keep the last
|
|
50
|
+
# normalized sql strings (and improve performance).
|
|
51
|
+
# Each check was successfull if "" is returned. Returns a
|
|
52
|
+
# German error message if not.
|
|
53
|
+
# Each method compares the normalized string between the start
|
|
54
|
+
# keyword and the next keyword or ;
|
|
55
|
+
|
|
56
|
+
res = He.checkColumns() # starts to search at keyword "SELECT"
|
|
57
|
+
res = He.checkTables() # starts to search at keyword "FROM"
|
|
58
|
+
res = He.checkCondition() # starts to search at keyword "WHERE"
|
|
59
|
+
res = He.checkOrder() # starts to search at keyword "ORDER BY"
|
|
60
|
+
res = He.checkGroup() # starts to search at keyword "GROUP BY"
|
|
61
|
+
|
|
62
|
+
# can not be called with new sql files
|
|
63
|
+
res = checkKeywords("startKeyword",["end","keywords"])
|
|
64
|
+
|
|
65
|
+
# compares equality of the full normalized sql strings and if
|
|
66
|
+
# not equal uses the Cosette API (cosette.cs.washington.edu)
|
|
67
|
+
# for comparison. A file 'cosette_apikey.txt' with only the
|
|
68
|
+
# apikey in it on root level of the test repository is required
|
|
69
|
+
# to use this feature. If not existant, only the string comparison
|
|
70
|
+
# is performed.
|
|
71
|
+
# Warning: Cosette is not maintained!
|
|
72
|
+
res = checkEquality()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Changelog
|
|
84
|
+
|
|
85
|
+
##### V0.2.4
|
|
86
|
+
- Added more check methods for single parts of queries: checkColumns, checkTables, checkCondition, checkOrder, checkGroup, checkKeywords
|
|
87
|
+
|
|
88
|
+
##### V 0.2.3
|
|
89
|
+
- fix: ASC/DESC in ORDER BY (also with multiple columns and order directions), no direction treated as ASC
|
|
90
|
+
- Verified that ; and whitespaces, linebreaks at end of query are ignored
|
|
91
|
+
|
|
92
|
+
##### V 0.2.2
|
|
93
|
+
- Support LIKE
|
|
94
|
+
- Support '<=' and '>=' (geq and leq)
|
|
95
|
+
|
|
96
|
+
##### V 0.2.1
|
|
97
|
+
- Support LIMIT
|
|
98
|
+
|
|
99
|
+
##### V 0.1.9 + 0.2.0
|
|
100
|
+
- Support ORDER BY
|
|
101
|
+
|
|
102
|
+
##### V 0.1.8
|
|
103
|
+
- Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
|
|
104
|
+
|
|
105
|
+
##### V 0.1.6 + V 0.1.7
|
|
106
|
+
- Fixed import error to ensure imports working in different environments
|
|
107
|
+
|
|
108
|
+
##### V 0.1.4 + V 0.1.5
|
|
109
|
+
- Chained conditions (with AND,OR and Paranthesises) in WHERE statement
|
|
110
|
+
- Aggregate Functions
|
|
111
|
+
|
|
112
|
+
##### V 0.1.3
|
|
113
|
+
- SELECT: columns with our without table prefix
|
|
114
|
+
- FROM: one or more table from DB; no queries as tables!
|
|
115
|
+
- WHERE: single conditions; no Paranthesises!
|
|
116
|
+
- GROUP BY one or more columns
|
|
117
|
+
|
|
@@ -12,6 +12,21 @@ from sqlparse.sql import Identifier, IdentifierList, Where, Comparison, Function
|
|
|
12
12
|
from sqlparse.tokens import Keyword, DML, Name, Wildcard
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
sql = ""
|
|
16
|
+
sol = ""
|
|
17
|
+
bd = None
|
|
18
|
+
|
|
19
|
+
def setup(sqlPath,solPath):
|
|
20
|
+
global sql, sol, bd
|
|
21
|
+
if(bd == None):
|
|
22
|
+
bd = Ba.getTableDict()
|
|
23
|
+
if(sqlPath and sqlPath != ""):
|
|
24
|
+
sql = normalizeSQLQuery(Ba.getSQLFromFile(sqlPath), bd)
|
|
25
|
+
if(solPath and solPath != ""):
|
|
26
|
+
sol = normalizeSQLQuery(Ba.getSQLFromFile(solPath), bd)
|
|
27
|
+
if(sql=='' or sol==''):
|
|
28
|
+
raise Exception("\n\nSQL-Datei ist leer. Aufgabe wurde noch nicht bearbeitet.")
|
|
29
|
+
|
|
15
30
|
|
|
16
31
|
def normalizeSQLQuery(query, baseDict):
|
|
17
32
|
try:
|
|
@@ -75,7 +90,6 @@ def normalizeSQLQuery(query, baseDict):
|
|
|
75
90
|
|
|
76
91
|
return " ".join(formatted_query)
|
|
77
92
|
|
|
78
|
-
|
|
79
93
|
def findTableForColumn(data_dict, target_value, relevantTables):
|
|
80
94
|
l = []
|
|
81
95
|
for key, value_list in data_dict.items():
|
|
@@ -90,7 +104,6 @@ def findTableForColumn(data_dict, target_value, relevantTables):
|
|
|
90
104
|
l.append(key)
|
|
91
105
|
return l
|
|
92
106
|
|
|
93
|
-
|
|
94
107
|
def getTableScheme(table_name: str, tableDict: dict):
|
|
95
108
|
tab = tableDict[table_name]
|
|
96
109
|
|
|
@@ -136,10 +149,52 @@ def buildAndSendCosetteRequest(baseDict, sql, sol):
|
|
|
136
149
|
return ("ERR", err)
|
|
137
150
|
|
|
138
151
|
|
|
139
|
-
def
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
sol
|
|
152
|
+
def checkKeywords(startWord:str, endWords:list):
|
|
153
|
+
global sql,sol
|
|
154
|
+
|
|
155
|
+
if(startWord not in sol or startWord not in sql):
|
|
156
|
+
return ""
|
|
157
|
+
|
|
158
|
+
if(startWord in sql):
|
|
159
|
+
start = str.find(sql, startWord)
|
|
160
|
+
end = -1
|
|
161
|
+
for kw in endWords:
|
|
162
|
+
if(str.find(sql, kw) != -1):
|
|
163
|
+
end = str.find(sql, kw)
|
|
164
|
+
break
|
|
165
|
+
if(end == -1):
|
|
166
|
+
end = len(sql)
|
|
167
|
+
|
|
168
|
+
submission = str.strip(sql[start:end])
|
|
169
|
+
print("'"+submission+"'")
|
|
170
|
+
|
|
171
|
+
start = str.find(sol, startWord)
|
|
172
|
+
end = -1
|
|
173
|
+
|
|
174
|
+
for kw in endWords:
|
|
175
|
+
if(str.find(sol, kw) != -1):
|
|
176
|
+
end = str.find(sol, kw)
|
|
177
|
+
break
|
|
178
|
+
if(end == -1):
|
|
179
|
+
end = len(sol)
|
|
180
|
+
|
|
181
|
+
solution = str.strip(sol[start:end])
|
|
182
|
+
print("'"+solution+"'")
|
|
183
|
+
|
|
184
|
+
if submission == solution:
|
|
185
|
+
return ""
|
|
186
|
+
return "Der '"+startWord+"' Teil der SQL-Abfrage ist nicht korrekt (oder nicht automatisch überprüfbar)."
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def checkColumns(sqlPath="", solPath=""):
|
|
192
|
+
global sql,sol
|
|
193
|
+
setup(sqlPath, solPath)
|
|
194
|
+
return checkKeywords("SELECT", ["FROM", "WHERE", "GROUP BY", "ORDER BY", "LIMIT", ";", "HAVING"])
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
143
198
|
|
|
144
199
|
if("SELECT" in sql and "FROM" in sql):
|
|
145
200
|
start = str.find(sql, "SELECT")
|
|
@@ -156,11 +211,13 @@ def checkColumns(sqlPath, solPath):
|
|
|
156
211
|
return ""
|
|
157
212
|
return "Ausgegebene Spalten sind nicht korrekt (oder nicht automatisch überprüfbar)."
|
|
158
213
|
|
|
214
|
+
def checkTables(sqlPath="", solPath=""):
|
|
215
|
+
global sql,sol
|
|
216
|
+
setup(sqlPath, solPath)
|
|
217
|
+
return checkKeywords("FROM", ["FROM", "WHERE", "GROUP BY", "ORDER BY", "LIMIT", ";", "HAVING"])
|
|
218
|
+
|
|
219
|
+
|
|
159
220
|
|
|
160
|
-
def checkTables(sqlPath, solPath):
|
|
161
|
-
bd = Ba.getTableDict()
|
|
162
|
-
sql = normalizeSQLQuery(Ba.getSQLFromFile(sqlPath), bd)
|
|
163
|
-
sol = normalizeSQLQuery(Ba.getSQLFromFile(solPath), bd)
|
|
164
221
|
|
|
165
222
|
if("SELECT" in sql and "FROM" in sql):
|
|
166
223
|
endFromKeywords = ["WHERE", "GROUP", "ORDER", "LIMIT", ";"]
|
|
@@ -196,13 +253,61 @@ def checkTables(sqlPath, solPath):
|
|
|
196
253
|
return ""
|
|
197
254
|
return "Verwendete Tabellen sind nicht korrekt (oder nicht automatisch überprüfbar)."
|
|
198
255
|
|
|
256
|
+
def checkCondition(sqlPath="", solPath=""):
|
|
257
|
+
global sql,sol
|
|
258
|
+
setup(sqlPath, solPath)
|
|
259
|
+
return checkKeywords("WHERE", ["GROUP BY", "ORDER BY", "LIMIT", ";", "HAVING"])
|
|
199
260
|
|
|
200
|
-
def
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
261
|
+
def checkOrder(sqlPath="", solPath=""):
|
|
262
|
+
global sql,sol
|
|
263
|
+
setup(sqlPath, solPath)
|
|
264
|
+
return checkKeywords("ORDER BY", ["WHERE", "GROUP BY", "ORDER BY", "LIMIT", ";", "HAVING"])
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
if("ORDER BY" in sql):
|
|
269
|
+
endFromKeywords = ["WHERE", "GROUP", "LIMIT", ";"]
|
|
270
|
+
|
|
271
|
+
start = str.find(sql, "ORDER BY")
|
|
272
|
+
end = -1
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
for keyword in endFromKeywords:
|
|
276
|
+
if(str.find(sql, keyword) != -1):
|
|
277
|
+
end = str.find(sql, keyword)
|
|
278
|
+
break
|
|
279
|
+
if(end == -1):
|
|
280
|
+
end = len(sql)
|
|
281
|
+
|
|
282
|
+
submission = str.strip(sql[start:end])
|
|
283
|
+
print("'"+submission+"'")
|
|
284
|
+
|
|
285
|
+
start = str.find(sol, "ORDER BY")
|
|
286
|
+
end = -1
|
|
287
|
+
|
|
288
|
+
for keyword in endFromKeywords:
|
|
289
|
+
if(str.find(sol, keyword) != -1):
|
|
290
|
+
end = str.find(sol, keyword)
|
|
291
|
+
break
|
|
292
|
+
if(end == -1):
|
|
293
|
+
end = len(sol)
|
|
294
|
+
|
|
295
|
+
solution = str.strip(sol[start:end])
|
|
296
|
+
print("'"+solution+"'")
|
|
297
|
+
|
|
298
|
+
if submission == solution:
|
|
299
|
+
return ""
|
|
300
|
+
return "Die Sortierung ist nicht korrekt (oder nicht automatisch überprüfbar)."
|
|
301
|
+
|
|
302
|
+
def checkGroup(sqlPath="", solPath=""):
|
|
303
|
+
global sql,sol
|
|
304
|
+
setup(sqlPath, solPath)
|
|
305
|
+
return checkKeywords("GROUP BY", ["WHERE", "ORDER BY", "LIMIT", ";", "HAVING"])
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def checkEquality(sqlPath="", solPath=""):
|
|
309
|
+
global sql,sol
|
|
310
|
+
setup(sqlPath, solPath)
|
|
206
311
|
|
|
207
312
|
if(sql==sol):
|
|
208
313
|
return ""
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: sql_testing_tools
|
|
3
|
+
Version: 0.2.4
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
Requires-Dist: sqlparse>=0.5.1
|
|
6
|
+
Requires-Dist: requests>=2.32.3
|
|
7
|
+
Dynamic: description
|
|
8
|
+
Dynamic: description-content-type
|
|
9
|
+
Dynamic: requires-dist
|
|
10
|
+
|
|
11
|
+
A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
|
|
12
|
+
|
|
13
|
+
### [Beta in Development!]
|
|
14
|
+
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
|
|
15
|
+
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
|
|
16
|
+
|
|
17
|
+
- Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
|
|
18
|
+
- PyPi-Package available at: https://pypi.org/project/sql-testing-tools/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Getting started
|
|
23
|
+
|
|
24
|
+
Use the following code to import the SQL Testing Tools to your project:
|
|
25
|
+
``` python
|
|
26
|
+
# ensure to always use the latest version of sql_testing_tools
|
|
27
|
+
import os
|
|
28
|
+
os.system('pip install -U sql_testing_tools')
|
|
29
|
+
|
|
30
|
+
# import sql_testing_tools
|
|
31
|
+
import sql_testing_tools.BaseAccess as Ba
|
|
32
|
+
import sql_testing_tools.Helper as He
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
On global level of your test class, set the SQLite database you want to use (bases must be located in the repository of the test class, no DBs contained in sql_testing_tools).
|
|
36
|
+
``` python
|
|
37
|
+
import unittest
|
|
38
|
+
class TestClass(unittest.TestCase):
|
|
39
|
+
Ba.setDBName("databases/ladepunkte.db")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The following methods are available for use in test methods:
|
|
43
|
+
``` python
|
|
44
|
+
try:
|
|
45
|
+
Ba.runAndGetStringTable_fromFile("sqlfile.sql")
|
|
46
|
+
except Exception as e:
|
|
47
|
+
# the execution failed
|
|
48
|
+
# (usually due to syntax or database errors)
|
|
49
|
+
self.fail(e)
|
|
50
|
+
|
|
51
|
+
# (optional) set the files to be compared. The sql strings will
|
|
52
|
+
# be normalized and used for all following methods (to improve
|
|
53
|
+
# performance), until new files are set. Arguments that are
|
|
54
|
+
# None or "" are ignored and the sql string remains the same.
|
|
55
|
+
# Raises an Exception if one of the files is empty.
|
|
56
|
+
setup("sqlfile.sql","solution.sql")
|
|
57
|
+
|
|
58
|
+
# All following methods call setup(sql,sol) before executing
|
|
59
|
+
# anything else. Call without arguments to keep the last
|
|
60
|
+
# normalized sql strings (and improve performance).
|
|
61
|
+
# Each check was successfull if "" is returned. Returns a
|
|
62
|
+
# German error message if not.
|
|
63
|
+
# Each method compares the normalized string between the start
|
|
64
|
+
# keyword and the next keyword or ;
|
|
65
|
+
|
|
66
|
+
res = He.checkColumns() # starts to search at keyword "SELECT"
|
|
67
|
+
res = He.checkTables() # starts to search at keyword "FROM"
|
|
68
|
+
res = He.checkCondition() # starts to search at keyword "WHERE"
|
|
69
|
+
res = He.checkOrder() # starts to search at keyword "ORDER BY"
|
|
70
|
+
res = He.checkGroup() # starts to search at keyword "GROUP BY"
|
|
71
|
+
|
|
72
|
+
# can not be called with new sql files
|
|
73
|
+
res = checkKeywords("startKeyword",["end","keywords"])
|
|
74
|
+
|
|
75
|
+
# compares equality of the full normalized sql strings and if
|
|
76
|
+
# not equal uses the Cosette API (cosette.cs.washington.edu)
|
|
77
|
+
# for comparison. A file 'cosette_apikey.txt' with only the
|
|
78
|
+
# apikey in it on root level of the test repository is required
|
|
79
|
+
# to use this feature. If not existant, only the string comparison
|
|
80
|
+
# is performed.
|
|
81
|
+
# Warning: Cosette is not maintained!
|
|
82
|
+
res = checkEquality()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Changelog
|
|
94
|
+
|
|
95
|
+
##### V0.2.4
|
|
96
|
+
- Added more check methods for single parts of queries: checkColumns, checkTables, checkCondition, checkOrder, checkGroup, checkKeywords
|
|
97
|
+
|
|
98
|
+
##### V 0.2.3
|
|
99
|
+
- fix: ASC/DESC in ORDER BY (also with multiple columns and order directions), no direction treated as ASC
|
|
100
|
+
- Verified that ; and whitespaces, linebreaks at end of query are ignored
|
|
101
|
+
|
|
102
|
+
##### V 0.2.2
|
|
103
|
+
- Support LIKE
|
|
104
|
+
- Support '<=' and '>=' (geq and leq)
|
|
105
|
+
|
|
106
|
+
##### V 0.2.1
|
|
107
|
+
- Support LIMIT
|
|
108
|
+
|
|
109
|
+
##### V 0.1.9 + 0.2.0
|
|
110
|
+
- Support ORDER BY
|
|
111
|
+
|
|
112
|
+
##### V 0.1.8
|
|
113
|
+
- Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
|
|
114
|
+
|
|
115
|
+
##### V 0.1.6 + V 0.1.7
|
|
116
|
+
- Fixed import error to ensure imports working in different environments
|
|
117
|
+
|
|
118
|
+
##### V 0.1.4 + V 0.1.5
|
|
119
|
+
- Chained conditions (with AND,OR and Paranthesises) in WHERE statement
|
|
120
|
+
- Aggregate Functions
|
|
121
|
+
|
|
122
|
+
##### V 0.1.3
|
|
123
|
+
- SELECT: columns with our without table prefix
|
|
124
|
+
- FROM: one or more table from DB; no queries as tables!
|
|
125
|
+
- WHERE: single conditions; no Paranthesises!
|
|
126
|
+
- GROUP BY one or more columns
|
|
127
|
+
|
sql_testing_tools-0.2.3/PKG-INFO
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.2
|
|
2
|
-
Name: sql_testing_tools
|
|
3
|
-
Version: 0.2.3
|
|
4
|
-
Description-Content-Type: text/markdown
|
|
5
|
-
Requires-Dist: sqlparse>=0.5.1
|
|
6
|
-
Requires-Dist: requests>=2.32.3
|
|
7
|
-
Dynamic: description
|
|
8
|
-
Dynamic: description-content-type
|
|
9
|
-
Dynamic: requires-dist
|
|
10
|
-
|
|
11
|
-
A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### [Beta in Development!]
|
|
16
|
-
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
|
|
17
|
-
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
|
|
18
|
-
|
|
19
|
-
Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
|
|
20
|
-
|
|
21
|
-
### V 0.2.3
|
|
22
|
-
- fix: ASC/DESC in ORDER BY (also with multiple columns and order directions), no direction treated as ASC
|
|
23
|
-
- Verified that ; and whitespaces, linebreaks at end of query are ignored
|
|
24
|
-
|
|
25
|
-
### V 0.2.2
|
|
26
|
-
- Support LIKE
|
|
27
|
-
- Support '<=' and '>=' (geq and leq)
|
|
28
|
-
|
|
29
|
-
### V 0.2.1
|
|
30
|
-
- Support LIMIT
|
|
31
|
-
|
|
32
|
-
### V 0.1.9 + 0.2.0
|
|
33
|
-
- Support ORDER BY
|
|
34
|
-
|
|
35
|
-
### V 0.1.8
|
|
36
|
-
- Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
|
|
37
|
-
|
|
38
|
-
### V 0.1.6 + V 0.1.7
|
|
39
|
-
- Fixed import error to ensure imports working in different environments
|
|
40
|
-
|
|
41
|
-
### V 0.1.4 + V 0.1.5
|
|
42
|
-
- Chained conditions (with AND,OR and Paranthesises) in WHERE statement
|
|
43
|
-
- Aggregate Functions
|
|
44
|
-
|
|
45
|
-
### V 0.1.3
|
|
46
|
-
- SELECT: columns with our without table prefix
|
|
47
|
-
- FROM: one or more table from DB; no queries as tables!
|
|
48
|
-
- WHERE: single conditions; no Paranthesises!
|
|
49
|
-
- GROUP BY one or more columns
|
|
50
|
-
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
### [Beta in Development!]
|
|
6
|
-
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
|
|
7
|
-
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
|
|
8
|
-
|
|
9
|
-
Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
|
|
10
|
-
|
|
11
|
-
### V 0.2.3
|
|
12
|
-
- fix: ASC/DESC in ORDER BY (also with multiple columns and order directions), no direction treated as ASC
|
|
13
|
-
- Verified that ; and whitespaces, linebreaks at end of query are ignored
|
|
14
|
-
|
|
15
|
-
### V 0.2.2
|
|
16
|
-
- Support LIKE
|
|
17
|
-
- Support '<=' and '>=' (geq and leq)
|
|
18
|
-
|
|
19
|
-
### V 0.2.1
|
|
20
|
-
- Support LIMIT
|
|
21
|
-
|
|
22
|
-
### V 0.1.9 + 0.2.0
|
|
23
|
-
- Support ORDER BY
|
|
24
|
-
|
|
25
|
-
### V 0.1.8
|
|
26
|
-
- Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
|
|
27
|
-
|
|
28
|
-
### V 0.1.6 + V 0.1.7
|
|
29
|
-
- Fixed import error to ensure imports working in different environments
|
|
30
|
-
|
|
31
|
-
### V 0.1.4 + V 0.1.5
|
|
32
|
-
- Chained conditions (with AND,OR and Paranthesises) in WHERE statement
|
|
33
|
-
- Aggregate Functions
|
|
34
|
-
|
|
35
|
-
### V 0.1.3
|
|
36
|
-
- SELECT: columns with our without table prefix
|
|
37
|
-
- FROM: one or more table from DB; no queries as tables!
|
|
38
|
-
- WHERE: single conditions; no Paranthesises!
|
|
39
|
-
- GROUP BY one or more columns
|
|
40
|
-
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.2
|
|
2
|
-
Name: sql_testing_tools
|
|
3
|
-
Version: 0.2.3
|
|
4
|
-
Description-Content-Type: text/markdown
|
|
5
|
-
Requires-Dist: sqlparse>=0.5.1
|
|
6
|
-
Requires-Dist: requests>=2.32.3
|
|
7
|
-
Dynamic: description
|
|
8
|
-
Dynamic: description-content-type
|
|
9
|
-
Dynamic: requires-dist
|
|
10
|
-
|
|
11
|
-
A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### [Beta in Development!]
|
|
16
|
-
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-build.yml)
|
|
17
|
-
[](https://github.com/ValentinHerrmann/sql_testing_tools/actions/workflows/python-unittests.yml)
|
|
18
|
-
|
|
19
|
-
Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
|
|
20
|
-
|
|
21
|
-
### V 0.2.3
|
|
22
|
-
- fix: ASC/DESC in ORDER BY (also with multiple columns and order directions), no direction treated as ASC
|
|
23
|
-
- Verified that ; and whitespaces, linebreaks at end of query are ignored
|
|
24
|
-
|
|
25
|
-
### V 0.2.2
|
|
26
|
-
- Support LIKE
|
|
27
|
-
- Support '<=' and '>=' (geq and leq)
|
|
28
|
-
|
|
29
|
-
### V 0.2.1
|
|
30
|
-
- Support LIMIT
|
|
31
|
-
|
|
32
|
-
### V 0.1.9 + 0.2.0
|
|
33
|
-
- Support ORDER BY
|
|
34
|
-
|
|
35
|
-
### V 0.1.8
|
|
36
|
-
- Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
|
|
37
|
-
|
|
38
|
-
### V 0.1.6 + V 0.1.7
|
|
39
|
-
- Fixed import error to ensure imports working in different environments
|
|
40
|
-
|
|
41
|
-
### V 0.1.4 + V 0.1.5
|
|
42
|
-
- Chained conditions (with AND,OR and Paranthesises) in WHERE statement
|
|
43
|
-
- Aggregate Functions
|
|
44
|
-
|
|
45
|
-
### V 0.1.3
|
|
46
|
-
- SELECT: columns with our without table prefix
|
|
47
|
-
- FROM: one or more table from DB; no queries as tables!
|
|
48
|
-
- WHERE: single conditions; no Paranthesises!
|
|
49
|
-
- GROUP BY one or more columns
|
|
50
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{sql_testing_tools-0.2.3 → sql_testing_tools-0.2.4}/sql_testing_tools.egg-info/top_level.txt
RENAMED
|
File without changes
|