Ejemplo n.º 1
0
  def setUp(self, *handler_classes):
    """Args:
    handler_classes: RequestHandlers to initialize
    """
    super(HandlerTest, self).setUp()

    self.conn = schemautil.get_db(':memory:')
    for cls in handler_classes:
      cls.init(self.conn, self.ME)

    self.app = server.application()
Ejemplo n.º 2
0
def test_wsgi_application():
    start_response = mock.MagicMock()
    response = server.application({
        'REQUEST_METHOD': 'GET',
        'PATH_INFO': '/b.txt',
        'QUERY_STRING': '',
        }, start_response)

    expected_response = 'This is b.txt'
    eq_([expected_response], response)
    start_response.assert_called_once_with('200 OK', [
        ('Content-Type', 'text/plain'),
        ('Content-Length', str(len(expected_response)))])
Ejemplo n.º 3
0
def test_head_only_requests_summary(mock_request):
    '''Pulling an entire 300GB BAM file for a HEAD request would be bad.'''
    httpfs_url = ('http://localhost:14000/webhdfs/v1/b.txt?'
        'user.name=igv&op=getcontentsummary')
    mock_request.return_value = stubbed_get(httpfs_url)
    start_response = mock.MagicMock()
    response = server.application({
        'REQUEST_METHOD': 'HEAD',
        'PATH_INFO': '/b.txt',
        'QUERY_STRING': '',
        }, start_response)

    mock_request.assert_called_once_with(httpfs_url)
Ejemplo n.º 4
0
def test_wsgi_missing_file_head():
    start_response = mock.MagicMock()
    response = server.application({
        'REQUEST_METHOD': 'HEAD',
        'PATH_INFO': '/c.txt',
        'QUERY_STRING': '',
        }, start_response)

    expected_response = 'File /c.txt does not exist.'
    eq_([expected_response], response)
    start_response.assert_called_once_with('404 Not Found', [
        ('Content-Type', 'text/plain'),
        ('Content-Length', str(len(expected_response)))])
Ejemplo n.º 5
0
def test_wsgi_missing_file_head():
    start_response = mock.MagicMock()
    response = server.application(
        {
            'REQUEST_METHOD': 'HEAD',
            'PATH_INFO': '/c.txt',
            'QUERY_STRING': '',
        }, start_response)

    expected_response = 'File /c.txt does not exist.'
    eq_([expected_response], response)
    start_response.assert_called_once_with(
        '404 Not Found', [('Content-Type', 'text/plain'),
                          ('Content-Length', str(len(expected_response)))])
Ejemplo n.º 6
0
def test_invalid_method(mock_get):
    start_response = mock.MagicMock()
    response = server.application({
        'REQUEST_METHOD': 'PUT',
        'PATH_INFO': '/b.txt',
        'QUERY_STRING': '',
        }, start_response)

    expected_response = 'Method PUT not allowed.'
    eq_([expected_response], response)  # no response for a HEAD request
    start_response.assert_called_once_with('405 Method Not Allowed', [
        ('Content-Type', 'text/plain'),
        ('Content-Length', str(len(expected_response)))])
    assert not mock_get.called
Ejemplo n.º 7
0
def test_wsgi_application():
    start_response = mock.MagicMock()
    response = server.application(
        {
            'REQUEST_METHOD': 'GET',
            'PATH_INFO': '/b.txt',
            'QUERY_STRING': '',
        }, start_response)

    expected_response = 'This is b.txt'
    eq_([expected_response], response)
    start_response.assert_called_once_with(
        '200 OK', [('Content-Type', 'text/plain'),
                   ('Content-Length', str(len(expected_response)))])
Ejemplo n.º 8
0
def test_head_only_requests_summary(mock_request):
    '''Pulling an entire 300GB BAM file for a HEAD request would be bad.'''
    httpfs_url = ('http://localhost:14000/webhdfs/v1/b.txt?'
                  'user.name=igv&op=getcontentsummary')
    mock_request.return_value = stubbed_get(httpfs_url)
    start_response = mock.MagicMock()
    response = server.application(
        {
            'REQUEST_METHOD': 'HEAD',
            'PATH_INFO': '/b.txt',
            'QUERY_STRING': '',
        }, start_response)

    mock_request.assert_called_once_with(httpfs_url)
Ejemplo n.º 9
0
def test_wsgi_range_bytes():
    start_response = mock.MagicMock()
    response = server.application({
        'REQUEST_METHOD': 'GET',
        'PATH_INFO': '/b.txt',
        'QUERY_STRING': '',
        'HTTP_RANGE': 'bytes=5-8'
        }, start_response)

    expected_response = 'is b'
    eq_([expected_response], response)
    start_response.assert_called_once_with('206 Partial Content', [
        ('Content-Type', 'text/plain'),
        ('Content-Length', str(len(expected_response))),
        ('Accept-Ranges', 'bytes'),
        ('Content-Range', 'bytes 5-8/13')])
