Skip to content

Commit

Permalink
use TableTest (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend authored Jun 19, 2024
1 parent 4be8aec commit d91d59c
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 249 deletions.
10 changes: 3 additions & 7 deletions tests/columns/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from piccolo.querystring import QueryString
from piccolo.table import Table
from tests.base import engines_only, engines_skip, sqlite_only
from tests.base import TableTest, engines_only, engines_skip, sqlite_only


class MyTable(Table):
Expand All @@ -32,16 +32,12 @@ def test_array_default(self):
self.assertTrue(column.default is list)


class TestArray(TestCase):
class TestArray(TableTest):
"""
Make sure an Array column can be created, and works correctly.
"""

def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
tables = [MyTable]

@pytest.mark.cockroach_array_slow
def test_storage(self):
Expand Down
12 changes: 3 additions & 9 deletions tests/columns/test_bigint.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import os
from unittest import TestCase

from piccolo.columns.column_types import BigInt
from piccolo.table import Table

from ..base import engines_only
from tests.base import TableTest, engines_only


class MyTable(Table):
value = BigInt()


@engines_only("postgres", "cockroach")
class TestBigIntPostgres(TestCase):
class TestBigIntPostgres(TableTest):
"""
Make sure a BigInt column in Postgres can store a large number.
"""

def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
tables = [MyTable]

def _test_length(self):
# Can store 8 bytes, but split between positive and negative values.
Expand Down
10 changes: 3 additions & 7 deletions tests/columns/test_boolean.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import typing as t
from unittest import TestCase

from piccolo.columns.column_types import Boolean
from piccolo.table import Table
from tests.base import TableTest


class MyTable(Table):
boolean = Boolean(boolean=False, null=True)


class TestBoolean(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestBoolean(TableTest):
tables = [MyTable]

def test_return_type(self) -> None:
for value in (True, False, None, ...):
Expand Down
19 changes: 5 additions & 14 deletions tests/columns/test_bytea.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import TestCase

from piccolo.columns.column_types import Bytea
from piccolo.table import Table
from tests.base import TableTest


class MyTable(Table):
Expand All @@ -19,12 +18,8 @@ class MyTableDefault(Table):
token_none = Bytea(default=None, null=True)


class TestBytea(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestBytea(TableTest):
tables = [MyTable]

def test_bytea(self):
"""
Expand All @@ -40,12 +35,8 @@ def test_bytea(self):
)


class TestByteaDefault(TestCase):
def setUp(self):
MyTableDefault.create_table().run_sync()

def tearDown(self):
MyTableDefault.alter().drop_table().run_sync()
class TestByteaDefault(TableTest):
tables = [MyTableDefault]

def test_json_default(self):
row = MyTableDefault()
Expand Down
19 changes: 5 additions & 14 deletions tests/columns/test_choices.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import enum
from unittest import TestCase

from piccolo.columns.column_types import Array, Varchar
from piccolo.table import Table
from tests.base import engines_only
from tests.base import TableTest, engines_only
from tests.example_apps.music.tables import Shirt


class TestChoices(TestCase):
def setUp(self):
Shirt.create_table().run_sync()

def tearDown(self):
Shirt.alter().drop_table().run_sync()
class TestChoices(TableTest):
tables = [Shirt]

def _insert_shirts(self):
Shirt.insert(
Expand Down Expand Up @@ -87,16 +82,12 @@ class Extras(str, enum.Enum):


@engines_only("postgres", "sqlite")
class TestArrayChoices(TestCase):
class TestArrayChoices(TableTest):
"""
🐛 Cockroach bug: https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg
""" # noqa: E501

def setUp(self):
Ticket.create_table().run_sync()

def tearDown(self):
Ticket.alter().drop_table().run_sync()
tables = [Ticket]

def test_string(self):
"""
Expand Down
18 changes: 5 additions & 13 deletions tests/columns/test_date.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import datetime
from unittest import TestCase

from piccolo.columns.column_types import Date
from piccolo.columns.defaults.date import DateNow
from piccolo.table import Table
from tests.base import TableTest


class MyTable(Table):
Expand All @@ -14,12 +14,8 @@ class MyTableDefault(Table):
created_on = Date(default=DateNow())


class TestDate(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestDate(TableTest):
tables = [MyTable]

def test_timestamp(self):
created_on = datetime.datetime.now().date()
Expand All @@ -31,12 +27,8 @@ def test_timestamp(self):
self.assertEqual(result.created_on, created_on)


class TestDateDefault(TestCase):
def setUp(self):
MyTableDefault.create_table().run_sync()

def tearDown(self):
MyTableDefault.alter().drop_table().run_sync()
class TestDateDefault(TableTest):
tables = [MyTableDefault]

def test_timestamp(self):
created_on = datetime.datetime.now().date()
Expand Down
11 changes: 3 additions & 8 deletions tests/columns/test_double_precision.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
from unittest import TestCase

from piccolo.columns.column_types import DoublePrecision
from piccolo.table import Table
from tests.base import TableTest


class MyTable(Table):
column_a = DoublePrecision()


class TestDoublePrecision(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestDoublePrecision(TableTest):
tables = [MyTable]

def test_creation(self):
row = MyTable(column_a=1.23)
Expand Down
18 changes: 5 additions & 13 deletions tests/columns/test_interval.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import datetime
from unittest import TestCase

from piccolo.columns.column_types import Interval
from piccolo.columns.defaults.interval import IntervalCustom
from piccolo.table import Table
from tests.base import TableTest


class MyTable(Table):
Expand All @@ -14,12 +14,8 @@ class MyTableDefault(Table):
interval = Interval(default=IntervalCustom(days=1))


class TestInterval(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestInterval(TableTest):
tables = [MyTable]

def test_interval(self):
# Test a range of different timedeltas
Expand Down Expand Up @@ -91,12 +87,8 @@ def test_interval_where_clause(self):
self.assertTrue(result)


class TestIntervalDefault(TestCase):
def setUp(self):
MyTableDefault.create_table().run_sync()

def tearDown(self):
MyTableDefault.alter().drop_table().run_sync()
class TestIntervalDefault(TableTest):
tables = [MyTableDefault]

def test_interval(self):
row = MyTableDefault()
Expand Down
35 changes: 9 additions & 26 deletions tests/columns/test_json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import TestCase

from piccolo.columns.column_types import JSON
from piccolo.table import Table
from tests.base import TableTest


class MyTable(Table):
Expand All @@ -20,12 +19,8 @@ class MyTableDefault(Table):
json_none = JSON(default=None, null=True)


class TestJSONSave(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestJSONSave(TableTest):
tables = [MyTable]

def test_json_string(self):
"""
Expand Down Expand Up @@ -58,12 +53,8 @@ def test_json_object(self):
)


class TestJSONDefault(TestCase):
def setUp(self):
MyTableDefault.create_table().run_sync()

def tearDown(self):
MyTableDefault.alter().drop_table().run_sync()
class TestJSONDefault(TableTest):
tables = [MyTableDefault]

def test_json_default(self):
row = MyTableDefault()
Expand All @@ -81,12 +72,8 @@ def test_invalid_default(self):
JSON(default=value) # type: ignore


class TestJSONInsert(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestJSONInsert(TableTest):
tables = [MyTable]

def check_response(self):
row = MyTable.select(MyTable.json).first().run_sync()
Expand All @@ -112,12 +99,8 @@ def test_json_object(self):
MyTable.insert(row).run_sync()


class TestJSONUpdate(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestJSONUpdate(TableTest):
tables = [MyTable]

def add_row(self):
row = MyTable(json={"message": "original"})
Expand Down
14 changes: 3 additions & 11 deletions tests/columns/test_jsonb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from unittest import TestCase

from piccolo.columns.column_types import JSONB, ForeignKey, Varchar
from piccolo.table import Table
from tests.base import engines_only, engines_skip
from tests.base import TableTest, engines_only, engines_skip


class RecordingStudio(Table):
Expand All @@ -16,14 +14,8 @@ class Instrument(Table):


@engines_only("postgres", "cockroach")
class TestJSONB(TestCase):
def setUp(self):
RecordingStudio.create_table().run_sync()
Instrument.create_table().run_sync()

def tearDown(self):
Instrument.alter().drop_table().run_sync()
RecordingStudio.alter().drop_table().run_sync()
class TestJSONB(TableTest):
tables = [RecordingStudio, Instrument]

def test_json(self):
"""
Expand Down
10 changes: 3 additions & 7 deletions tests/columns/test_numeric.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
from decimal import Decimal
from unittest import TestCase

from piccolo.columns.column_types import Numeric
from piccolo.table import Table
from tests.base import TableTest


class MyTable(Table):
column_a = Numeric()
column_b = Numeric(digits=(3, 2))


class TestNumeric(TestCase):
def setUp(self):
MyTable.create_table().run_sync()

def tearDown(self):
MyTable.alter().drop_table().run_sync()
class TestNumeric(TableTest):
tables = [MyTable]

def test_creation(self):
row = MyTable(column_a=Decimal(1.23), column_b=Decimal(1.23))
Expand Down
Loading

0 comments on commit d91d59c

Please sign in to comment.