def get_instance_and_form(request, query_id): query = get_object_or_404(Query, pk=query_id) query.params = url_get_params(request) form = QueryForm(request.POST if len(request.POST) else None, instance=query) return query, form
def test_form_is_valid_with_valid_sql(self): q = SimpleQueryFactory(sql="select 1;", created_by_user_id=None) form = QueryForm(model_to_dict(q)) self.assertTrue(form.is_valid())
def render(self): return self.render_template('explorer/play.html', { 'title': 'Playground', 'form': QueryForm() })
def test_form_fails_blacklist(self): q = SimpleQueryFactory(sql="delete $$a$$;", created_by_user_id=None) q.params = {} form = QueryForm(model_to_dict(q)) self.assertFalse(form.is_valid())
def test_form_is_invalid_with_non_select_statement(self): q = SimpleQueryFactory(sql="delete $$a$$;", created_by_user_id=None) q.params = {} form = QueryForm(model_to_dict(q)) self.assertFalse(form.is_valid())
def test_form_is_valid_with_valid_sql(self): q = SimpleQueryFactory(sql="select 1;") form = QueryForm(model_to_dict(q)) self.assertTrue(form.is_valid())
def render(self): return self.render_template('reports/playground.html', { 'title': 'Playground', 'form': QueryForm(), 'no_jquery': True })
def test_form_is_always_valid_with_params(self): q = SimpleQueryFactory(sql="select $$a$$;") q.params = {} form = QueryForm(model_to_dict(q)) self.assertTrue(form.is_valid())
def test_form_fails_blacklist_even_with_params(self): q = SimpleQueryFactory(sql="delete $$a$$;", created_by_user_id=None) q.params = {} form = QueryForm(model_to_dict(q)) self.assertFalse(form.is_valid())
def test_form_is_not_valid_with_invalid_sql(self): q = SimpleQueryFactory(sql="select a;", created_by_user_id=None) form = QueryForm(model_to_dict(q)) self.assertFalse(form.is_valid())
def test_form_is_not_valid_with_invalid_sql(self): q = SimpleQueryFactory(sql="select a;") form = QueryForm(model_to_dict(q)) self.assertFalse(form.is_valid())