From 1b25a207bf1b914ae93bea8167d5940231cc46f3 Mon Sep 17 00:00:00 2001 From: Daniel DiPaolo Date: Fri, 24 Oct 2003 01:03:18 +0000 Subject: [PATCH] Made MoobotFactoids case insensitive, and added tests to make sure that case-insensitivity works. --- plugins/MoobotFactoids.py | 18 +++++++++--------- test/test_MoobotFactoids.py | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/MoobotFactoids.py b/plugins/MoobotFactoids.py index c34052e40..15e783767 100644 --- a/plugins/MoobotFactoids.py +++ b/plugins/MoobotFactoids.py @@ -205,7 +205,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): return # Check the factoid db for an appropriate reply cursor = self.db.cursor() - cursor.execute("""SELECT fact FROM factoids WHERE key = %s""", key) + cursor.execute("""SELECT fact FROM factoids WHERE key LIKE %s""", key) if cursor.rowcount == 0: text = self._getDunno(msg.nick) irc.reply(msg, text, prefixName=False) @@ -249,7 +249,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): key, fact = match.groups() cursor = self.db.cursor() # Check and make sure it's not in the DB already - cursor.execute("""SELECT * FROM factoids WHERE key = %s""", key) + cursor.execute("""SELECT * FROM factoids WHERE key LIKE %s""", key) if cursor.rowcount != 0: irc.error(msg, "Factoid '%s' already exists." % key) return @@ -273,7 +273,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): cursor = self.db.cursor() # Check and make sure it's in the DB cursor.execute("""SELECT locked_at, fact FROM factoids - WHERE key = %s""", key) + WHERE key LIKE %s""", key) if cursor.rowcount == 0: irc.error(msg, "Factoid '%s' not found." % key) return @@ -308,7 +308,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): cursor = self.db.cursor() # Check and make sure it's in the DB cursor.execute("""SELECT locked_at, fact FROM factoids - WHERE key = %s""", key) + WHERE key LIKE %s""", key) if cursor.rowcount == 0: irc.error(msg, "Factoid '%s' not found." % key) return @@ -338,7 +338,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): cursor = self.db.cursor() # Check and make sure it's in the DB cursor.execute("""SELECT locked_at, fact FROM factoids - WHERE key = %s""", key) + WHERE key LIKE %s""", key) if cursor.rowcount == 0: irc.error(msg, "Factoid '%s' not found." % key) return @@ -367,7 +367,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): """ key = privmsgs.getArgs(args, needed=1) cursor = self.db.cursor() - cursor.execute("""SELECT fact FROM factoids WHERE key = %s""", key) + cursor.execute("""SELECT fact FROM factoids WHERE key LIKE %s""", key) if cursor.rowcount == 0: irc.error(msg, "No such factoid: %s" % key) return @@ -388,7 +388,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): cursor.execute("""SELECT created_by, created_at, modified_by, modified_at, last_requested_by, last_requested_at, requested_count, locked_at FROM - factoids WHERE key = %s""", key) + factoids WHERE key LIKE %s""", key) if cursor.rowcount == 0: irc.error(msg, "No such factoid: %s" % key) return @@ -432,7 +432,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): key = privmsgs.getArgs(args, needed=1) cursor = self.db.cursor() cursor.execute("""SELECT created_by, locked_at FROM factoids - WHERE key = %s""", key) + WHERE key LIKE %s""", key) if cursor.rowcount == 0: irc.error(msg, "No such factoid: %s" % key) return @@ -559,7 +559,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): key = privmsgs.getArgs(args, needed=1) cursor = self.db.cursor() cursor.execute("""SELECT key, locked_at FROM factoids - WHERE key = %s""", key) + WHERE key LIKE %s""", key) if cursor.rowcount == 0: irc.error(msg, "No such factoid: %s" % key) return diff --git a/test/test_MoobotFactoids.py b/test/test_MoobotFactoids.py index 919ebf06d..951f435ed 100644 --- a/test/test_MoobotFactoids.py +++ b/test/test_MoobotFactoids.py @@ -66,6 +66,10 @@ if sqlite is not None: # Test and make sure it's parsing self.assertNotError('moo4 is (1|2|3)') self.assertRegexp('moo4', '^(1|2|3)$') + # Check case-insensitivity + self.assertResponse('MOO', 'foo') + self.assertResponse('mOo', 'foo') + self.assertResponse('MoO', 'foo') def testFactinfo(self): self.assertNotError('moo is foo') @@ -206,7 +210,7 @@ if sqlite is not None: def testDunnoAdd(self): self.assertNotError('dunnoadd moo') - self.assertResponse('asdfagagfosdfk', 'moo (#1)') + self.assertResponse('asdfagagfosdfk', 'moo') def testDunnoRemove(self): self.assertNotError('dunnoadd moo')