def test_no_body(self): query = """ -- name: test -- documentation1 -- documentation2 """ with self.assertRaises(ParseError): parse_query(LineParser(query))
def test_simple_query(self): query = """ -- name: test QUERY BODY """ q = parse_query(LineParser(query)) self.assertEqual(q.name, 'test') self.assertFalse(q.statement) self.assertEqual(q.doc, '') self.assertEqual(q.body.strip(), 'QUERY BODY')
def test_doc_query(self): query = """ -- name: test -- documentation1 -- documentation2 QUERY BODY """ q = parse_query(LineParser(query)) self.assertEqual(q.name, 'test') self.assertEqual(q.doc.strip(), 'documentation1\ndocumentation2') self.assertEqual(q.body.strip(), 'QUERY BODY')
def test_include_comment_query(self): query = """ -- name: test QUERY BODY 1 -- comment QUERY BODY 2 """ q = parse_query(LineParser(query)) self.assertEqual(q.name, 'test') self.assertEqual(q.doc, '') self.assertEqual([l.strip() for l in q.body.splitlines()], ['QUERY BODY 1', '-- comment', 'QUERY BODY 2', ''])
def test_multiline_query(self): query = """ -- name: test QUERY BODY 1 QUERY BODY 2 QUERY BODY 3 """ q = parse_query(LineParser(query)) self.assertEqual(q.name, 'test') self.assertEqual(q.doc, '') self.assertEqual([l.strip() for l in q.body.splitlines()], ['QUERY BODY 1', '', 'QUERY BODY 2', '', 'QUERY BODY 3', ''])
def test_multiline_query(self): query = """ -- name: test QUERY BODY 1 QUERY BODY 2 QUERY BODY 3 """ q = parse_query(LineParser(query)) self.assertEqual(q.name, 'test') self.assertEqual(q.doc, '') self.assertEqual( [l.strip() for l in q.body.splitlines()], ['QUERY BODY 1', '', 'QUERY BODY 2', '', 'QUERY BODY 3', ''])
def test_empty(self): with self.assertRaises(ParseError): parse_query(LineParser(""))
def test_no_doc_or_body(self): query = """ -- name: test """ with self.assertRaises(ParseError): parse_query(LineParser(query))