This repository has been archived by the owner on Apr 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Justin Funston <[email protected]>
- Loading branch information
Showing
10 changed files
with
768 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## chogori-sql integration tests | ||
|
||
This directory contains the chogori-sql integration tests. Run it with "./integrate.py" or with | ||
"./integrate.sh" which will run initDB and postmaster first. Requires python3 and | ||
"pip3 install psycopg2-binary". It uses python's unittest library and you can pass arguments to it directly | ||
on the command line. | ||
|
||
The tests must be run after initDB and with postmaster running. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
''' | ||
MIT License | ||
Copyright (c) 2021 Futurewei Cloud | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
''' | ||
|
||
import unittest | ||
import psycopg2 | ||
from helper import commitSQL, selectOneRecord, getConn | ||
|
||
class TestAggregation(unittest.TestCase): | ||
sharedConn = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.sharedConn = getConn() | ||
|
||
commitSQL(cls.sharedConn, "CREATE TABLE aggregate (id integer PRIMARY KEY, dataA integer, dataB integer);") | ||
with cls.sharedConn: # commits at end of context if no errors | ||
with cls.sharedConn.cursor() as cur: | ||
for i in range(1, 21): | ||
b = 1 | ||
if i % 2 == 0: | ||
b = 0 | ||
cur.execute("INSERT INTO aggregate VALUES (%s, %s, 1);", (i, b)) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# TODO delete table | ||
cls.sharedConn.close() | ||
|
||
def test_count(self): | ||
record = selectOneRecord(self.sharedConn, "SELECT COUNT(id) FROM aggregate;") | ||
self.assertEqual(record[0], 20) | ||
|
||
def test_sum(self): | ||
record = selectOneRecord(self.sharedConn, "SELECT SUM(dataA) FROM aggregate;") | ||
self.assertEqual(record[0], 10) | ||
|
||
def test_min(self): | ||
record = selectOneRecord(self.sharedConn, "SELECT MIN(dataA) FROM aggregate;") | ||
self.assertEqual(record[0], 0) | ||
|
||
def test_max(self): | ||
record = selectOneRecord(self.sharedConn, "SELECT MAX(dataA) FROM aggregate;") | ||
self.assertEqual(record[0], 1) | ||
|
||
def test_countWithFilter(self): | ||
record = selectOneRecord(self.sharedConn, "SELECT COUNT(id) FROM aggregate WHERE dataA=0;") | ||
self.assertEqual(record[0], 10) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
''' | ||
MIT License | ||
Copyright (c) 2021 Futurewei Cloud | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
''' | ||
|
||
import unittest | ||
import psycopg2 | ||
from helper import commitSQL, selectOneRecord, getConn | ||
|
||
class TestCompoundKey(unittest.TestCase): | ||
sharedConn = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.sharedConn = getConn() | ||
commitSQL(cls.sharedConn, "CREATE TABLE compoundkey (id integer, idstr text, id3 integer, dataA integer, PRIMARY KEY(id, idstr, id3));") | ||
commitSQL(cls.sharedConn, "CREATE TABLE compoundkeyintint (id integer, id2 integer, dataA integer, PRIMARY KEY(id, id2));") | ||
commitSQL(cls.sharedConn, "CREATE TABLE compoundkeytxttxt (id text, id2 text, dataA integer, PRIMARY KEY(id, id2));") | ||
commitSQL(cls.sharedConn, "CREATE TABLE compoundkeyboolint (id bool, id2 integer, dataA integer, PRIMARY KEY(id, id2));") | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# TODO delete table | ||
cls.sharedConn.close() | ||
|
||
@unittest.skip("Fails and causes other tests to fail. See issue #219 and #216") | ||
def test_prefixScanThreeKeys(self): | ||
# Populate some records for the tests | ||
with self.sharedConn: # commits at end of context if no errors | ||
with self.sharedConn.cursor() as cur: | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkey VALUES (1, 'sometext', %s, 1);", (i,)) | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkey VALUES (2, 'someothertext', %s, 2);", (i,)) | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkey VALUES (3, 'somemoretext', %s, 3);", (i,)) | ||
|
||
# Prefix scan with first two keys specified with = | ||
with self.sharedConn: # commits at end of context if no errors | ||
with self.sharedConn.cursor() as cur: | ||
cur.execute("SELECT * FROM compoundkey WHERE id = 2 AND idstr = 'someothertext';") | ||
for i in range(1, 11): | ||
record = cur.fetchone() | ||
self.assertNotEqual(record, None) | ||
self.assertEqual(record[0], 2) | ||
self.assertEqual(record[1], "someothertext") | ||
self.assertEqual(record[2], i) | ||
self.assertEqual(record[3], 2) | ||
|
||
# Partial prefix scan with extra filter that is not a prefix | ||
record = selectOneRecord(self.sharedConn, "SELECT * FROM compoundkey WHERE id = 1 AND id3 = 5;") | ||
self.assertEqual(record[0], 1) | ||
self.assertEqual(record[1], "sometext") | ||
self.assertEqual(record[2], 5) | ||
self.assertEqual(record[1], 1) | ||
|
||
def test_prefixScanIntInt(self): | ||
# Populate some records for the tests | ||
with self.sharedConn: # commits at end of context if no errors | ||
with self.sharedConn.cursor() as cur: | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkeyintint VALUES (1, %s, 1);", (i,)) | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkeyintint VALUES (2, %s, 2);", (i,)) | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkeyintint VALUES (3, %s, 3);", (i,)) | ||
|
||
# Prefix scan with first key specified with = | ||
with self.sharedConn: # commits at end of context if no errors | ||
with self.sharedConn.cursor() as cur: | ||
cur.execute("SELECT * FROM compoundkeyintint WHERE id = 2;") | ||
for i in range(1, 11): | ||
record = cur.fetchone() | ||
self.assertNotEqual(record, None) | ||
self.assertEqual(record[0], 2) | ||
self.assertEqual(record[1], i) | ||
self.assertEqual(record[2], 2) | ||
|
||
@unittest.skip("Fails and causes other tests to fail. See issue #219 and #216") | ||
def test_prefixScanTxtTxt(self): | ||
# Populate some records for the tests | ||
with self.sharedConn: # commits at end of context if no errors | ||
with self.sharedConn.cursor() as cur: | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkeytxttxt VALUES ('1', %s, 1);", (str(i),)) | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkeytxttxt VALUES ('2', %s, 2);", (str(i),)) | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkeytxttxt VALUES ('3', %s, 3);", (str(i),)) | ||
|
||
# Prefix scan with first key specified with = | ||
with self.sharedConn: # commits at end of context if no errors | ||
with self.sharedConn.cursor() as cur: | ||
cur.execute("SELECT * FROM compoundkeytxttxt WHERE id = '2';") | ||
for i in range(1, 11): | ||
record = cur.fetchone() | ||
self.assertNotEqual(record, None) | ||
self.assertEqual(record[0], '2') | ||
self.assertEqual(record[1], str(i)) | ||
self.assertEqual(record[2], 2) | ||
|
||
|
||
def test_prefixScanBoolInt(self): | ||
# Populate some records for the tests | ||
with self.sharedConn: # commits at end of context if no errors | ||
with self.sharedConn.cursor() as cur: | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkeyboolint VALUES (TRUE, %s, 1);", (i,)) | ||
for i in range(1, 11): | ||
cur.execute("INSERT INTO compoundkeyboolint VALUES (FALSE, %s, 2);", (i,)) | ||
|
||
# Prefix scan with first key specified with = | ||
with self.sharedConn: # commits at end of context if no errors | ||
with self.sharedConn.cursor() as cur: | ||
cur.execute("SELECT * FROM compoundkeyboolint WHERE id = FALSE;") | ||
for i in range(1, 11): | ||
record = cur.fetchone() | ||
self.assertNotEqual(record, None) | ||
self.assertEqual(record[0], False) | ||
self.assertEqual(record[1], i) | ||
self.assertEqual(record[2], 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
''' | ||
MIT License | ||
Copyright (c) 2021 Futurewei Cloud | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
''' | ||
|
||
import unittest | ||
import psycopg2 | ||
from helper import commitSQL, selectOneRecord, getConn | ||
|
||
|
||
class TestDDL(unittest.TestCase): | ||
sharedConn = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.sharedConn = getConn() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# TODO delete table | ||
cls.sharedConn.close() | ||
|
||
def test_makeBasicTable(self): | ||
commitSQL(self.sharedConn, "CREATE TABLE ddltest1 (id integer PRIMARY KEY, dataA integer);") | ||
|
||
def test_makeTableWithManyTypes(self): | ||
commitSQL(self.sharedConn, "CREATE TABLE ddltest2 (id integer PRIMARY KEY, dataA integer, dataB boolean, dataC real, dataD numeric, dataE text, dataF char[36]);") | ||
|
||
def test_makeTableWithoutPrimaryKey(self): | ||
commitSQL(self.sharedConn, "CREATE TABLE ddltest3 (id integer, dataA integer);") | ||
|
||
def test_alterTable(self): | ||
#with self.assertRaises(psycopg2.errors.InternalError): | ||
commitSQL(self.sharedConn, "CREATE TABLE ddltest4 (id integer, dataA integer);") | ||
commitSQL(self.sharedConn, "ALTER TABLE ddltest4 ADD txtcol text;") | ||
commitSQL(self.sharedConn, "INSERT INTO ddltest4 VALUES(1, 1, 'mytext')") | ||
|
||
record = selectOneRecord(self.sharedConn, "SELECT dataB FROM dmlbasic WHERE id=1;") | ||
self.assertEqual(record[0], 1) | ||
self.assertEqual(record[1], 1) | ||
self.assertEqual(record[2], "mytext") | ||
|
||
# TODO add table already exists error case after #216 is fixed | ||
|
Oops, something went wrong.