Пример #1
0
 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
Пример #2
0
 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())
Пример #3
0
 def render(self):
     return self.render_template('explorer/play.html', {
         'title': 'Playground',
         'form': QueryForm()
     })
Пример #4
0
 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())
Пример #5
0
 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())
Пример #6
0
 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())
Пример #7
0
 def render(self):
     return self.render_template('reports/playground.html', {
         'title': 'Playground',
         'form': QueryForm(),
         'no_jquery': True
     })
Пример #8
0
 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())
Пример #9
0
 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())
Пример #10
0
 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())
Пример #11
0
 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())
Пример #12
0
 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())