예제 #1
0
def get_user_id_from_hatohol_server(session_id):
    server = hatoholserver.get_address()
    port = hatoholserver.get_port()
    path = '/user/me'
    url = 'http://%s:%d%s' % (server, port, path)
    hdrs = {hatohol_def.FACE_REST_SESSION_ID_HEADER_NAME: session_id}
    req = urllib2.Request(url, headers=hdrs)
    response = urllib2.urlopen(req)
    body = response.read()    
    user_info = json.loads(body)
    user_id = user_info['users'][0]['userId']
    return user_id
예제 #2
0
def get_user_id_from_hatohol_server(session_id):
    server = hatoholserver.get_address()
    port = hatoholserver.get_port()
    path = '/user/me'
    url = 'http://%s:%d%s' % (server, port, path)
    hdrs = {hatohol_def.FACE_REST_SESSION_ID_HEADER_NAME: session_id}
    req = urllib2.Request(url, headers=hdrs)
    response = urllib2.urlopen(req)
    body = response.read()    
    user_info = json.loads(body)
    user_id = user_info['users'][0]['userId']
    return user_id
예제 #3
0
def get_user_id_from_hatohol_server(request):
    if hatoholserver.SESSION_NAME_META not in request.META:
        raise NoHatoholSession
    session_id = request.META[hatoholserver.SESSION_NAME_META]
    server = hatoholserver.get_address()
    port = hatoholserver.get_port()
    path = '/user/me'
    url = 'http://%s:%d%s' % (server, port, path)
    hdrs = {hatohol_def.FACE_REST_SESSION_ID_HEADER_NAME: session_id}
    req = urllib2.Request(url, headers=hdrs)
    response = urllib2.urlopen(req)
    body = response.read()
    user_info = json.loads(body)
    user_id = user_info['users'][0]['userId']
    if user_id is None:
        raise NoHatoholUser
    return user_id
예제 #4
0
 def run(self):
     addr = hatoholserver.get_address()
     port = hatoholserver.get_port()
     self._server = HTTPServer((addr, port), self._emulation_handler)
     self._setup_done_evt.set()
     self._server.serve_forever()
예제 #5
0
 def test_get_address_with_env(self):
     os.environ[hatoholserver.SERVER_PORT_ENV_NAME] = '12345'
     hatoholserver._setup()  # Update the internal information
     addr = self.assertEqual(hatoholserver.get_port(), 12345)
예제 #6
0
 def test_get_default_port(self):
     if os.getenv(hatoholserver.SERVER_PORT_ENV_NAME):
         del os.environ[hatoholserver.SERVER_PORT_ENV_NAME]
     hatoholserver._setup()  # Update the internal information
     addr = self.assertEqual(hatoholserver.get_port(),
                             hatoholserver.DEFAULT_SERVER_PORT)
 def run(self):
     addr = hatoholserver.get_address()
     port = hatoholserver.get_port()
     self._server = HTTPServer((addr, port), self._emulation_handler)
     self._setup_done_evt.set()
     self._server.serve_forever()
예제 #8
0
 def test_get_address_with_env(self):
     os.environ[hatoholserver.SERVER_PORT_ENV_NAME] = '12345'
     hatoholserver._setup() # Update the internal information
     addr = self.assertEqual(hatoholserver.get_port(), 12345)
예제 #9
0
 def test_get_default_port(self):
     if os.getenv(hatoholserver.SERVER_PORT_ENV_NAME):
         del os.environ[hatoholserver.SERVER_PORT_ENV_NAME]
     hatoholserver._setup() # Update the internal information
     addr = self.assertEqual(hatoholserver.get_port(),
                             hatoholserver.DEFAULT_SERVER_PORT)