def test_areena_series(botmock): regex = u"Title: Kummeli \[SERIES - 54 episodes - latest episode: %s\]" % ( age_str_regex) msg = "http://areena.yle.fi/1-3339547" check_re( regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_areena_series(): regex = u'Title: (.*?) \[SERIES - \d+ episodes - latest episode: %s\]' % ( age_str_regex) msg = "http://areena.yle.fi/tv/2129619" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_areena_tv(): regex = u'Title: (.*?) \[%s - %s plays - %s( - exits in \d+ (weeks|days|hours|minutes))?\]' % ( lengh_str_regex, views_str_regex, age_str_regex) msg = "http://areena.yle.fi/tv/1999860" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_posti(): '''11d 1h 45m ago - Item delivered to the recipient. - TAALINTEHDAS 25900''' regex = u'(\d+d\ )?(\d+h\ )?(\d+m )?ago - (.*?) - (.*? )?(\d+)' check_re( regex, command_posti(bot, '[email protected]', '#example', 'JJFI')[1])
def test_liveleak(): regex = "Title: (.*?) by (.*?) \[%s views - Jul-23-2013 - tags\: sword, cut, hand, watermelon, fail\]" % ( views_str_regex ) msg = "http://www.liveleak.com/view?i=f8e_1374614129" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_vimeo(): regex = 'Title: (.*?) by (.*?) \[%s - %s likes - %s views - %s]' % ( lengh_str_regex, views_str_regex, views_str_regex, age_str_regex) msg = 'http://vimeo.com/29996808' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_simple(): module_wolfram_alpha.init(bot) query = "42" # Wolfram Alpha seems to randomly return also Roman numerals regex = u"(42 = forty-two|forty-two = XLII)" result = module_wolfram_alpha.command_wa(bot, None, "#channel", query)[1] check_re(regex, result)
def test_areena_not_available(botmock): regex = u"Title: (.*?) \[%s - %s - not available\]" % ( length_str_regex, age_str_regex, ) msg = "http://areena.yle.fi/1-2372901" check_re(regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_liveleak(): regex = 'Title: (.*?) by (.*?) \[%s views - Jul-23-2013 - tags\: sword, cut, hand, watermelon, fail\]' % ( views_str_regex) msg = 'http://www.liveleak.com/view?i=f8e_1374614129' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_youtube(): regex = 'Title: (.*?) by (.*?) \[%s - \[\** *\] - %s views - %s( - XXX)?\]' % ( lengh_str_regex, views_str_regex, age_str_regex) msg = "http://www.youtube.com/watch?v=awsolTK175c" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_areena_tv_exiting(botmock): regex = u"Title: (.*?) \[%s - %s( - exits in %s)?\]" % ( length_str_regex, age_str_regex, age_str_regex, ) msg = "http://areena.yle.fi/1-3093932" check_re(regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_areena_not_available(botmock): regex = u"Title: (.*?) \[%s - %s - not available\]" % ( length_str_regex, age_str_regex, ) msg = "http://areena.yle.fi/1-2372901" check_re( regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_youtube(): regex = "Title: (.*?) by (.*?) \[%s - %s views - %s( - age restricted)?\]" % ( lengh_str_regex, views_str_regex, age_str_regex, ) msg = "http://www.youtube.com/watch?v=awsolTK175c" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_youtube(botmock): regex = "Title: (.*?) by (.*?) \[%s - %s views - %s( - age restricted)?\]" % ( lengh_str_regex, views_str_regex, age_str_regex, ) msg = "http://www.youtube.com/watch?v=awsolTK175c" module_urltitle.init(botmock) check_re(regex, __handle_url(botmock, msg))
def test_vimeo(botmock): regex = "Title: (.*?) by (.*?) \[%s - %s likes - %s views - %s]" % ( lengh_str_regex, views_str_regex, views_str_regex, age_str_regex, ) msg = "http://vimeo.com/29996808" check_re(regex, __handle_url(botmock, msg))
def test_areena_tv_exiting(botmock): regex = u"Title: (.*?) \[%s - %s( - exits in %s)?\]" % ( length_str_regex, age_str_regex, age_str_regex, ) msg = "http://areena.yle.fi/1-3093932" check_re( regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_areena_tv_exiting_in_far_far_future(botmock): from datetime import datetime if datetime.utcnow() < datetime(2098, 1, 1): regex = u'Title: Kummeli - 5x03 \[%s - %s\]' % (length_str_regex, age_str_regex) else: regex = u'Title: Kummeli - 5x03 \[%s - %s( - exits in %s)?\]' % (length_str_regex, age_str_regex, age_str_regex) msg = "http://areena.yle.fi/1-1823488" check_re(regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_vimeo(): regex = "Title: (.*?) by (.*?) \[%s - %s likes - %s views - %s]" % ( lengh_str_regex, views_str_regex, views_str_regex, age_str_regex, ) msg = "http://vimeo.com/29996808" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_areena_tv_exiting_in_far_far_future(botmock): from datetime import datetime if datetime.utcnow() < datetime(2098, 1, 1): regex = u"Title: Kummeli - 5x03 \[%s - %s\]" % (length_str_regex, age_str_regex) else: regex = u"Title: Kummeli - 5x03 \[%s - %s( - exits in %s)?\]" % ( length_str_regex, age_str_regex, age_str_regex, ) msg = "http://areena.yle.fi/1-1823488" check_re( regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_areena_series(): regex = u'Title: (.*?) \[SERIES - \d+ episodes - latest episode: %s\]' % (age_str_regex) msg = "http://areena.yle.fi/1-2540167" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_weather(): regex = u'(Lappeenranta, (Finland|FI): Temperature: -?\d+.\d\xb0C, feels like: -?\d+.\d\xb0C, wind: \d+.\d m/s, humidity: \d+%, pressure: \d+ hPa, cloudiness: \d+%)|(Error: API error.)' check_re(regex, module_openweather.command_weather(bot, None, "#channel", 'lappeenranta')[1])
def test_add_feed(): check_re( r'feed added with \d+ items', command_rss( bot, ADMIN_USER, '#pyfibot', 'add http://feeds.feedburner.com/ampparit-kaikki?format=xml')[1])
def test_areena_series(botmock): regex = u"Title: Kummeli \[SERIES - 54 episodes - latest episode: %s\]" % ( age_str_regex ) msg = "http://areena.yle.fi/1-3339547" check_re(regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_youtube(): regex = 'Title: (.*?) by (.*?) \[%s - \[\**\] - %s views - %s( - XXX)?\]' % (lengh_str_regex, views_str_regex, age_str_regex) msg = "http://www.youtube.com/watch?v=awsolTK175c" module_urltitle.init(bot) assert check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_alko(): regex = 'Title: Sandels IV A tölkki \[\d\.\d\de, \d\.\d\dl, \d\.\d\de/l, oluet, 5\.30\%\]' msg = 'http://www.alko.fi/tuotteet/798684/' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_verkkokauppacom(botmock): msg = "http://www.verkkokauppa.com/fi/product/55124/dfbfn/Coca-Cola-Vanilla-USA-virvoitusjuoma-355-ml" regex = "Title: Coca-Cola Vanilla USA virvoitusjuoma 355 ml \| \d+,\d+ € \(.*?\)" check_re(regex, __handle_url(botmock, msg))
def test_areena_live(botmock): regex = u"Title: Yle TV2 - (.*?)( <http://areena.yle.fi/\d-\d+>)? \(LIVE\)" msg = "http://areena.yle.fi/tv/suora/tv2" check_re( regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_weather(): regex = u'Lappeenranta, FI: Temperature: \d+.\d\xb0C, feels like: \d+.\d\xb0C, wind: \d+.\d m/s, humidity: \d+%, pressure: \d+ hPa, cloudiness: \d+%' check_re(regex, module_openweather.command_weather(bot, None, "#channel", 'lappeenranta')[1])
def test_forecast(): regex = u'Lappeenranta, FI: tomorrow: \d+.\d-\d+.\d \xb0C \(.*?\), in 2 days: \d+.\d-\d+.\d \xb0C \(.*?\), in 3 days: \d+.\d-\d+.\d \xb0C \(.*?\)' check_re(regex, module_openweather.command_forecast(bot, None, "#channel", 'lappeenranta')[1])
def test_dx(): regex = u'Title: Wireless Bluetooth Audio Music Receiver Adapter - Black \[\d+\.\d+e - \[\** *\] - \d+ reviews\]' msg = 'http://dx.com/p/wireless-bluetooth-audio-music-receiver-adapter-black-151659' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_weather(): regex = u'(Lappeenranta, (Finland|FI): Temperature: -?\d+.\d\xb0C, feels like: -?\d+.\d\xb0C, wind: \d+.\d m/s, humidity: \d+%, pressure: \d+ hPa, cloudiness: \d+%)|(Error: API error.)' check_re( regex, module_openweather.command_weather(bot, None, "#channel", 'lappeenranta')[1])
def test_ebay_cgi(): msg = 'http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=121136837564' regex = 'Title: .*? \[\d+\.\de - over \d+ available - ships from .*?\]' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_verkkokauppacom(): msg = "http://www.verkkokauppa.com/fi/product/34214/dkqht/Sony-NEX-3N-mikrojarjestelmakamera-16-50-mm-objektiivi-musta" module_urltitle.init(bot) regex = 'Title: Sony NEX-3N mikrojärjestelmäkamera \+ 16-50 mm objektiivi, musta \| \d+,\d+ € \(.*?\)' check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_imdb(): regex = 'Title: Wreck-It Ralph \(2012\) - [\d.]{1,}/10 \(%s votes\) - .*' % views_str_regex msg = "http://www.imdb.com/title/tt1772341/" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_gfycat_reddit_title(botmock): regex = "Title: California Sunset \(/r/NatureGifs\) 1280x720@29fps \d+ views" msg = "http://www.gfycat.com/ZanyFragrantHoneyeater" check_re(regex, __handle_url(botmock, msg))
def test_command_add(): check_re( r'feed added with \d+ items', command_rss(bot, ADMIN_USER, '#pyfibot', 'add ./tests/static/test_rss_init.xml')[1])
def test_gfycat_own_title(botmock): regex = "Title: Star Trail's in the Desert 632x480@30fps \d+ views" msg = "https://www.gfycat.com/EcstaticWelllitHarpseal" check_re(regex, __handle_url(botmock, msg))
def test_areena_live(botmock): regex = u"Title: Yle TV2 - (.*?)( <http://areena.yle.fi/\d-\d+>)? \(LIVE\)" msg = "http://areena.yle.fi/tv/suora/tv2" check_re(regex, module_urltitle.handle_url(botmock, None, "#channel", msg, msg)[1])
def test_forecast(): regex = u'(Lappeenranta, (Finland|FI): tomorrow: -?\d+.\d - -?\d+.\d \xb0C \(.*?\), in 2 days: -?\d+.\d - -?\d+.\d \xb0C \(.*?\), in 3 days: -?\d+.\d - -?\d+.\d \xb0C \(.*?\))|(Error: API error.)' check_re( regex, module_openweather.command_forecast(bot, None, "#channel", 'lappeenranta')[1])
def test_forecast(): regex = u'(Lappeenranta, (Finland|FI): tomorrow: -?\d+.\d - -?\d+.\d \xb0C \(.*?\), in 2 days: -?\d+.\d - -?\d+.\d \xb0C \(.*?\), in 3 days: -?\d+.\d - -?\d+.\d \xb0C \(.*?\))|(Error: API error.)' check_re(regex, module_openweather.command_forecast(bot, None, "#channel", 'lappeenranta')[1])
def test_add_feed(): check_re( r'feed added with \d+ items', command_rss(bot, ADMIN_USER, '#pyfibot', 'add http://feeds.feedburner.com/ampparit-kaikki?format=xml')[1] )
def test_areena_tv(): regex = u'Title: (.*?) \[%s - %s plays - %s( - exits in \d+ (weeks|days|hours|minutes))?\]' % (lengh_str_regex, views_str_regex, age_str_regex) msg = "http://areena.yle.fi/1-1999860" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_gfycat_direct_url(botmock): regex = "Title: \(/r/NatureGifs\) 270x480@30fps \d+ views" msg = "https://zippy.gfycat.com/QualifiedSpanishAmericankestrel.webm" check_re(regex, __handle_url(botmock, msg))
def test_areena_live(): regex = u'Title: Yle TV2 - (.*?)( <http://areena.yle.fi/\d-\d+>)? \(LIVE\)' msg = "http://areena.yle.fi/tv/suora/tv2" module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_youtube(botmock): regex = 'Title: (.*?) by (.*?) \[%s - %s views - %s( - age restricted)?\]' % (lengh_str_regex, views_str_regex, age_str_regex) msg = "http://www.youtube.com/watch?v=awsolTK175c" module_urltitle.init(botmock) check_re(regex, __handle_url(botmock, msg))
def test_ebay_cgi(botmock): msg = "http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=121136837564" regex = "Title: .*? \[\d+\.\de - over \d+ available - ships from .*?\ - ENDED]" check_re(regex, __handle_url(botmock, msg))
def test_http_artist(botmock): msg = 'http://open.spotify.com/artist/3MXhtYDNuzQQmLfOKFgPiI' regex = '\[Spotify\] Einojuhani Rautavaara( \(Genre: \S.+\))?' check_re(regex, handle_privmsg(botmock, None, '#channel', msg)[1])
def test_alko(): regex = u'Title: Sandels IV A tölkki \[\d\.\d\de, \d\.\d\dl, \d\.\d\de/l, oluet, 5\.30\%\]' msg = 'http://www.alko.fi/tuotteet/798684/' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_ebay(): msg = 'https://ebay.com/itm/390629338875' regex = u'Title: .*? \[\d+\.\de \(postage \d+\.\de\) - over \d+ available - ships from .*?\]' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_ebay(): msg = 'https://ebay.com/itm/390629338875' regex = 'Title: .*? \[\d+\.\de \(postage \d+\.\de\) - over \d+ available - ships from .*?\]' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_ebay_cgi(): msg = 'http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=121136837564' regex = u'Title: .*? \[\d+\.\de - over \d+ available - ships from .*?\]' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_dx(): regex = 'Title: Wireless Bluetooth Audio Music Receiver Adapter - Black \[\d+\.\d+e - \[\** *\] - \d+ reviews\]' msg = 'http://dx.com/p/wireless-bluetooth-audio-music-receiver-adapter-black-151659' module_urltitle.init(bot) check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_areena_tv(): regex = 'Title: (.*?) \[\d+ min - \d+ plays - %s( - exits in \d+ (weeks|days|hours|minutes))?\]' % (age_str_regex) msg = "http://areena.yle.fi/tv/1999860" module_urltitle.init(bot) assert check_re(regex, module_urltitle.handle_url(bot, None, "#channel", msg, msg)[1])
def test_http_artist(): msg = 'http://open.spotify.com/artist/3MXhtYDNuzQQmLfOKFgPiI' regex = '\[Spotify\] Einojuhani Rautavaara( \(Genre: \S.+\))?' check_re(regex, handle_privmsg(bot, None, '#channel', msg)[1])
def test_posti(): '''11d 1h 45m ago - Item delivered to the recipient. - TAALINTEHDAS 25900''' regex = u'(\d+d\ )?(\d+h\ )?(\d+m )?ago - (.*?) - (.*?) (\d+)' check_re(regex, command_posti(bot, '[email protected]', '#example', 'JJFI')[1])
def test_verkkokauppacom(botmock): msg = "http://www.verkkokauppa.com/fi/product/55124/dfbfn/Coca-Cola-Vanilla-USA-virvoitusjuoma-355-ml" regex = 'Title: Coca-Cola Vanilla USA virvoitusjuoma 355 ml \| \d+,\d+ € \(.*?\)' check_re(regex, __handle_url(botmock, msg))
def test_command_add(): check_re( r'feed added with \d+ items', command_rss(bot, ADMIN_USER, '#pyfibot', 'add ./tests/static/test_rss_init.xml')[1] )
def test_imdb(botmock): regex = 'Title: Wreck-It Ralph \(2012\) - [\d.]{1,}/10 \(%s votes\) - .*' % views_str_regex msg = "http://www.imdb.com/title/tt1772341/" check_re(regex, __handle_url(botmock, msg))