def test_history_sidebar_invalid(self): response = self.client.get(reverse("djdt:history_sidebar")) self.assertEqual(response.status_code, 400) data = {"signed": SignedDataForm.sign({"store_id": "foo"}) + "invalid"} response = self.client.get(reverse("djdt:history_sidebar"), data=data) self.assertEqual(response.status_code, 400)
def test_sql_profile_checks_show_toolbar(self): url = "/__debug__/sql_profile/" data = { "signed": SignedDataForm.sign({ "sql": "SELECT * FROM auth_user", "raw_sql": "SELECT * FROM auth_user", "params": "{}", "alias": "default", "duration": "0", }) } response = self.client.post(url, data) self.assertEqual(response.status_code, 200) response = self.client.post(url, data, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.assertEqual(response.status_code, 200) with self.settings(INTERNAL_IPS=[]): response = self.client.post(url, data) self.assertEqual(response.status_code, 404) response = self.client.post(url, data, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.assertEqual(response.status_code, 404)
def test_sql_explain_postgres_json_field(self): url = "/__debug__/sql_explain/" base_query = ( 'SELECT * FROM "tests_postgresjson" WHERE "tests_postgresjson"."field" @>' ) query = base_query + """ '{"foo": "bar"}'""" data = { "signed": SignedDataForm.sign({ "sql": query, "raw_sql": base_query + " %s", "params": '["{\\"foo\\": \\"bar\\"}"]', "alias": "default", "duration": "0", }) } response = self.client.post(url, data) self.assertEqual(response.status_code, 200) response = self.client.post(url, data, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.assertEqual(response.status_code, 200) with self.settings(INTERNAL_IPS=[]): response = self.client.post(url, data) self.assertEqual(response.status_code, 404) response = self.client.post(url, data, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.assertEqual(response.status_code, 404)
def test_history_refresh(self): """Verify refresh history response has request variables.""" data = {"foo": "bar"} self.client.get("/json_view/", data, content_type="application/json") data = {"signed": SignedDataForm.sign({"store_id": "foo"})} response = self.client.get(reverse("djdt:history_refresh"), data=data) self.assertEqual(response.status_code, 200) data = response.json() self.assertEqual(len(data["requests"]), 1) for val in ["foo", "bar"]: self.assertIn(val, data["requests"][0]["content"])
def test_verified_data(self): form = SignedDataForm(data={"signed": SignedDataForm.sign(DATA)}) self.assertEqual( form.verified_data(), { "value": "foo", "date": "2020-01-01 00:00:00+00:00", }, ) # Take it back to the foo form to validate the datetime is serialized foo_form = FooForm(data=form.verified_data()) self.assertTrue(foo_form.is_valid()) self.assertDictEqual(foo_form.cleaned_data, DATA)
def test_history_sidebar(self): """Validate the history sidebar view.""" self.client.get("/json_view/") store_id = list(DebugToolbar._store.keys())[0] data = {"signed": SignedDataForm.sign({"store_id": store_id})} response = self.client.get(reverse("djdt:history_sidebar"), data=data) self.assertEqual(response.status_code, 200) self.assertEqual( set(response.json().keys()), { "VersionsPanel", "TimerPanel", "SettingsPanel", "HeadersPanel", "RequestPanel", "SQLPanel", "StaticFilesPanel", "TemplatesPanel", "CachePanel", "SignalsPanel", "LoggingPanel", "ProfilingPanel", }, )
def test_signed_data(self): data = {"signed": SignedDataForm.sign(DATA)} form = SignedDataForm(data=data) self.assertTrue(form.is_valid()) # Check the signature value self.assertEqual(data["signed"], SIGNED_DATA)