@@ -119,3 +119,85 @@ def test_updating(client):
119119
120120 assert response .content == b'{"response": {"props": {"children": "The chosen T-shirt is a medium blue one."}}}'
121121 assert response .status_code == 200
122+
123+ @pytest .mark .django_db
124+ def test_injection_app_access (client ):
125+ 'Check direct use of a stateless application using demo test data'
126+
127+ from django .urls import reverse
128+ from .app_name import main_view_label
129+
130+ for route_name in ['layout' , 'dependencies' , main_view_label ]:
131+ for prefix , arg_map in [('app-' , {'ident' :'dash_example_1' }),
132+ #('', {'ident':'simpleexample-1'}),
133+ ]:
134+ url = reverse ('the_django_plotly_dash:%s%s' % (prefix , route_name ), kwargs = arg_map )
135+
136+ response = client .get (url )
137+
138+ assert response .content
139+ assert response .status_code == 200
140+
141+ for route_name in ['routes' ,]:
142+ for prefix , arg_map in [('app-' , {'ident' :'dash_example_1' }),]:
143+ url = reverse ('the_django_plotly_dash:%s%s' % (prefix , route_name ), kwargs = arg_map )
144+
145+ did_fail = False
146+ try :
147+ response = client .get (url )
148+ except :
149+ did_fail = True
150+
151+ assert did_fail
152+
153+ @pytest .mark .django_db
154+ def test_injection_updating (client ):
155+ 'Check updating of an app using demo test data'
156+
157+ import json
158+ from django .urls import reverse
159+
160+ route_name = 'update-component'
161+
162+ for prefix , arg_map in [('app-' , {'ident' :'dash_example_1' }),]:
163+ url = reverse ('the_django_plotly_dash:%s%s' % (prefix , route_name ), kwargs = arg_map )
164+
165+ response = client .post (url , json .dumps ({'output' :{'id' :'test-output-div' , 'property' :'children' },
166+ 'inputs' :[{'id' :'my-dropdown1' ,
167+ 'property' :'value' ,
168+ 'value' :'TestIt' },
169+ ]}), content_type = "application/json" )
170+
171+ rStart = b'{"response": {"props": {"children":'
172+
173+ assert response .content [:len (rStart )] == rStart
174+ assert response .status_code == 200
175+
176+ have_thrown = False
177+
178+ try :
179+ response2 = client .post (url , json .dumps ({'output' :{'id' :'test-output-div2' , 'property' :'children' },
180+ 'inputs' :[{'id' :'my-dropdown2' ,
181+ 'property' :'value' ,
182+ 'value' :'TestIt' },
183+ ]}), content_type = "application/json" )
184+ except :
185+ have_thrown = True
186+
187+ assert have_thrown
188+
189+ session = client .session
190+ session ['django_plotly_dash' ] = {'django_to_dash_context' : 'Test 789 content' }
191+ session .save ()
192+
193+ response3 = client .post (url , json .dumps ({'output' :{'id' :'test-output-div2' , 'property' :'children' },
194+ 'inputs' :[{'id' :'my-dropdown2' ,
195+ 'property' :'value' ,
196+ 'value' :'TestIt' },
197+ ]}), content_type = "application/json" )
198+ rStart3 = b'{"response": {"props": {"children":'
199+
200+ assert response3 .content [:len (rStart3 )] == rStart3
201+ assert response3 .status_code == 200
202+
203+ assert response3 .content .find (b'Test 789 content' ) > 0
0 commit comments