99
1010
1111class ClientWithLastResponse :
12- def __init__ (self , client ):
12+ def __init__ (self , client : Client ):
1313 self .client = client
1414 self .last_response = None
1515
@@ -29,10 +29,6 @@ def setUp(self):
2929 def last_response (self ):
3030 return self .inertia .last_response or self .client .last_response
3131
32- def assertJSONResponse (self , response , json_obj ):
33- self .assertEqual (response .headers ["Content-Type" ], "application/json" )
34- self .assertEqual (response .json (), json_obj )
35-
3632
3733class InertiaTestCase (BaseInertiaTestCase , TestCase ):
3834 def setUp (self ):
@@ -47,11 +43,12 @@ def tearDown(self):
4743 self .mock_inertia .stop ()
4844
4945 def page (self ):
50- page_data = (
51- self .mock_render .call_args [0 ][1 ]["page" ]
52- if self .mock_render .call_args
53- else self .last_response ().content
54- )
46+ if self .mock_render .call_args :
47+ page_data = self .mock_render .call_args [0 ][1 ]["page" ]
48+ elif response := self .last_response ():
49+ page_data = response .content
50+ else :
51+ page_data = ""
5552
5653 return loads (page_data )
5754
@@ -75,6 +72,10 @@ def template_data(self):
7572 def component (self ):
7673 return self .page ()["component" ]
7774
75+ def assertJSONResponse (self , response , json_obj ):
76+ self .assertEqual (response .headers ["Content-Type" ], "application/json" )
77+ self .assertEqual (response .json (), json_obj )
78+
7879 def assertIncludesProps (self , props ):
7980 self .assertDictEqual (self .props (), {** self .props (), ** props })
8081
0 commit comments