def test_get_read_permission_pattern(self): postsai = api.Postsai({}) self.assertEqual(postsai.get_read_permission_pattern(), ".*", "no read permission function") postsai = api.Postsai( {"get_read_permission_pattern": get_permission_pattern}) self.assertEqual(postsai.get_read_permission_pattern(), "^test$", "read permission function defined")
def test_create_where_for_date(self): postsai = api.Postsai({}) postsai.data = [] postsai.sql = "" postsai.create_where_for_date(self.FormMock({"date": "none"})) self.assertEqual(postsai.sql, " AND 1 = 0") postsai.sql = "" postsai.create_where_for_date(self.FormMock({"date": "day"})) self.assertEqual(postsai.sql, " AND ci_when >= DATE_SUB(NOW(),INTERVAL 1 DAY)") postsai.sql = "" postsai.create_where_for_date(self.FormMock({"date": "week"})) self.assertEqual(postsai.sql, " AND ci_when >= DATE_SUB(NOW(),INTERVAL 1 WEEK)") postsai.sql = "" postsai.create_where_for_date(self.FormMock({"date": "month"})) self.assertEqual(postsai.sql, " AND ci_when >= DATE_SUB(NOW(),INTERVAL 1 MONTH)") postsai.sql = "" postsai.create_where_for_date( self.FormMock({ "date": "hours", "hours": "2" })) self.assertEqual(postsai.sql, " AND ci_when >= DATE_SUB(NOW(),INTERVAL %s HOUR)") postsai.sql = "" postsai.create_where_for_date( self.FormMock({ "date": "explicit", "mindate": "2016-02-22", "maxdate": "" })) self.assertEqual(postsai.sql, " AND ci_when >= %s") postsai.sql = "" postsai.create_where_for_date( self.FormMock({ "date": "explicit", "mindate": "", "maxdate": "2016-02-22" })) self.assertEqual(postsai.sql, " AND ci_when <= %s") postsai.sql = "" postsai.create_where_for_date(self.FormMock({"date": "invalid21345"})) self.assertEqual(postsai.sql, "")
def test_validate_input(self): postsai = api.Postsai({}) form = self.FormMock({"who": "postman"}) self.assertEqual(postsai.validate_input(form), "", "no filter") postsai = api.Postsai({"filter": {"who": "^cvsscript$"}}) form = self.FormMock({"who": "postman"}) self.assertNotEqual(postsai.validate_input(form), "", "postman is not a permitted user") form = self.FormMock({"who": "cvsscript"}) self.assertEqual(postsai.validate_input(form), "", "cvsscript is a permitted user") form = self.FormMock({"who": "^cvsscript$"}) self.assertEqual(postsai.validate_input(form), "", "^cvsscript$ is a permitted user") form = self.FormMock({}) self.assertEqual(postsai.validate_input(form), "", "parameter is not present")
def test_create_where_for_column(self): postsai = api.Postsai({}) postsai.sql = "" postsai.data = [] form = self.FormMock({ "file": "config.py", "filetype": "", "branch": "HEAD", "branchtype": "match", "dir": "webapps.*", "dirtype": "regexp", "repository": "stendhal", "repositorytype": "notregexp", "description": "bla", "descriptiontype": "search" }) postsai.create_where_for_column("who", form, "who") self.assertEqual(postsai.sql, "", "undefined parameter") postsai.create_where_for_column("file", form, "file") self.assertEqual(postsai.sql, " AND file = %s", "file with empty match type") postsai.create_where_for_column("branch", form, "branch") self.assertEqual(postsai.sql, " AND file = %s AND branch = %s", "branch with match") postsai.create_where_for_column("dir", form, "dir") self.assertEqual(postsai.sql, " AND file = %s AND branch = %s AND dir REGEXP %s", "dir with regexp") postsai.sql = "" postsai.create_where_for_column("repository", form, "repository") self.assertEqual(postsai.sql, " AND repository NOT REGEXP %s", "repository with not regexp") postsai.sql = "" postsai.create_where_for_column("description", form, "description") self.assertEqual(postsai.sql, " AND MATCH (description) AGAINST (%s)", "description matching")
def test_create_query(self): postsai = api.Postsai({}) postsai.create_query(self.FormMock({"limit": "10"})) self.assertTrue("LIMIT 10" in postsai.sql, "Limit")