Пример #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
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
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
def add_server():
    s = Server(tdata, all_formats, allow_add=True)
    s.app.testing = True
    return s
Пример #6
0
def server():
    s = Server(tdata, all_formats)
    s.app.testing = True
    return s
Пример #7
0
def test_server_accepts_non_nonzero_ables():
    Server(DataFrame())
Пример #8
0
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
def iris_server():
    iris = CSV(example('iris.csv'))
    server = Server(iris)
    return server.app.test_client()
Пример #13
0
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
def iris_server():
    iris = CSV(example('iris.csv'))
    server = Server(datasets={'iris': iris})
    return server.app.test_client()
Пример #15
0
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
def iris_server(request):
    iris = CSV(example('iris.csv'))
    return Server(iris).app.test_client()