Exemple #1
0
def test_get_db_handler_mongo():
    assert isinstance(db.get_db_handler(), mongo_adapter.Db)
Exemple #2
0
def test_get_db_handler_invalid(monkeypatch):
    monkeypatch.setattr(db, 'DB_NAME', 'invaliddb')
    with pytest.raises(NotImplementedError):
        db.get_db_handler()
flask_jsondash.utils
~~~~~~~~~~~~~~~~~~~~

General utils for handling data within the blueprint.

:copyright: (c) 2016 by Chris Tabor.
:license: MIT, see LICENSE for more details.
"""

from collections import defaultdict, namedtuple

from flask import current_app

from flask_jsondash import db

adapter = db.get_db_handler()
Paginator = namedtuple('Paginator',
                       'count per_page curr_page num_pages next limit skip')

default_config = dict(
    JSONDASH_FILTERUSERS=False,
    JSONDASH_GLOBALDASH=False,
    JSONDASH_GLOBAL_USER='******',
    JSONDASH_PERPAGE=25,
)


def setting(name, default=None):
    """A simplified getter for namespaced flask config values.

    Args:
Exemple #4
0
def test_get_db_handler_invalid(monkeypatch):
    monkeypatch.setattr(db, 'DB_NAME', 'invaliddb')
    with pytest.raises(NotImplementedError):
        db.get_db_handler()
Exemple #5
0
def test_get_db_handler_mongo():
    assert isinstance(db.get_db_handler(), mongo_adapter.Db)
:copyright: (c) 2016 by Chris Tabor.
:license: MIT, see LICENSE for more details.
"""

import os
import json
from datetime import datetime as dt
from random import choice, randrange
from uuid import uuid1

import click
from werkzeug.datastructures import ImmutableMultiDict

from flask_jsondash import db, settings

adapter = db.get_db_handler()


def get_random_group():
    """Return a random namespaced group of charts.

    Returns:
        str: A random chart name.

    Examples:
        >>> get_random_group()
        >>> {'charts': [...], 'dependencies', 'js_url': '...', ...}
    """
    return choice(list(settings.CHARTS_CONFIG.values()))

Exemple #7
0
def adapter():
    return db.get_db_handler()