-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test for multidimensional arrays
- Loading branch information
1 parent
cb6966f
commit 559fa99
Showing
1 changed file
with
69 additions
and
2 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 |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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``. | ||
""" | ||
|
||
|
@@ -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 | ||
|