def test_msg(self): ret = 'dr sugary booklet feat phat rule' base.create_json_response('.*amazonaws.*', {'text': ret}) self._proto.privmsg('tester', base.TEST_CHANNEL, '!humanid') self.assertEqual(1, len(self._proto.msgs)) self.assertEqual(self._proto.msgs[0][2], ret)
def test_msg(self): ret = {'definition': 'test response'} base.create_json_response('.*urbandictionary.*', {'list': [ret]}) self._proto.privmsg('tester', base.TEST_CHANNEL, '!ud test') self.assertEqual(1, len(self._proto.msgs)) self.assertEqual(self._proto.msgs[0][2], 'test: test response')
def test_forecast_response(self): base.create_json_response('.*autocomplete.*', {'RESULTS': [{'l': self._newry_me}]}) base.create_json_response('.*api\.wunderground.*', {'forecast': FAKE_FORECAST}) self._proto.privmsg('tester', base.TEST_CHANNEL, '!forecast boston') for i, txt in enumerate(FAKE_FORECAST['txt_forecast']['forecastday']): self.assertEqual(self._proto.msgs[i][0], 'notice') self.assertTrue(self._proto.msgs[i][2].endswith(txt['fcttext']))
def test_forecast_response(self): base.create_json_response(".*autocomplete.*", {"RESULTS": [{"l": self._newry_me}]}) base.create_json_response(".*api\.wunderground.*", {"forecast": FAKE_FORECAST}) self._proto.privmsg("tester", base.TEST_CHANNEL, "!forecast boston") for i, txt in enumerate(FAKE_FORECAST["txt_forecast"]["forecastday"]): self.assertEqual(self._proto.msgs[i][0], "notice") self.assertTrue(self._proto.msgs[i][2].endswith(txt["fcttext"]))
def test_geoip(self): ret = { 'region_code': 'test_region', 'city': 'test_city'} base.create_json_response('.*telize.*', ret) m = self._plugin.geoip(self._ip) self.assertEqual(m, ('test_region', 'test_city'))
def test_query(self): resp = { 'answer': 'yes', 'image': 'http://some.image/url', } base.create_json_response('http://yesno.wtf/api', resp) answer, image = self._plugin.query() self.assertEqual(answer, resp['answer']) self.assertEqual(image, resp['image'])
def test_msg(self): resp = { 'answer': 'yes', 'image': 'http://some.image/url', } base.create_json_response('http://yesno.wtf/api', resp) self._proto.privmsg('tester', base.TEST_CHANNEL, '!yesno') self.assertEqual(1, len(self._proto.msgs)) self.assertEqual( self._proto.msgs[0][2], '%s! (%s)' % (resp['answer'].upper(), resp['image']))
def test_msg(self): base.create_json_response('.*autocomplete.*', {'RESULTS': [{'l': self._newry_me}]}) base.create_json_response('.*api\.wunderground.*', FAKE_WEATHER) self._proto.privmsg('tester', base.TEST_CHANNEL, '!weather boston') self.assertEqual(1, len(self._proto.msgs)) expected = "%s, %s, %s, Humidity: %s, Wind: %s, Feels like: %s" % ( FAKE_WEATHER['current_observation']['display_location']['full'], FAKE_WEATHER['current_observation']['weather'], FAKE_WEATHER['current_observation']['temperature_string'], FAKE_WEATHER['current_observation']['relative_humidity'], FAKE_WEATHER['current_observation']['wind_string'], FAKE_WEATHER['current_observation']['feelslike_string'],) self.assertEqual(self._proto.msgs[0][2], expected)
def test_msg(self): base.create_json_response(".*autocomplete.*", {"RESULTS": [{"l": self._newry_me}]}) base.create_json_response(".*api\.wunderground.*", FAKE_WEATHER) self._proto.privmsg("tester", base.TEST_CHANNEL, "!weather boston") self.assertEqual(1, len(self._proto.msgs)) expected = "%s, %s, %s, Humidity: %s, Wind: %s, Feels like: %s" % ( FAKE_WEATHER["current_observation"]["display_location"]["full"], FAKE_WEATHER["current_observation"]["weather"], FAKE_WEATHER["current_observation"]["temperature_string"], FAKE_WEATHER["current_observation"]["relative_humidity"], FAKE_WEATHER["current_observation"]["wind_string"], FAKE_WEATHER["current_observation"]["feelslike_string"], ) self.assertEqual(self._proto.msgs[0][2], expected)
def test_host(self): class Closure(object): got_valid_request = False cls = Closure() def f(request): ret = {"region_code": "test_region", "city": "test_city"} if request.url.split("/")[-1] == self._ip: cls.got_valid_request = True return (200, {}, json.dumps(ret)) responses.add_callback(responses.GET, url="http://www.telize.com/geoip/%s" % (self._ip,), callback=f) base.create_json_response(".*autocomplete.*", {"RESULTS": [{"l": self._newry_me}]}) base.create_json_response(".*api\.wunderground.*", FAKE_WEATHER) self._proto.privmsg("tester!blah@%s" % (self._ip,), base.TEST_CHANNEL, "!weather") self.assertTrue(cls.got_valid_request)
def test_msg_multistring(self): def f(request): req = request.url.split("=")[1] if req == "newry+me": return (200, {}, json.dumps({"RESULTS": [{"l": self._newry_me}]})) responses.add_callback(responses.GET, url="http://autocomplete.wunderground.com/aq", callback=f) base.create_json_response(".*api\.wunderground.*", FAKE_WEATHER) self._proto.privmsg("tester", base.TEST_CHANNEL, "!weather newry me") self.assertEqual(1, len(self._proto.msgs)) expected = "%s, %s, %s, Humidity: %s, Wind: %s, Feels like: %s" % ( FAKE_WEATHER["current_observation"]["display_location"]["full"], FAKE_WEATHER["current_observation"]["weather"], FAKE_WEATHER["current_observation"]["temperature_string"], FAKE_WEATHER["current_observation"]["relative_humidity"], FAKE_WEATHER["current_observation"]["wind_string"], FAKE_WEATHER["current_observation"]["feelslike_string"], ) self.assertEqual(self._proto.msgs[0][2], expected)
def test_msg(self): status = { 'Status': 'SUCCESS', 'Name': 'Apple Inc', 'Symbol': 'AAPL', 'LastPrice': 124.31, 'Change': -2.83, 'ChangePercent': -2.22589271669026, 'Timestamp': 'Tue Mar 10 13: 00: 42 UTC-04: 00 2015', 'MSDate': 42073.5421527937, 'MarketCap': 724074423880, 'Volume': 5845689, 'ChangeYTD': 110.38, 'ChangePercentYTD': 12.6200398622939, 'High': 127.21, 'Low': 123.8, 'Open': 126.62} base.create_json_response('.*markitondemand.com.*', status) self._proto.privmsg('tester', base.TEST_CHANNEL, '!quote AAPL') self.assertEqual(1, len(self._proto.msgs)) self.assertEqual(self._proto.msgs[0][2], u'Apple Inc [AAPL], 124.31, -2.83(-2.23%)')
def test_msg_multistring(self): def f(request): req = request.url.split('=')[1] if req == 'newry+me': return (200, {}, json.dumps({'RESULTS': [{'l': self._newry_me}]})) responses.add_callback(responses.GET, url='http://autocomplete.wunderground.com/aq', callback=f) base.create_json_response('.*api\.wunderground.*', FAKE_WEATHER) self._proto.privmsg('tester', base.TEST_CHANNEL, '!weather newry me') self.assertEqual(1, len(self._proto.msgs)) expected = "%s, %s, %s, Humidity: %s, Wind: %s, Feels like: %s" % ( FAKE_WEATHER['current_observation']['display_location']['full'], FAKE_WEATHER['current_observation']['weather'], FAKE_WEATHER['current_observation']['temperature_string'], FAKE_WEATHER['current_observation']['relative_humidity'], FAKE_WEATHER['current_observation']['wind_string'], FAKE_WEATHER['current_observation']['feelslike_string'],) self.assertEqual(self._proto.msgs[0][2], expected)
def test_respond(self): msg_count = 0 resp = { 'answer': 'yes', 'image': 'http://some.image/url', } base.create_json_response('http://yesno.wtf/api', resp) self._plugin._chance = 1 self._proto.privmsg('tester', base.TEST_CHANNEL, 'Not a question') self.assertEqual(msg_count, len(self._proto.msgs)) self._proto.privmsg('tester', base.TEST_CHANNEL, 'Is a question? in here') msg_count += 1 self.assertEqual(msg_count, len(self._proto.msgs)) self.assertEqual( self._proto.msgs[msg_count-1][2], '%s! (%s)' % (resp['answer'].upper(), resp['image'])) self._plugin._chance = 0 self._proto.privmsg('tester', base.TEST_CHANNEL, 'All the questions? have no? chance?????') self.assertEqual(msg_count, len(self._proto.msgs))
def test_host(self): class Closure(object): got_valid_request = False cls = Closure() def f(request): ret = { 'region_code': 'test_region', 'city': 'test_city'} if request.url.split('/')[-1] == self._ip: cls.got_valid_request = True return (200, {}, json.dumps(ret)) responses.add_callback(responses.GET, url='http://www.telize.com/geoip/%s' % (self._ip,), callback=f) base.create_json_response('.*autocomplete.*', {'RESULTS': [{'l': self._newry_me}]}) base.create_json_response('.*api\.wunderground.*', FAKE_WEATHER) self._proto.privmsg('tester!blah@%s' % (self._ip,), base.TEST_CHANNEL, '!weather') self.assertTrue(cls.got_valid_request)
def test_fail_msg(self): base.create_json_response('.*urbandictionary.*', {}) self._proto.privmsg('tester', base.TEST_CHANNEL, '!ud blah') self.assertEqual('No idea :(', self._proto.msgs[0][2])
def test_autocomplete_multistring(self): base.create_json_response(".*wunderground.*", {"RESULTS": [{"l": self._newry_me}]}) m = self._plugin.autocomplete("newry me") self.assertEqual(m, self._newry_me)
def test_query(self): ret = {'definition': 'test response'} base.create_json_response('.*urbandictionary.*', {'list': [ret]}) m = self._plugin.query('test') self.assertEqual('test response', m)
def test_geoip(self): ret = {"region_code": "test_region", "city": "test_city"} base.create_json_response(".*telize.*", ret) m = self._plugin.geoip(self._ip) self.assertEqual(m, ("test_region", "test_city"))
def test_query(self): ret = {'text': 'test response'} base.create_json_response('.*amazonaws.*', ret) m = self._plugin.get_some() self.assertEqual('test response', m)
def test_fail_autocomplete(self): base.create_json_response(".*autocomplete.*", {"RESULTS": []}) self._proto.privmsg("tester", base.TEST_CHANNEL, "!weather fail") self.assertEqual(1, len(self._proto.msgs)) self.assertTrue(self._proto.msgs[0][2].startswith("Nice try,"))
def test_autocomplete(self): base.create_json_response('.*wunderground.*', {'RESULTS': [{'l': self._boston}]}) m = self._plugin.autocomplete('boston') self.assertEqual(m, self._boston)
def test_autocomplete_multistring(self): base.create_json_response('.*wunderground.*', {'RESULTS': [{'l': self._newry_me}]}) m = self._plugin.autocomplete('newry me') self.assertEqual(m, self._newry_me)
def test_fail_autocomplete(self): base.create_json_response('.*autocomplete.*', {'RESULTS': []}) self._proto.privmsg('tester', base.TEST_CHANNEL, '!weather fail') self.assertEqual(1, len(self._proto.msgs)) self.assertTrue(self._proto.msgs[0][2].startswith('Nice try,'))
def test_autocomplete(self): base.create_json_response(".*wunderground.*", {"RESULTS": [{"l": self._boston}]}) m = self._plugin.autocomplete("boston") self.assertEqual(m, self._boston)
def test_get_weather(self): base.create_json_response('.*wunderground.*', FAKE_FORECAST) m = self._plugin.get_weather(self._boston) self.assertEqual(m, FAKE_FORECAST)