Esempio n. 1
0
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()
Esempio n. 2
0
 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"')
Esempio n. 3
0
 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"')
Esempio n. 4
0
 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')
Esempio n. 5
0
 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')
Esempio n. 6
0
 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())
Esempio n. 7
0
 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())
Esempio n. 8
0
 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))
Esempio n. 9
0
 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))
Esempio n. 10
0
 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))
Esempio n. 11
0
 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))
Esempio n. 12
0
 def test_happy_path(self):
     actual_input = '''
     SELECT *
     FROM schema.table
     '''
     self.assertEqual(sql_parser.run_parser(actual_input), Response.okay())
Esempio n. 13
0
 def test_check_conditional_happy_path(self):
     actual_input = ''' greater > lesser '''
     actual_conditional = Conditional(actual_input)
     self.assertEqual(actual_conditional.check_validity(), Response.okay())
Esempio n. 14
0
 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))