2005-02-01 10:09:49 +01:00
|
|
|
###
|
|
|
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
2012-09-01 16:16:48 +02:00
|
|
|
# Copyright (c) 2009-2010, James McCoy
|
2005-02-01 10:09:49 +01:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
|
|
|
from supybot.test import *
|
|
|
|
|
|
|
|
class ShrinkUrlTestCase(ChannelPluginTestCase):
|
|
|
|
plugins = ('ShrinkUrl',)
|
2009-11-05 04:37:53 +01:00
|
|
|
config = {'supybot.snarfThrottle': 0}
|
2009-10-09 04:28:02 +02:00
|
|
|
|
2013-01-04 22:56:12 +01:00
|
|
|
sfUrl ='http://sourceforge.net/p/supybot/bugs/?source=navbar'
|
2009-10-09 04:28:02 +02:00
|
|
|
udUrl = 'http://www.urbandictionary.com/define.php?' \
|
|
|
|
'term=all+your+base+are+belong+to+us'
|
2013-01-04 22:56:12 +01:00
|
|
|
tests = {'tiny': [(sfUrl, r'http://tinyurl.com/b7wyvfz'),
|
2009-10-09 04:28:02 +02:00
|
|
|
(udUrl, r'http://tinyurl.com/u479')],
|
2015-04-19 12:56:39 +02:00
|
|
|
'ur1': [(sfUrl, r'http://ur1.ca/ceqh8'),
|
2012-08-11 11:07:40 +02:00
|
|
|
(udUrl, r'http://ur1.ca/9xl9k')],
|
2015-04-19 12:56:39 +02:00
|
|
|
'x0': [(sfUrl, r'http://x0.no/a53s'),
|
2009-10-09 04:58:57 +02:00
|
|
|
(udUrl, r'http://x0.no/0l2k')]
|
2009-10-09 04:28:02 +02:00
|
|
|
}
|
2005-02-01 10:09:49 +01:00
|
|
|
if network:
|
2009-10-09 04:28:02 +02:00
|
|
|
def testShrink(self):
|
2010-07-11 15:48:16 +02:00
|
|
|
for (service, testdata) in self.tests.iteritems():
|
|
|
|
for (url, shrunkurl) in testdata:
|
|
|
|
self.assertRegexp('shrinkurl %s %s' % (service, url),
|
|
|
|
shrunkurl)
|
|
|
|
|
|
|
|
def testShrinkCycle(self):
|
|
|
|
cycle = conf.supybot.plugins.ShrinkUrl.serviceRotation
|
2009-10-09 04:28:02 +02:00
|
|
|
snarfer = conf.supybot.plugins.ShrinkUrl.shrinkSnarfer
|
2010-07-11 15:48:16 +02:00
|
|
|
origcycle = cycle()
|
|
|
|
origsnarfer = snarfer()
|
2005-02-01 10:09:49 +01:00
|
|
|
try:
|
2010-07-11 15:48:16 +02:00
|
|
|
self.assertNotError(
|
2015-04-19 12:56:39 +02:00
|
|
|
'config plugins.ShrinkUrl.serviceRotation tiny x0')
|
2010-07-11 15:48:16 +02:00
|
|
|
self.assertError(
|
2015-04-19 12:56:39 +02:00
|
|
|
'config plugins.ShrinkUrl.serviceRotation tiny x1')
|
2010-07-11 15:48:16 +02:00
|
|
|
snarfer.setValue(True)
|
2013-01-04 22:56:12 +01:00
|
|
|
self.assertSnarfRegexp(self.udUrl, r'.*%s.* \(at' %
|
2015-04-19 12:56:39 +02:00
|
|
|
self.tests['tiny'][1][1])
|
2013-01-04 22:56:12 +01:00
|
|
|
self.assertSnarfRegexp(self.udUrl, r'.*%s.* \(at' %
|
2010-07-11 15:48:16 +02:00
|
|
|
self.tests['x0'][1][1])
|
2005-02-01 10:09:49 +01:00
|
|
|
finally:
|
2010-07-11 15:48:16 +02:00
|
|
|
cycle.setValue(origcycle)
|
|
|
|
snarfer.setValue(origsnarfer)
|
2005-02-01 10:09:49 +01:00
|
|
|
|
2009-10-09 04:28:02 +02:00
|
|
|
def _snarf(self, service):
|
|
|
|
shrink = conf.supybot.plugins.ShrinkUrl
|
|
|
|
origService = shrink.default()
|
|
|
|
origSnarf = shrink.shrinkSnarfer()
|
|
|
|
shrink.default.setValue(service)
|
|
|
|
shrink.shrinkSnarfer.setValue(True)
|
2005-02-01 10:09:49 +01:00
|
|
|
try:
|
2009-10-09 04:28:02 +02:00
|
|
|
for (url, shrunkurl) in self.tests[service]:
|
2013-01-04 22:56:12 +01:00
|
|
|
teststr = r'.*%s.* \(at' % shrunkurl
|
2009-10-09 04:28:02 +02:00
|
|
|
self.assertSnarfRegexp(url, teststr)
|
2005-02-01 10:09:49 +01:00
|
|
|
finally:
|
2009-10-09 04:28:02 +02:00
|
|
|
shrink.default.setValue(origService)
|
|
|
|
shrink.shrinkSnarfer.setValue(origSnarf)
|
2005-02-01 10:09:49 +01:00
|
|
|
|
2009-10-09 04:28:02 +02:00
|
|
|
def testTinysnarf(self):
|
|
|
|
self._snarf('tiny')
|
2005-02-01 10:09:49 +01:00
|
|
|
|
2012-08-11 11:07:40 +02:00
|
|
|
def testUr1snarf(self):
|
|
|
|
self._snarf('ur1')
|
|
|
|
|
2009-10-09 04:58:57 +02:00
|
|
|
def testX0snarf(self):
|
|
|
|
self._snarf('x0')
|
|
|
|
|
2005-02-01 10:09:49 +01:00
|
|
|
def testNonSnarfing(self):
|
2009-10-09 04:28:02 +02:00
|
|
|
shrink = conf.supybot.plugins.ShrinkUrl
|
|
|
|
origService = shrink.default()
|
|
|
|
origSnarf = shrink.shrinkSnarfer()
|
|
|
|
origLen = shrink.minimumLength()
|
|
|
|
origRegexp = shrink.nonSnarfingRegexp()
|
|
|
|
shrink.default.setValue('tiny')
|
|
|
|
shrink.shrinkSnarfer.setValue(True)
|
|
|
|
shrink.minimumLength.setValue(10)
|
|
|
|
shrink.nonSnarfingRegexp.set('m/sf/')
|
2005-02-01 10:09:49 +01:00
|
|
|
try:
|
2009-10-09 04:28:02 +02:00
|
|
|
self.assertSnarfNoResponse('http://sf.net/', 5)
|
|
|
|
self.assertSnarfRegexp('http://sourceforge.net/',
|
|
|
|
r'http://tinyurl.com/7vm7.*\(at ')
|
2005-02-01 10:09:49 +01:00
|
|
|
finally:
|
2009-10-09 04:28:02 +02:00
|
|
|
shrink.default.setValue(origService)
|
|
|
|
shrink.shrinkSnarfer.setValue(origSnarf)
|
|
|
|
shrink.minimumLength.setValue(origLen)
|
|
|
|
shrink.nonSnarfingRegexp.setValue(origRegexp)
|
2005-02-01 10:09:49 +01:00
|
|
|
|
2012-09-02 10:06:33 +02:00
|
|
|
def testExpand(self):
|
|
|
|
self.assertResponse('expand http://x0.no/0l2k', self.udUrl)
|
|
|
|
self.assertResponse('expand http://x0.no/0l2k', self.udUrl)
|
2013-01-04 22:56:12 +01:00
|
|
|
self.assertResponse('expand http://x0.no/a53s', self.sfUrl)
|
|
|
|
self.assertResponse('expand http://x0.no/a53s', self.sfUrl)
|
2012-09-02 10:06:33 +02:00
|
|
|
self.assertResponse('expand http://x0.no/0l2k', self.udUrl)
|
|
|
|
|
2006-02-11 16:52:51 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|