mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +01:00
ShrinkUrl: Remove goo.gl (buggy) and fix tests.
This commit is contained in:
parent
d8aa4f3181
commit
f293cfaeda
@ -42,11 +42,11 @@ def configure(advanced):
|
|||||||
conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True)
|
conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True)
|
||||||
|
|
||||||
class ShrinkService(registry.OnlySomeStrings):
|
class ShrinkService(registry.OnlySomeStrings):
|
||||||
"""Valid values include 'tiny', 'goo', 'ur1', and 'x0'."""
|
"""Valid values include 'tiny', 'ur1', and 'x0'."""
|
||||||
validStrings = ('tiny', 'goo', 'ur1', 'x0')
|
validStrings = ('tiny', 'ur1', 'x0')
|
||||||
|
|
||||||
class ShrinkCycle(registry.SpaceSeparatedListOfStrings):
|
class ShrinkCycle(registry.SpaceSeparatedListOfStrings):
|
||||||
"""Valid values include 'ln', 'tiny', 'goo', 'ur1', and 'x0'."""
|
"""Valid values include 'ln', 'tiny', 'ur1', and 'x0'."""
|
||||||
Value = ShrinkService
|
Value = ShrinkService
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -198,39 +198,6 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
irc.errorPossibleBug(str(e))
|
irc.errorPossibleBug(str(e))
|
||||||
tiny = thread(wrap(tiny, ['httpUrl']))
|
tiny = thread(wrap(tiny, ['httpUrl']))
|
||||||
|
|
||||||
_gooApi = 'https://www.googleapis.com/urlshortener/v1/url'
|
|
||||||
@retry
|
|
||||||
def _getGooUrl(self, url):
|
|
||||||
try:
|
|
||||||
return self.db.get('goo', url)
|
|
||||||
except KeyError:
|
|
||||||
headers = utils.web.defaultHeaders.copy()
|
|
||||||
headers['content-type'] = 'application/json'
|
|
||||||
data = json.dumps({'longUrl': url})
|
|
||||||
text = utils.web.getUrl(self._gooApi, data=data, headers=headers)
|
|
||||||
if sys.version_info[0] >= 3 and isinstance(text, bytes):
|
|
||||||
text = text.decode()
|
|
||||||
googl = json.loads(text)['id']
|
|
||||||
if googl:
|
|
||||||
self.db.set('goo', url, googl)
|
|
||||||
return googl
|
|
||||||
else:
|
|
||||||
raise ShrinkError(text)
|
|
||||||
|
|
||||||
def goo(self, irc, msg, args, url):
|
|
||||||
"""<url>
|
|
||||||
|
|
||||||
Returns an goo.gl version of <url>.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
goourl = self._getGooUrl(url)
|
|
||||||
m = irc.reply(goourl)
|
|
||||||
if m is not None:
|
|
||||||
m.tag('shrunken')
|
|
||||||
except ShrinkError as e:
|
|
||||||
irc.error(str(e))
|
|
||||||
goo = thread(wrap(goo, ['httpUrl']))
|
|
||||||
|
|
||||||
_ur1Api = 'http://ur1.ca/'
|
_ur1Api = 'http://ur1.ca/'
|
||||||
_ur1Regexp = re.compile(r'<a href="(?P<url>[^"]+)">')
|
_ur1Regexp = re.compile(r'<a href="(?P<url>[^"]+)">')
|
||||||
@retry
|
@retry
|
||||||
|
@ -39,11 +39,9 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
|
|||||||
'term=all+your+base+are+belong+to+us'
|
'term=all+your+base+are+belong+to+us'
|
||||||
tests = {'tiny': [(sfUrl, r'http://tinyurl.com/b7wyvfz'),
|
tests = {'tiny': [(sfUrl, r'http://tinyurl.com/b7wyvfz'),
|
||||||
(udUrl, r'http://tinyurl.com/u479')],
|
(udUrl, r'http://tinyurl.com/u479')],
|
||||||
'goo': [(sfUrl, r'http://goo.gl/3c59N'),
|
'ur1': [(sfUrl, r'http://ur1.ca/ceqh8'),
|
||||||
(udUrl, r'http://goo.gl/ocTga')],
|
|
||||||
'ur1': [(sfUrl, r'http://ur1.ca/9xl25'),
|
|
||||||
(udUrl, r'http://ur1.ca/9xl9k')],
|
(udUrl, r'http://ur1.ca/9xl9k')],
|
||||||
'x0': [(sfUrl, r'http://x0.no/0l2j'),
|
'x0': [(sfUrl, r'http://x0.no/a53s'),
|
||||||
(udUrl, r'http://x0.no/0l2k')]
|
(udUrl, r'http://x0.no/0l2k')]
|
||||||
}
|
}
|
||||||
if network:
|
if network:
|
||||||
@ -60,12 +58,12 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
|
|||||||
origsnarfer = snarfer()
|
origsnarfer = snarfer()
|
||||||
try:
|
try:
|
||||||
self.assertNotError(
|
self.assertNotError(
|
||||||
'config plugins.ShrinkUrl.serviceRotation goo x0')
|
'config plugins.ShrinkUrl.serviceRotation tiny x0')
|
||||||
self.assertError(
|
self.assertError(
|
||||||
'config plugins.ShrinkUrl.serviceRotation goo x1')
|
'config plugins.ShrinkUrl.serviceRotation tiny x1')
|
||||||
snarfer.setValue(True)
|
snarfer.setValue(True)
|
||||||
self.assertSnarfRegexp(self.udUrl, r'.*%s.* \(at' %
|
self.assertSnarfRegexp(self.udUrl, r'.*%s.* \(at' %
|
||||||
self.tests['goo'][1][1])
|
self.tests['tiny'][1][1])
|
||||||
self.assertSnarfRegexp(self.udUrl, r'.*%s.* \(at' %
|
self.assertSnarfRegexp(self.udUrl, r'.*%s.* \(at' %
|
||||||
self.tests['x0'][1][1])
|
self.tests['x0'][1][1])
|
||||||
finally:
|
finally:
|
||||||
@ -89,9 +87,6 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
|
|||||||
def testTinysnarf(self):
|
def testTinysnarf(self):
|
||||||
self._snarf('tiny')
|
self._snarf('tiny')
|
||||||
|
|
||||||
def testGoosnarf(self):
|
|
||||||
self._snarf('goo')
|
|
||||||
|
|
||||||
def testUr1snarf(self):
|
def testUr1snarf(self):
|
||||||
self._snarf('ur1')
|
self._snarf('ur1')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user