def check_bracket_order(conditional_section): bracket_stack = [] for index, character in enumerate(conditional_section): if character == '(': bracket_stack.append(index) elif character == ')': if len(bracket_stack) == 0: return Response('Brackets don\' match', 1) bracket_stack.pop() if len(bracket_stack) != 0: return Response('Brackets don\' match', 1) return Response.okay()
def test_schema_table_spaces_quotes(self): actual_input = '"schema"."table name"' table_name = TableName(actual_input) response = table_name.check_validity() self.assertEquals(response, Response.okay()) self.assertEquals(table_name.schema, '"schema"') self.assertEquals(table_name.table, '"table name"')
def test_table_and_alias_quotes_alias(self): actual_input = '"table_name" "alias"' table_name = TableName(actual_input) response = table_name.check_validity() self.assertEquals(response, Response.okay()) self.assertEquals(table_name.table, '"table_name"') self.assertEquals(table_name.alias, '"alias"')
def test_and_table_no_quotes_alias(self): actual_input = 'table_name alias' table_name = TableName(actual_input) response = table_name.check_validity() self.assertEquals(response, Response.okay()) self.assertEquals(table_name.table, 'table_name') self.assertEquals(table_name.alias, 'alias')
def test_schema_and_table_no_quotes(self): actual_input = 'schema.table_name' table_name = TableName(actual_input) response = table_name.check_validity() self.assertEquals(response, Response.okay()) self.assertEquals(table_name.schema, 'schema') self.assertEquals(table_name.table, 'table_name')
def test_check_inner_query(self): actual_input = ''' SELECT lala,lalala FROM (SELECT * FROM lalaland) ''' select = Select(actual_input) select.check_validity() self.assertEquals(select.response, Response.okay())
def test_check_query_happy_path(self): actual_input = ''' SELECT * FROM schema.table ''' select = Select(actual_input) select.check_validity() self.assertEquals(select.response, Response.okay())
def test_check_query_unhappy_path(self): actual_input = ''' SELECT lala,lalala dfsdf FROM schema.table ''' select = Select(actual_input) select.check_validity() self.assertEquals(select.response, Response('ColumnList not properly made',1))
def test_table_alias_spaces_no_quotes(self): actual_input = 'table name alias' table_name = TableName(actual_input) response = table_name.check_validity() self.assertEquals(response, Response('Table Name has spaces without quotes', 1))
def test_too_many_periods_without_quotes(self): actual_input = 'sch.ema.table_name' table_name = TableName(actual_input) response = table_name.check_validity() self.assertEquals(response, Response('Schema Name has period without quotes', 1))
def test_space_after_period(self): actual_input = 'schema. table_name' table_name = TableName(actual_input) response = table_name.check_validity() self.assertEquals(response, Response('Failed to parse Table Name', 1))
def test_happy_path(self): actual_input = ''' SELECT * FROM schema.table ''' self.assertEqual(sql_parser.run_parser(actual_input), Response.okay())
def test_check_conditional_happy_path(self): actual_input = ''' greater > lesser ''' actual_conditional = Conditional(actual_input) self.assertEqual(actual_conditional.check_validity(), Response.okay())
def test_check_conditional_no_spaces(self): """No spaces implies that the columns are adjacent to the AND/OR""" actual_input = '''greater > lesser''' actual_conditional = Conditional(actual_input) self.assertEqual(actual_conditional.check_validity(), Response('No space between operator and field', 1))