@@ -24,6 +24,12 @@ def __init__(self, user) -> None:
2424 self .GET = {}
2525
2626
27+ class MockResponse :
28+ def __init__ (self , context_data = None ) -> None :
29+ if context_data :
30+ self .context_data = {}
31+
32+
2733@pytest .fixture
2834def user_with_group (request , django_user_model , user_group ):
2935 marker = request .node .get_closest_marker ("user_group" )
@@ -319,6 +325,7 @@ def test_project_event_inlines(admin_with_user):
319325 site , request = admin_with_user
320326 inline = ProjectEventInline (Project , site .admin_site )
321327 assert not inline .has_add_permission ({})
328+ assert not inline .has_change_permission ({})
322329
323330 project = Project (sentry_id = "123" )
324331 event = Event (project = project , type = EventType .FIRING , timestamp = timezone .now ())
@@ -337,6 +344,7 @@ def test_app_event_inlines(admin_with_user):
337344 inline = AppEventInline (App , site .admin_site )
338345 app = App (reference = "123" )
339346 assert not inline .has_add_permission ({})
347+ assert not inline .has_change_permission ({})
340348 assert len (inline .get_form_queryset (app )) == 0
341349
342350 project = Project (sentry_id = "123" )
@@ -350,7 +358,7 @@ def test_app_event_inlines(admin_with_user):
350358 inline .save_new_instance ({}, {})
351359
352360
353- @patch ("django_object_actions.utils.BaseDjangoObjectActions .change_view" )
361+ @patch ("django.contrib.admin.ModelAdmin .change_view" )
354362@pytest .mark .django_db
355363@pytest .mark .parametrize ("user_group" , ["Developer" ])
356364@pytest .mark .admin_site (model_class = Project )
@@ -364,7 +372,27 @@ def test_project_chart_no_data(super_call: Mock, admin_with_user):
364372 super_call .assert_called_once_with (request , project .sentry_id , "" , extra_context )
365373
366374
367- @patch ("django_object_actions.utils.BaseDjangoObjectActions.change_view" )
375+ @patch ("django.contrib.admin.ModelAdmin.change_view" )
376+ @pytest .mark .django_db
377+ @pytest .mark .parametrize ("user_group" , ["Developer" ])
378+ @pytest .mark .admin_site (model_class = Project )
379+ def test_project_chart_no_context (super_call : Mock , admin_with_user ):
380+ site , request = admin_with_user
381+ project = Project (sentry_id = "123" )
382+ project .detection_result = {
383+ "signal" : [0 , 1 ],
384+ "avg_filter" : [0 , 1 ],
385+ "std_filter" : [0 , 2 ],
386+ "series" : [0 , 5 ],
387+ "intervals" : ["a" , "b" ],
388+ }
389+ project .save ()
390+ super_call .return_value = MockResponse (context_data = False )
391+ response = site .change_view (request , project .sentry_id )
392+ assert not hasattr (response , "context_data" )
393+
394+
395+ @patch ("django.contrib.admin.ModelAdmin.change_view" )
368396@pytest .mark .django_db
369397@pytest .mark .parametrize ("user_group" , ["Developer" ])
370398@pytest .mark .admin_site (model_class = Project )
@@ -379,7 +407,8 @@ def test_project_chart(super_call: Mock, admin_with_user):
379407 "intervals" : ["a" , "b" ],
380408 }
381409 project .save ()
382- site .change_view (request , project .sentry_id )
410+ super_call .return_value = MockResponse (context_data = True )
411+ response = site .change_view (request , project .sentry_id )
383412
384413 expected_context = {
385414 "adminchart_chartjs_config" : {
@@ -424,4 +453,6 @@ def test_project_chart(super_call: Mock, admin_with_user):
424453 }
425454 }
426455
427- super_call .assert_called_once_with (request , project .sentry_id , "" , expected_context )
456+ super_call .assert_called_once_with (request , project .sentry_id , "" , None )
457+
458+ assert response .context_data == expected_context
0 commit comments