Skip to content

Commit

Permalink
add a test for multidimensional arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Mar 26, 2024
1 parent cb6966f commit 559fa99
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions tests/crud/test_crud_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
from unittest import TestCase

from piccolo.apps.user.tables import BaseUser
from piccolo.columns import Email, ForeignKey, Integer, Secret, Text, Varchar
from piccolo.columns import (
Array,
Email,
ForeignKey,
Integer,
Secret,
Text,
Varchar,
)
from piccolo.columns.column_types import OnDelete
from piccolo.columns.readable import Readable
from piccolo.table import Table, create_db_tables_sync, drop_db_tables_sync
Expand Down Expand Up @@ -43,6 +51,10 @@ class Studio(Table):
booking_email = Email(default="[email protected]")


class Seats(Table):
arrangement = Array(Array(Varchar()))


class Cinema(Table):
name = Varchar()
address = Text(unique=True)
Expand Down Expand Up @@ -1131,7 +1143,7 @@ def test_match(self):

class TestFilterEmail(TestCase):
"""
Make suer that ``Email`` columns can be filtered - i.e. we can pass in
Make sure that ``Email`` columns can be filtered - i.e. we can pass in
partial emails like ``google.com``.
"""

Expand Down Expand Up @@ -1179,6 +1191,61 @@ def test_filter_email(self):
)


class TestFilterMultidimensionalArray(TestCase):
"""
Make sure that multidimensional ``Array`` columns can be filtered.
"""

def setUp(self):
Seats.create_table(if_not_exists=True).run_sync()

def tearDown(self):
Seats.alter().drop_table().run_sync()

def test_filter_multidimensional_array(self):
client = TestClient(PiccoloCRUD(table=Seats))

Seats.insert(
Seats(
{
Seats.arrangement: [
["A1", "A2", "A3"],
["B1", "B2", "B3"],
["C1", "C2", "C3"],
],
}
),
Seats(
{
Seats.arrangement: [
["D1", "D2", "D3"],
["E1", "E2", "E3"],
["F1", "F2", "F3"],
],
}
),
).run_sync()

response = client.get("/?arrangement=A1")
self.assertEqual(response.status_code, 200)

self.assertEqual(
response.json(),
{
"rows": [
{
"id": 1,
"arrangement": [
["A1", "A2", "A3"],
["B1", "B2", "B3"],
["C1", "C2", "C3"],
],
}
]
},
)


class TestExcludeSecrets(TestCase):
"""
Make sure that if ``exclude_secrets`` is ``True``, then values for
Expand Down

0 comments on commit 559fa99

Please sign in to comment.