예제 #1
0
파일: tests.py 프로젝트: AHAPX/websocket
 def test_server(self):
     server = WebSocketServer()
     # test run
     with patch("asyncio.async") as mock, patch(
         "asyncio.base_events.BaseEventLoop.run_until_complete"
     ) as mock1, patch("asyncio.base_events.BaseEventLoop.run_forever") as mock2:
         run(MagicMock, MagicMock, "localhost", 999, "localhost", 6379, 0, "ws-channel")
         mock.assert_called_once()
         mock1.assert_called_once()
         mock2.assert_called_once()
     # test receiver
     client = Client(MockSocket(True))
     server.receiver(client, "msg")
     self.assertEqual(client.name, "unknown")
     server.receiver(client, '{"message": "msg", "tags": ["tag1", "tag2"]}')
     server.receiver(client, "msg")
     self.assertEqual(client.name, "tag1, tag2")
예제 #2
0
import urllib
from contextlib import closing
from lxml.etree import parse as parse_xml


CURRENT_URL = 'http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query={0}'


@Api.register('weather')
class Weather(Api):


    @Api.expose
    def get_temperature(self, location):

        print
        print location
        print

        current_url = CURRENT_URL.format(location)
        with closing(urllib.urlopen(current_url)) as file_handle:
            current_data = parse_xml(file_handle)

        return {'temperature': current_data.find('temp_c').text, 'location': location}



if __name__ == '__main__':
    run(ApiWebSocket)
예제 #3
0
def main():
    run(8000, False)