11import decimal
2- from unittest import TestCase
32
3+ from piccolo .testing .test_case import TableTest
44from tests .base import engine_is
55from tests .example_apps .music .tables import (
66 Band ,
77 Concert ,
8+ Instrument ,
89 Manager ,
10+ RecordingStudio ,
911 Signing ,
1012 Ticket ,
1113 Venue ,
@@ -23,12 +25,20 @@ def test_create_join(self):
2325 table .alter ().drop_table ().run_sync ()
2426
2527
26- class TestJoin (TestCase ):
27- tables = [Manager , Band , Venue , Concert , Ticket , Signing ]
28+ class TestJoin (TableTest ):
29+ tables = [
30+ Manager ,
31+ Band ,
32+ Venue ,
33+ Concert ,
34+ Ticket ,
35+ Signing ,
36+ Instrument ,
37+ RecordingStudio ,
38+ ]
2839
2940 def setUp (self ):
30- for table in self .tables :
31- table .create_table ().run_sync ()
41+ super ().setUp ()
3242
3343 manager_1 = Manager (name = "Guido" )
3444 manager_1 .save ().run_sync ()
@@ -56,9 +66,13 @@ def setUp(self):
5666 signing = Signing (with_ = band_1 )
5767 signing .save ().run_sync ()
5868
59- def tearDown (self ):
60- for table in reversed (self .tables ):
61- table .alter ().drop_table ().run_sync ()
69+ recording_studio = RecordingStudio (facilities = {"restaurant" : True })
70+ recording_studio .save ().run_sync ()
71+
72+ instrument = Instrument (
73+ name = "Piccolo" , recording_studio = recording_studio
74+ )
75+ instrument .save ().run_sync ()
6276
6377 ###########################################################################
6478
@@ -399,6 +413,26 @@ def test_objects__all_related__deep(self):
399413 self .assertIsInstance (ticket .concert .band_1 .manager , Manager )
400414 self .assertIsInstance (ticket .concert .band_2 .manager , Manager )
401415
416+ def test_objects_nested_with_load_json (self ):
417+ """
418+ Make sure that nested objects works alongside ``load_json`` (i.e. the
419+ JSON on nested objects gets loaded).
420+
421+ https://github.com/piccolo-orm/piccolo/issues/1383
422+
423+ """
424+ instrument = (
425+ Instrument .objects (Instrument .recording_studio )
426+ .output (load_json = True )
427+ .first ()
428+ .run_sync ()
429+ )
430+ assert instrument is not None
431+ self .assertDictEqual (
432+ instrument .recording_studio .facilities ,
433+ {"restaurant" : True },
434+ )
435+
402436 def test_objects_prefetch_clause (self ):
403437 """
404438 Make sure that ``prefetch`` clause works correctly.
0 commit comments