Ejemplo n.º 10
0
def test_simple_cors_request():
    start_response = mock.MagicMock()
    response = server.application({
        'REQUEST_METHOD': 'GET',
        'PATH_INFO': '/b.txt',
        'QUERY_STRING': 'salt=1234',
        'HTTP_ORIGIN': 'example.com'
        }, start_response)

    expected_response = 'This is b.txt'
    eq_([expected_response], response)
    start_response.assert_called_once_with('200 OK', [
        ('Content-Type', 'text/plain'),
        ('Content-Length', str(len(expected_response))),
        ('Access-Control-Allow-Origin', '*'),
        ('Access-Control-Allow-Headers', 'Range')])
Ejemplo n.º 11
0
def test_invalid_method(mock_get):
    start_response = mock.MagicMock()
    response = server.application(
        {
            'REQUEST_METHOD': 'PUT',
            'PATH_INFO': '/b.txt',
            'QUERY_STRING': '',
        }, start_response)

    expected_response = 'Method PUT not allowed.'
    eq_([expected_response], response)  # no response for a HEAD request
    start_response.assert_called_once_with(
        '405 Method Not Allowed',
        [('Content-Type', 'text/plain'),
         ('Content-Length', str(len(expected_response)))])
    assert not mock_get.called
Ejemplo n.º 12
0
def application(environ, start_response):
    try:
        request = environ['REQUEST_URI'][1:].split('/')[0]
        dir = os.path.join(os.getcwd(), request)
        if os.path.isfile(os.path.join(dir, 'server.py')):
            sys.path.append(dir)
            import server
            ret = server.application(environ, start_response)
            sys.path.pop()
            return ret
        else:
            start_response('404', [('content-type', 'text/plain')])
            return '404'
    except:
        start_response('500', [('content-type', 'text/plain')])
        return traceback.format_exc()
Ejemplo n.º 13
0
def test_wsgi_range_bytes():
    start_response = mock.MagicMock()
    response = server.application(
        {
            'REQUEST_METHOD': 'GET',
            'PATH_INFO': '/b.txt',
            'QUERY_STRING': '',
            'HTTP_RANGE': 'bytes=5-8'
        }, start_response)

    expected_response = 'is b'
    eq_([expected_response], response)
    start_response.assert_called_once_with(
        '206 Partial Content',
        [('Content-Type', 'text/plain'),
         ('Content-Length', str(len(expected_response))),
         ('Accept-Ranges', 'bytes'), ('Content-Range', 'bytes 5-8/13')])
Ejemplo n.º 14
0
def test_simple_cors_request():
    start_response = mock.MagicMock()
    response = server.application(
        {
            'REQUEST_METHOD': 'GET',
            'PATH_INFO': '/b.txt',
            'QUERY_STRING': 'salt=1234',
            'HTTP_ORIGIN': 'example.com'
        }, start_response)

    expected_response = 'This is b.txt'
    eq_([expected_response], response)
    start_response.assert_called_once_with(
        '200 OK', [('Content-Type', 'text/plain'),
                   ('Content-Length', str(len(expected_response))),
                   ('Access-Control-Allow-Origin', '*'),
                   ('Access-Control-Allow-Headers', 'Range')])
Ejemplo n.º 15
0
def test_cors_preflight_request():
    start_response = mock.MagicMock()
    response = server.application({
        'REQUEST_METHOD': 'OPTIONS',
        'PATH_INFO': '/b.txt',
        'QUERY_STRING': 'salt=1234',
        'HTTP_ORIGIN': 'example.com',
        'HTTP_ACCESS_CONTROL_REQUEST_HEADERS': 'range',
        'HTTP_ACCESS_CONTROL_REQUEST_METHOD': 'GET'
        }, start_response)

    expected_response = ''
    eq_([expected_response], response)
    start_response.assert_called_once_with('200 OK', [
        ('Access-Control-Allow-Methods', 'HEAD, GET, OPTIONS'),
        ('Access-Control-Max-Age', '1728000'),
        ('Content-Type', 'text/plain'),
        ('Content-Length', '0'),
        ('Access-Control-Allow-Origin', '*'),
        ('Access-Control-Allow-Headers', 'Range'),
        ])
Ejemplo n.º 16
0
def test_cors_preflight_request():
    start_response = mock.MagicMock()
    response = server.application(
        {
            'REQUEST_METHOD': 'OPTIONS',
            'PATH_INFO': '/b.txt',
            'QUERY_STRING': 'salt=1234',
            'HTTP_ORIGIN': 'example.com',
            'HTTP_ACCESS_CONTROL_REQUEST_HEADERS': 'range',
            'HTTP_ACCESS_CONTROL_REQUEST_METHOD': 'GET'
        }, start_response)

    expected_response = ''
    eq_([expected_response], response)
    start_response.assert_called_once_with('200 OK', [
        ('Access-Control-Allow-Methods', 'HEAD, GET, OPTIONS'),
        ('Access-Control-Max-Age', '1728000'),
        ('Content-Type', 'text/plain'),
        ('Content-Length', '0'),
        ('Access-Control-Allow-Origin', '*'),
        ('Access-Control-Allow-Headers', 'Range'),
    ])
Ejemplo n.º 17
0
 async def get_application(self):
     return server.application(actions=False)