forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_output.py
More file actions
30 lines (21 loc) · 847 Bytes
/
test_output.py
File metadata and controls
30 lines (21 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
from ..base import DBTestCase
from ..example_app.tables import Band
class TestOutputList(DBTestCase):
def test_output_as_list(self):
self.insert_row()
response = Band.select(Band.name).output(as_list=True).run_sync()
self.assertTrue(response == ["Pythonistas"])
# Make sure that if no rows are found, an empty list is returned.
empty_response = (
Band.select(Band.name)
.where(Band.name == "ABC123")
.output(as_list=True)
.run_sync()
)
self.assertTrue(empty_response == [])
class TestOutputJSON(DBTestCase):
def test_output_as_json(self):
self.insert_row()
response = Band.select(Band.name).output(as_json=True).run_sync()
self.assertTrue(json.loads(response) == [{"name": "Pythonistas"}])