def test_delete_query_removes_query(self): query_id = 1234 test_utils.create_query(query_id=query_id) self.post_to_delete_queries(query_id=query_id) query = helpers.get_record_from_id(SqlQuery, query_id) assert not query
def test_delete_query_requires_writer_privileges(self): query_id = 1234 test_utils.create_query(query_id=query_id) self.post_to_delete_queries(query_id=query_id, token_type='viewer') query = helpers.get_record_from_id(SqlQuery, query_id) assert query
def test_add_usergroup_to_query_with_bad_user_id(self): query_id = 1234 test_utils.create_query(query_id=query_id) response = self.patch_to_edit_queries(query_id=query_id, usergroup_ids=[99999]) query = helpers.get_record_from_id(SqlQuery, query_id) assert response.status_code == 400 assert not query.usergroups
def test_get_all_queries_returns_all_queries(self): test_utils.create_query(label='ug101') test_utils.create_query(label='ug202') query_count = len(SqlQuery.query.all()) response = self.get_to_get_all_queries() response_dict = json.loads(response.data) response_count = len(response_dict['queries']) assert response.status_code == 200 assert query_count == response_count
def test_edit_label_with_bad_label(self): starting_label = 'test123' conn_id = 42 test_utils.create_query(label=starting_label, query_id=conn_id) new_label = '' response = self.patch_to_edit_queries(label=new_label, query_id=conn_id) response_dict = json.loads(response.data) query = helpers.get_record_from_id(SqlQuery, conn_id) query_label = query.label assert query_label == starting_label
def test_edit_label_with_valid_data(self): starting_label = 'my_conn' conn_id = 42 test_utils.create_query(label=starting_label, query_id=conn_id) new_label = 'my_new_conn' response = self.patch_to_edit_queries(label=new_label, query_id=conn_id) query = helpers.get_record_from_id(SqlQuery, conn_id) query_label = query.label assert response.status_code == 200 assert query_label == new_label
def test_add_query_to_usergroup(self): usergroup_id = 1234 test_utils.create_usergroup(usergroup_id=usergroup_id) query_id = 42 test_utils.create_query(query_id=query_id) response = self.patch_to_edit_usergroups(usergroup_id=usergroup_id, query_ids=[query_id]) usergroup = helpers.get_record_from_id(Usergroup, usergroup_id) assert response.status_code == 200 assert len(usergroup.queries) == 1
def test_add_usergroup_to_query(self): usergroup_id = 42 usergroup = test_utils.create_usergroup(usergroup_id=usergroup_id) query_id = 1234 test_utils.create_query(query_id=query_id) response = self.patch_to_edit_queries(query_id=query_id, usergroup_ids=[usergroup_id]) query = helpers.get_record_from_id(SqlQuery, query_id) assert response.status_code == 200 assert len(query.usergroups) == 1 assert query.usergroups[0].id == usergroup_id
def test_create_chart_with_invalid_data(self): with db.session.no_autoflush: sql_query_id = 111 test_utils.create_query(query_id=sql_query_id) connection_id = 222 test_utils.create_connection(connection_id=connection_id) label = '' response = self.post_to_create_charts(label=label, sql_query_id=sql_query_id, connection_id=connection_id) response_dict = json.loads(response.data) chart = Chart.query.filter(Chart.label == label).first() assert response.status_code == 400 assert not chart
def test_create_chart_requires_writer_privileges(self): with db.session.no_autoflush: sql_query_id = 111 test_utils.create_query(query_id=sql_query_id) connection_id = 222 test_utils.create_connection(connection_id=connection_id) label = 'my chart' response = self.post_to_create_charts(label=label, sql_query_id=sql_query_id, connection_id=connection_id, token_type='viewer') response_dict = json.loads(response.data) chart = Chart.query.filter(Chart.label == label).first() assert response.status_code == 401 assert not chart
def test_execute_query_object_with_valid_input(self): conn = self.create_db_with_test_data() sql = 'select * from TABLE1' query = test_utils.create_query(label='testQ', raw_sql=sql) result = cm.execute_query_object(conn=conn, query=query) assert isinstance(result, list)