From 3dd99626ff3fd55f8c820c30573a499e0869aaa7 Mon Sep 17 00:00:00 2001 From: HelloZeroNet Date: Mon, 18 Apr 2016 00:47:42 +0200 Subject: [PATCH] Test DbQuery --- src/Test/TestDbQuery.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Test/TestDbQuery.py diff --git a/src/Test/TestDbQuery.py b/src/Test/TestDbQuery.py new file mode 100644 index 00000000..214704a4 --- /dev/null +++ b/src/Test/TestDbQuery.py @@ -0,0 +1,31 @@ +import re + +from Db import DbQuery + + +class TestDbQuery: + def testParse(self): + query_text = """ + SELECT + 'comment' AS type, + date_added, post.title AS title, + keyvalue.value || ': ' || comment.body AS body, + '?Post:' || comment.post_id || '#Comments' AS url + FROM + comment + LEFT JOIN json USING (json_id) + LEFT JOIN json AS json_content ON (json_content.directory = json.directory AND json_content.file_name='content.json') + LEFT JOIN keyvalue ON (keyvalue.json_id = json_content.json_id AND key = 'cert_user_id') + LEFT JOIN post ON (comment.post_id = post.post_id) + WHERE + post.date_added > 123 + ORDER BY + date_added DESC + LIMIT 20 + """ + query = DbQuery(query_text) + assert query.parts["LIMIT"] == "20" + assert query.fields["body"] == "keyvalue.value || ': ' || comment.body" + assert re.sub("[ \r\n]", "", str(query)) == re.sub("[ \r\n]", "", query_text) + query.wheres.append("body LIKE '%hello%'") + assert "body LIKE '%hello%'" in str(query)