def test_cant_query_with_unregistered_connection(self): from dataworkspace.apps.explorer.utils import ( # pylint: disable=import-outside-toplevel InvalidExplorerConnectionException, ) user = UserFactory() q = SimpleQueryFactory.create(sql="select '$$foo:bar$$', '$$qux$$';", connection='not_registered') with pytest.raises(InvalidExplorerConnectionException): q.execute(user, None, 10, 10000)
def test_cannot_post_to_another_users_query(self, staff_user, staff_client): query_creator = get_user_model().objects.create_superuser( "admin", "*****@*****.**", "pwd" ) query = SimpleQueryFactory.create(created_by_user=query_creator) data = model_to_dict(query) del data["id"] data["created_by_user_id"] = staff_user.id resp = staff_client.post( reverse("explorer:query_detail", kwargs={"query_id": query.id}), {**data, "action": "save"}, ) query = Query.objects.get(id=query.id) assert resp.status_code == 404 assert query.created_by_user_id == query_creator.id