def call_crowd_control(self, input, called=None, rules=None): mock_names = ['kick', 'ban', 'unban', 'reply'] mocks = {} for name in mock_names: mocks[name] = Mock(name=name) config = {'crowdcontrol': rules} if rules else {} bot = namedtuple('Bot', 'config')(config=config) execute_skybot_regex(crowdcontrol, input, bot=bot, **mocks) return mocks
def call_crowd_control(self, input, called=None, rules=None): mock_names = ['kick', 'ban', 'unban', 'reply'] mocks = {} for name in mock_names: mocks[name] = Mock(name=name) config = { 'crowdcontrol': rules } if rules else {} bot = namedtuple('Bot', 'config')(config=config) execute_skybot_regex(crowdcontrol, input, bot=bot, **mocks) return mocks
def test_comment(self, mock_http_get): mock_http_get.return_value = get_fixture_file(self, '9943987.json') expected = u'"Yes, they must have meant kilowatt hours. Was ' \ u'there no editor?" -- oaktowner' url = 'https://news.ycombinator.com/item?id=9943987' actual = execute_skybot_regex(hackernews, url) assert expected == actual
def test_story(self, mock_http_get): mock_http_get.return_value = get_fixture_file(self, '9943431.json') expected = u'Can Desalination Counter the Drought? by cwal37 ' \ u'with 51 points and 94 comments ' \ u'(http://www.newyorker.com/tech/elements/can-' \ u'desalination-counter-the-drought)' url = 'https://news.ycombinator.com/item?id=9943431' actual = execute_skybot_regex(hackernews, url) assert expected == actual
def test_story(self, mock_http_get): mock_http_get.return_value = get_fixture_file_data( self, "9943431.json") expected = (u"Can Desalination Counter the Drought? by cwal37 " u"with 51 points and 94 comments " u"(http://www.newyorker.com/tech/elements/can-" u"desalination-counter-the-drought)") url = "https://news.ycombinator.com/item?id=9943431" actual = execute_skybot_regex(hackernews, url) assert expected == actual
def test_tweet_regex(self, mock_http_get): mock_http_get.return_value = get_fixture_file_data(self, '1014260007771295745.json') expected = u'2018-07-03 21:30:04 \x02jk_rowling\x02: ' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahaha ' \ u'*draws breath* ' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'haha https://t.co/gbionAPK9Z' url = 'https://twitter.com/jk_rowling/status/1014260007771295745' actual = execute_skybot_regex(show_tweet, url, api_key=FAKE_API_KEY) assert expected == actual
def test_tweet_regex(self, mock_http_get): mock_http_get.return_value = get_fixture_file(self, '1014260007771295745.json') expected = u'2018-07-03 21:30:04 \x02jk_rowling\x02: ' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahaha ' \ u'*draws breath* ' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'hahahahahahahahahahahahahahahahahahahahaha' \ u'haha https://t.co/gbionAPK9Z' url = 'https://twitter.com/jk_rowling/status/1014260007771295745' actual = execute_skybot_regex(show_tweet, url, api_key=FAKE_API_KEY) assert expected == actual
def test_comment_encoding(self, mock_http_get): mock_http_get.return_value = get_fixture_file(self, '9943897.json') expected = u'"> All told, it takes about 3460 kilowatts per ' \ u'acre-foot to pump water from Northern California ' \ u'to San Diego; Carlsbad will use about thirty per ' \ u'cent more energy, five thousand kilowatts per ' \ u'acre-foot, to desalinate ocean water and deliver ' \ u'it to households, according to Poseidon\u2019s ' \ u'report to the Department of Water Resources // ' \ u'These units are abominations. Couldn\'t just ' \ u'say 2.8 Watts per liter vs 4.0 Watts per liter? ' \ u'Or even 10.6 and 15.3 Watts per gallon? I\'m ' \ u'not a metric purist, but the only advantage to ' \ u'using imperial units is that they are more ' \ u'familiar to the average American, but when does ' \ u'the average person deal with acre-feet?" ' \ u'-- alwaysdoit' url = 'https://news.ycombinator.com/item?id=9943897' actual = execute_skybot_regex(hackernews, url) assert expected == actual
def test_comment_encoding(self, mock_http_get): mock_http_get.return_value = get_fixture_file_data( self, "9943897.json") expected = (u'"> All told, it takes about 3460 kilowatts per ' u"acre-foot to pump water from Northern California " u"to San Diego; Carlsbad will use about thirty per " u"cent more energy, five thousand kilowatts per " u"acre-foot, to desalinate ocean water and deliver " u"it to households, according to Poseidon\u2019s " u"report to the Department of Water Resources // " u"These units are abominations. Couldn't just " u"say 2.8 Watts per liter vs 4.0 Watts per liter? " u"Or even 10.6 and 15.3 Watts per gallon? I'm " u"not a metric purist, but the only advantage to " u"using imperial units is that they are more " u"familiar to the average American, but when does " u'the average person deal with acre-feet?" ' u"-- alwaysdoit") url = "https://news.ycombinator.com/item?id=9943897" actual = execute_skybot_regex(hackernews, url) assert expected == actual