Forgot to bump version in build config
This commit is contained in:
parent
edaafcdf4f
commit
0e03594e54
2 changed files with 11 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[metadata]
|
[metadata]
|
||||||
name = based
|
name = based
|
||||||
version = 0.1.0
|
version = 0.2.0
|
||||||
description = A simple, fast (maybe), and reliable (I hope) PostgreSQL ORM oriented for dynamic models.
|
description = A simple, fast (maybe), and reliable (I hope) PostgreSQL ORM oriented for dynamic models.
|
||||||
author = nuark
|
author = nuark
|
||||||
author_email = me@nuark.xyz
|
author_email = me@nuark.xyz
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import unittest
|
import unittest
|
||||||
import uuid
|
|
||||||
from based.db import DBConnector, ColumnUpdate, ColumnCondition
|
from based.db import DBConnector, ColumnUpdate, ColumnCondition
|
||||||
from based.columns import *
|
from based.columns import *
|
||||||
|
|
||||||
|
|
@ -9,25 +8,20 @@ connector = DBConnector(conninfo)
|
||||||
|
|
||||||
class TestDBConnector(unittest.TestCase):
|
class TestDBConnector(unittest.TestCase):
|
||||||
def test_connection(self):
|
def test_connection(self):
|
||||||
with connector.connection() as conn:
|
with connector.connection as conn:
|
||||||
one: dict = conn.execute('SELECT 1 as "ONE"').fetchone() # type: ignore
|
one: dict = conn.execute('SELECT 1 as "ONE"').fetchone() # type: ignore
|
||||||
self.assertIsNotNone(one)
|
self.assertIsNotNone(one)
|
||||||
self.assertEqual(one["ONE"], 1)
|
self.assertEqual(one["ONE"], 1)
|
||||||
|
|
||||||
def test_columnDefinition(self):
|
def test_columnDefinition(self):
|
||||||
with connector.connection() as conn:
|
with connector.connection as conn:
|
||||||
cdef1 = PrimarySerialColumnDefinition("id")
|
cdef1 = PrimarySerialColumnDefinition("id")
|
||||||
cdef2 = PrimaryUUIDColumnDefinition("uid")
|
cdef2 = TextColumnDefinition("name")
|
||||||
cdef3 = TextColumnDefinition("name")
|
cdef3 = TextColumnDefinition("name", "John Doe")
|
||||||
cdef4 = TextColumnDefinition("name", "John Doe")
|
|
||||||
self.assertEqual(cdef1.sql().as_string(conn), '"id" SERIAL PRIMARY KEY')
|
self.assertEqual(cdef1.sql().as_string(conn), '"id" SERIAL PRIMARY KEY')
|
||||||
|
self.assertEqual(cdef2.sql().as_string(conn), '"name" TEXT')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cdef2.sql().as_string(conn),
|
cdef3.sql().as_string(conn), "\"name\" TEXT DEFAULT 'John Doe'"
|
||||||
'"uid" uuid DEFAULT gen_random_uuid() PRIMARY KEY',
|
|
||||||
)
|
|
||||||
self.assertEqual(cdef3.sql().as_string(conn), '"name" TEXT')
|
|
||||||
self.assertEqual(
|
|
||||||
cdef4.sql().as_string(conn), "\"name\" TEXT DEFAULT 'John Doe'"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_tableCreation(self):
|
def test_tableCreation(self):
|
||||||
|
|
@ -52,13 +46,10 @@ class TestDBConnector(unittest.TestCase):
|
||||||
[
|
[
|
||||||
PrimarySerialColumnDefinition("id"),
|
PrimarySerialColumnDefinition("id"),
|
||||||
TextColumnDefinition("textcol", "John Doe"),
|
TextColumnDefinition("textcol", "John Doe"),
|
||||||
BigintColumnDefinition("bigintcol", 2**30),
|
|
||||||
BooleanColumnDefinition("boolcol", True),
|
BooleanColumnDefinition("boolcol", True),
|
||||||
DateColumnDefinition("datecol", date.today()),
|
|
||||||
TimestampColumnDefinition("tscol", date.today()),
|
TimestampColumnDefinition("tscol", date.today()),
|
||||||
DoubleColumnDefinition("doublecol", 3.14),
|
DoubleColumnDefinition("doublecol", 3.14),
|
||||||
IntegerColumnDefinition("intcol", 100),
|
IntegerColumnDefinition("intcol", 100),
|
||||||
UUIDColumnDefinition("uuidcol", "00000000-0000-0000-0000-000000000000"),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
self.assertTrue(connector.tableExists("test_table"))
|
self.assertTrue(connector.tableExists("test_table"))
|
||||||
|
|
@ -67,35 +58,24 @@ class TestDBConnector(unittest.TestCase):
|
||||||
"test_table",
|
"test_table",
|
||||||
{
|
{
|
||||||
"textcol": "Jane Doe",
|
"textcol": "Jane Doe",
|
||||||
"bigintcol": 3**30,
|
|
||||||
"boolcol": False,
|
"boolcol": False,
|
||||||
"datecol": date.today(),
|
|
||||||
"tscol": date.today(),
|
"tscol": date.today(),
|
||||||
"doublecol": 3.14,
|
"doublecol": 3.14,
|
||||||
"intcol": 100,
|
"intcol": 100,
|
||||||
"uuidcol": uuid.uuid4(),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
res = connector.selectFromTable("test_table", ["*"])
|
res = connector.selectFromTable("test_table", ["*"])
|
||||||
self.assertEqual(len(res), 2)
|
self.assertEqual(len(res), 2)
|
||||||
self.assertEqual(res[0]["textcol"], "John Doe")
|
self.assertEqual(res[0]["textcol"], "John Doe")
|
||||||
self.assertEqual(res[0]["bigintcol"], 2**30)
|
|
||||||
self.assertEqual(res[0]["boolcol"], True)
|
self.assertEqual(res[0]["boolcol"], True)
|
||||||
self.assertIsNotNone(res[0]["datecol"])
|
|
||||||
self.assertIsNotNone(res[0]["tscol"])
|
self.assertIsNotNone(res[0]["tscol"])
|
||||||
self.assertEqual(res[0]["doublecol"], 3.14)
|
self.assertEqual(res[0]["doublecol"], 3.14)
|
||||||
self.assertEqual(res[0]["intcol"], 100)
|
self.assertEqual(res[0]["intcol"], 100)
|
||||||
self.assertEqual(
|
|
||||||
res[0]["uuidcol"], uuid.UUID("00000000-0000-0000-0000-000000000000")
|
|
||||||
)
|
|
||||||
self.assertEqual(res[1]["textcol"], "Jane Doe")
|
self.assertEqual(res[1]["textcol"], "Jane Doe")
|
||||||
self.assertEqual(res[1]["bigintcol"], 3**30)
|
|
||||||
self.assertEqual(res[1]["boolcol"], False)
|
self.assertEqual(res[1]["boolcol"], False)
|
||||||
self.assertIsNotNone(res[1]["datecol"])
|
|
||||||
self.assertIsNotNone(res[1]["tscol"])
|
self.assertIsNotNone(res[1]["tscol"])
|
||||||
self.assertEqual(res[1]["doublecol"], 3.14)
|
self.assertEqual(res[1]["doublecol"], 3.14)
|
||||||
self.assertEqual(res[1]["intcol"], 100)
|
self.assertEqual(res[1]["intcol"], 100)
|
||||||
self.assertIsNotNone(res[1]["uuidcol"])
|
|
||||||
connector.dropTable("test_table")
|
connector.dropTable("test_table")
|
||||||
self.assertFalse(connector.tableExists("test_table"))
|
self.assertFalse(connector.tableExists("test_table"))
|
||||||
|
|
||||||
|
|
@ -138,7 +118,7 @@ class TestDBConnector(unittest.TestCase):
|
||||||
ColumnUpdate("name", "John"),
|
ColumnUpdate("name", "John"),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
ColumnCondition("name", "John Doe"),
|
ColumnCondition("name", "eq", "John Doe"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
rows = connector.selectFromTable("test_table", ["name"])
|
rows = connector.selectFromTable("test_table", ["name"])
|
||||||
|
|
@ -162,7 +142,9 @@ class TestDBConnector(unittest.TestCase):
|
||||||
self.assertEqual(rows[0]["name"], "John Doe")
|
self.assertEqual(rows[0]["name"], "John Doe")
|
||||||
self.assertEqual(rows[1]["name"], "Jane Doe")
|
self.assertEqual(rows[1]["name"], "Jane Doe")
|
||||||
self.assertEqual(rows[2]["name"], "Mikhail Prokopenko")
|
self.assertEqual(rows[2]["name"], "Mikhail Prokopenko")
|
||||||
connector.deleteFromTable("test_table", [ColumnCondition("name", "John Doe")])
|
connector.deleteFromTable(
|
||||||
|
"test_table", [ColumnCondition("name", "eq", "John Doe")]
|
||||||
|
)
|
||||||
rows = connector.selectFromTable("test_table", ["name"])
|
rows = connector.selectFromTable("test_table", ["name"])
|
||||||
self.assertEqual(len(rows), 2)
|
self.assertEqual(len(rows), 2)
|
||||||
self.assertEqual(rows[0]["name"], "Jane Doe")
|
self.assertEqual(rows[0]["name"], "Jane Doe")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue