ubuntu-bots/Encyclopedia/test.py

110 lines
3.8 KiB
Python

# -*- Encoding: utf-8 -*-
###
# Copyright (c) 2006 Dennis Kaarsemaker
# Copyright (c) 2010 Elián Hanisch
# Copyright (c) 2018 Krytarik Raido
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###
from supybot.test import *
import supybot.conf as conf
Econf = conf.supybot.plugins.Encyclopedia
Econf.prefixchar.set('@')
class EncyclopediaTestCase(ChannelPluginTestCase):
plugins = ('Encyclopedia',)
def setUp(self):
super(EncyclopediaTestCase, self).setUp()
conf.supybot.reply.whenNotCommand.setValue(False)
self.createDB()
def createDB(self):
import sqlite3, os
dbfile = os.path.join(Econf.datadir(), '%s.db' % Econf.database())
try:
os.remove(dbfile)
except:
pass
db = sqlite3.connect(dbfile)
cur = db.cursor()
cur.execute("""CREATE TABLE facts (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
value TEXT NOT NULL,
author TEXT NOT NULL,
added TEXT NOT NULL,
editor TEXT,
edited TEXT,
popularity INTEGER NOT NULL DEFAULT 0
)""")
cur.execute("""CREATE TABLE log (
id INTEGER PRIMARY KEY,
type TEXT NOT NULL,
name TEXT NOT NULL,
value TEXT NOT NULL,
author TEXT NOT NULL,
added TEXT NOT NULL
)""")
cur.execute("""CREATE TABLE requests (
id INTEGER PRIMARY KEY,
type TEXT NOT NULL,
name TEXT NOT NULL,
value TEXT NOT NULL,
requester TEXT NOT NULL,
requested TEXT NOT NULL
)""")
db.commit()
db.close()
self.getCallback().databases = {}
def getCallback(self):
for cb in self.irc.callbacks:
if cb.name() == 'Encyclopedia':
break
return cb
def testAdd(self):
self.assertNotError('foo is bar')
self.assertResponse('foo', 'foo is bar')
def testEdit(self):
self.assertNotError('foo is bar')
self.assertNotError('no, foo is bar1')
self.assertResponse('foo', 'foo is bar1')
def testKeyword(self):
self.assertNotError('hello is <reply> Hi, welcome to $chan!')
self.assertResponse('hello', 'Hi, welcome to #test!')
def testRequests(self):
world.testing = False
self.prefix = 'user!user@home.com'
try:
self.assertResponse('test-#ubuntu-se is <reply> blah',
'Your edit request has been forwarded to #ubuntu-ops. Thank you ' \
'for your attention to detail')
self.assertEqual(self.irc.takeMsg().args[1],
'In #test, user said: @test-#ubuntu-se is <reply> blah')
# test in private, it shouldn't use the prefix char.
self.assertResponse('test-#ubuntu-se is <reply> blah',
'Your edit request has been forwarded to #ubuntu-ops. Thank you ' \
'for your attention to detail', private=True, usePrefixChar=False)
self.assertEqual(self.irc.takeMsg().args[1],
'In test, user said: test-#ubuntu-se is <reply> blah')
finally:
world.testing = True