@@ -5842,69 +5842,27 @@ def test_post_clears_all_tags_when_none_selected(self):
58425842
58435843class TestGrafanaProxyView (AuthTestCase ):
58445844 def _dashboard_url (self , slug ):
5845- return reverse ("nimbus-ui-grafana-proxy" , kwargs = { "path" : "" } ) + f"?slug={ slug } "
5845+ return reverse ("nimbus-ui-grafana-proxy" ) + f"?slug={ slug } "
58465846
58475847 @patch ("experimenter.nimbus_ui.views.requests.get" )
5848- def test_proxy_returns_grafana_html (self , mock_get ):
5848+ def test_proxy_returns_grafana_response (self , mock_get ):
58495849 feature = NimbusFeatureConfigFactory .create (
58505850 slug = "my-feature" ,
58515851 application = NimbusExperiment .Application .DESKTOP ,
58525852 )
58535853 mock_get .return_value .status_code = 200
58545854 mock_get .return_value .headers = {"Content-Type" : "text/html; charset=utf-8" }
5855- mock_get .return_value .text = (
5856- '<html><head><base href="/"></head><body></body></html>'
5857- )
5855+ mock_get .return_value .content = b"<html></html>"
58585856
58595857 response = self .client .get (self ._dashboard_url (feature .slug ))
58605858
58615859 self .assertEqual (response .status_code , 200 )
58625860 mock_get .assert_called_once ()
58635861 call_url = mock_get .call_args [0 ][0 ]
58645862 self .assertIn ("nimbus-feature-monitoring" , call_url )
5865-
5866- @patch ("experimenter.nimbus_ui.views.requests.get" )
5867- def test_proxy_rewrites_base_href (self , mock_get ):
5868- feature = NimbusFeatureConfigFactory .create (
5869- slug = "my-feature" ,
5870- application = NimbusExperiment .Application .DESKTOP ,
5871- )
5872- mock_get .return_value .status_code = 200
5873- mock_get .return_value .headers = {"Content-Type" : "text/html" }
5874- mock_get .return_value .text = '<base href="/">'
5875-
5876- response = self .client .get (self ._dashboard_url (feature .slug ))
5877-
5878- self .assertIn (b"/nimbus/grafana-proxy/" , response .content )
5879- self .assertNotIn (b'base href="/"' , response .content )
5880-
5881- @patch ("experimenter.nimbus_ui.views.requests.get" )
5882- def test_proxy_rewrites_app_url_in_boot_data (self , mock_get ):
5883- feature = NimbusFeatureConfigFactory .create (
5884- slug = "my-feature" ,
5885- application = NimbusExperiment .Application .DESKTOP ,
5886- )
5887- mock_get .return_value .status_code = 200
5888- mock_get .return_value .headers = {"Content-Type" : "text/html" }
5889- mock_get .return_value .text = '"appUrl":"https://yardstick.mozilla.org/"'
5890-
5891- response = self .client .get (self ._dashboard_url (feature .slug ))
5892-
5893- self .assertIn (b"/nimbus/grafana-proxy/" , response .content )
5894- self .assertNotIn (b"yardstick.mozilla.org" , response .content )
5895-
5896- @patch ("experimenter.nimbus_ui.views.requests.get" )
5897- def test_proxy_returns_binary_content_unchanged (self , mock_get ):
5898- mock_get .return_value .status_code = 200
5899- mock_get .return_value .headers = {"Content-Type" : "application/javascript" }
5900- mock_get .return_value .content = b"console.log('hello');"
5901-
5902- response = self .client .get (
5903- reverse ("nimbus-ui-grafana-proxy" , kwargs = {"path" : "public/build/app.js" }),
5904- )
5905-
5906- self .assertEqual (response .status_code , 200 )
5907- self .assertEqual (response .content , b"console.log('hello');" )
5863+ call_params = mock_get .call_args [1 ]["params" ]
5864+ self .assertEqual (call_params ["var-feature" ], "my-feature" )
5865+ self .assertEqual (call_params ["var-application" ], "firefox_desktop" )
59085866
59095867 @patch (
59105868 "experimenter.nimbus_ui.views.requests.get" ,
@@ -5921,9 +5879,7 @@ def test_proxy_returns_503_when_grafana_unavailable(self, mock_get):
59215879
59225880 def test_proxy_requires_login (self ):
59235881 self .client .defaults .pop (settings .OPENIDC_EMAIL_HEADER )
5924- response = self .client .get (
5925- reverse ("nimbus-ui-grafana-proxy" , kwargs = {"path" : "d/abc/my-dashboard" }),
5926- )
5882+ response = self .client .get (reverse ("nimbus-ui-grafana-proxy" ))
59275883 self .assertNotEqual (response .status_code , 200 )
59285884
59295885 @override_settings (GRAFANA_SERVICE_ACCOUNT_TOKEN = "test-token" )
@@ -5935,17 +5891,15 @@ def test_proxy_sends_service_account_token(self, mock_get):
59355891 )
59365892 mock_get .return_value .status_code = 200
59375893 mock_get .return_value .headers = {"Content-Type" : "text/html" }
5938- mock_get .return_value .text = ""
5894+ mock_get .return_value .content = b ""
59395895
59405896 self .client .get (self ._dashboard_url (feature .slug ))
59415897
59425898 call_headers = mock_get .call_args [1 ]["headers" ]
59435899 self .assertEqual (call_headers ["Authorization" ], "Bearer test-token" )
59445900
59455901 def test_proxy_returns_400_when_slug_missing (self ):
5946- response = self .client .get (
5947- reverse ("nimbus-ui-grafana-proxy" , kwargs = {"path" : "" }),
5948- )
5902+ response = self .client .get (reverse ("nimbus-ui-grafana-proxy" ))
59495903 self .assertEqual (response .status_code , 400 )
59505904
59515905 def test_proxy_returns_404_when_slug_invalid (self ):
0 commit comments