コード例 #1
0
def server_with_auth(username, password):
    def auth(a):
        return a and a.username == username and a.password == password

    s = Server(tdata, all_formats, authorization=auth)
    s.app.testing = True
    return s
コード例 #2
0
def temp_add_server(request):
    """For when we want to mutate the server, and also add datasets to it."""
    data = request.param
    s = Server(copy(data), formats=all_formats, allow_add=True)
    s.app.testing = True
    with s.app.test_client() as c:
        yield c
コード例 #3
0
ファイル: test_server.py プロジェクト: rajsingh7/blaze
def temp_server_with_custom_hook(request):
    """Server with custom compute hook"""
    def custom_compute_hook(expr, kwargs):
        """Custom compute hook that sets the status of the response.
        """
        return expr, kwargs.get('status'), 'ERROR MSG'

    s = Server(tdata, formats=all_formats, compute_hook=custom_compute_hook)
    s.app.testing = True
    with s.app.test_client() as c:
        yield c
コード例 #4
0
ファイル: test_server.py プロジェクト: rajsingh7/blaze
def temp_server_with_excfmt(request):
    """With a custom log exception formatter"""
    data = request.param
    log_format_exc = lambda tb: 'CUSTOM TRACEBACK'
    stream = StringIO()
    s = Server(copy(data),
               formats=all_formats,
               allow_add=True,
               logfile=stream,
               log_exception_formatter=log_format_exc)
    s.app.testing = True
    with s.app.test_client() as client:
        yield (client, stream)
コード例 #5
0
ファイル: test_server.py プロジェクト: rajsingh7/blaze
def add_server():
    s = Server(tdata, all_formats, allow_add=True)
    s.app.testing = True
    return s
コード例 #6
0
ファイル: test_server.py プロジェクト: rajsingh7/blaze
def server():
    s = Server(tdata, all_formats)
    s.app.testing = True
    return s
コード例 #7
0
ファイル: test_server.py プロジェクト: rajsingh7/blaze
def test_server_accepts_non_nonzero_ables():
    Server(DataFrame())
コード例 #8
0
ファイル: test_server.py プロジェクト: rajsingh7/blaze
def iris_server():
    iris = CSV(example('iris.csv'))
    s = Server(iris, all_formats, allow_add=True)
    s.app.testing = True
    with s.app.test_client() as c:
        yield c
コード例 #9
0
def iris_server(request):
    iris = CSV(example('iris.csv'))
    server = Server(iris)
    with server.context():
        yield server.app.test_client()
コード例 #10
0
def empty_server():
    s = Server(formats=all_formats)
    s.app.testing = True
    with s.app.test_client() as c:
        yield c
コード例 #11
0
def temp_server(data=None):
    """For when we want to mutate the server"""
    s = Server(copy(data), formats=all_formats)
    s.app.testing = True
    yield s.app.test_client()
コード例 #12
0
ファイル: test_server.py プロジェクト: mindis/blaze
def iris_server():
    iris = CSV(example('iris.csv'))
    server = Server(iris)
    return server.app.test_client()
コード例 #13
0
ファイル: test_server.py プロジェクト: mindis/blaze
from blaze.server.server import Server, to_tree, from_tree

accounts = DataFrame([['Alice', 100], ['Bob', 200]],
                     columns=['name', 'amount'])

cities = DataFrame([['Alice', 'NYC'], ['Bob', 'LA']], columns=['name', 'city'])

events = DataFrame([[1, datetime(2000, 1, 1, 12, 0, 0)],
                    [2, datetime(2000, 1, 2, 12, 0, 0)]],
                   columns=['value', 'when'])

db = resource('sqlite:///' + example('iris.db'))

data = {'accounts': accounts, 'cities': cities, 'events': events, 'db': db}

server = Server(data)

test = server.app.test_client()


def test_datasets():
    response = test.get('/datashape')
    assert response.data.decode('utf-8') == str(discover(data))


def test_bad_responses():
    assert 'OK' not in test.post('/compute/accounts.json',
                                 data=json.dumps(500),
                                 content_type='application/json').status
    assert 'OK' not in test.post('/compute/non-existent-table.json',
                                 data=json.dumps(0),
コード例 #14
0
ファイル: test_server.py プロジェクト: vitan/blaze
def iris_server():
    iris = CSV(example('iris.csv'))
    server = Server(datasets={'iris': iris})
    return server.app.test_client()
コード例 #15
0
ファイル: test_server.py プロジェクト: vitan/blaze
from flask import json
from datetime import datetime
from pandas import DataFrame

from blaze.utils import example
from blaze import discover, Symbol, by, CSV, compute, join, into
from blaze.server.server import Server, to_tree, from_tree
from blaze.server.index import emit_index

accounts = DataFrame([['Alice', 100], ['Bob', 200]],
                     columns=['name', 'amount'])

cities = DataFrame([['Alice', 'NYC'], ['Bob', 'LA']], columns=['name', 'city'])

server = Server(datasets={'accounts': accounts, 'cities': cities})

test = server.app.test_client()


def test_datasets():
    response = test.get('/datasets.json')
    assert json.loads(response.data) == {
        'accounts': str(discover(accounts)),
        'cities': str(discover(cities))
    }


def test_bad_responses():
    assert 'OK' not in test.post('/compute/accounts.json',
                                 data=json.dumps(500),
コード例 #16
0
ファイル: test_server.py プロジェクト: somu-analyst/blaze
def iris_server(request):
    iris = CSV(example('iris.csv'))
    return Server(iris).app.test_client()