コード例 #1
0
ファイル: __init__.py プロジェクト: patallen/markdraft.com
    def setUp(self):
        super(BaseTestCase, self).setUp()
        self.app = create_app(config.Testing)
        self.app_context = self.app.app_context()
        self.client = self.app.test_client()
        self.app_context.push()
        self.db = db
        self.db.drop_all()
        self.db.create_all()
        self.user = dict(
            username="******",
            password="******",
            first_name="Test",
            last_name="User",
            _admin=True
        )
        self.document = dict(
            title="This is a Test Title",
            body="Body Body Body, likeasomebody"
        )
        self.tag = {"title": "TAGGY"}

        self.default_user = User.create(self.user)
        self.default_document = Document.create(self.document)
        self.default_document.user = self.default_user
        self.tag = Tag.create(self.tag)
        self.tag.user = self.default_user
        self.default_document.tags.append(self.tag)
        self.db.session.commit()
        self.redis_store = RedisStore(store=FakeStrictRedis, name='test')
        token = jwt.create_token_for_user(self.default_user)
        self.headers = [
            ('Content-Type', 'application/json'),
            ('Authorization', 'Bearer %s' % token)
        ]
コード例 #2
0
    def setUp(self):
        super(BaseTestCase, self).setUp()
        self.app = create_app(config.Testing)
        self.app_context = self.app.app_context()
        self.client = self.app.test_client()
        self.app_context.push()
        self.db = db
        self.db.drop_all()
        self.db.create_all()
        self.user = dict(username="******",
                         password="******",
                         first_name="Test",
                         last_name="User",
                         _admin=True)
        self.document = dict(title="This is a Test Title",
                             body="Body Body Body, likeasomebody")
        self.tag = {"title": "TAGGY"}

        self.default_user = User.create(self.user)
        self.default_document = Document.create(self.document)
        self.default_document.user = self.default_user
        self.tag = Tag.create(self.tag)
        self.tag.user = self.default_user
        self.default_document.tags.append(self.tag)
        self.db.session.commit()
        self.redis_store = RedisStore(store=FakeStrictRedis, name='test')
        token = jwt.create_token_for_user(self.default_user)
        self.headers = [('Content-Type', 'application/json'),
                        ('Authorization', 'Bearer %s' % token)]
コード例 #3
0
def app():
    _app = create_app(TestConfig)
    ctx = _app.test_request_context()
    ctx.push()
    yield _app
    # Code after yield executes on teardown
    ctx.pop()
コード例 #4
0
    def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.drop_all()
        db.create_all()
        user = User(username=self.default_username,
                    password=self.default_password)
        user2 = User(username=self.another_user,
                     password=self.default_password)
        db.session.add_all([user, user2])
        db.session.commit()
        g.user = user

        bucketlist = BucketList(name=self.bucketlist_name, creator_id=user.id)
        bucketlist2 = BucketList(name=self.bucketlist2_name,
                                 creator_id=user2.id)
        bucketlist3 = BucketList(name=self.bucketlist3_name,
                                 creator_id=user.id)
        db.session.add_all([bucketlist, bucketlist2, bucketlist3])
        db.session.commit()

        bucketlist_item = BucketListItem(
            name=self.bucketlist_item_name, bucketlist_id=bucketlist.id
        )
        bucketlist_item2 = BucketListItem(
            name=self.bucketlist_item2_name, bucketlist_id=bucketlist2.id
        )
        bucketlist_item3 = BucketListItem(
            name=self.bucketlist_item3_name, bucketlist_id=bucketlist3.id
        )
        db.session.add_all([bucketlist_item, bucketlist_item2,
                            bucketlist_item3])
        db.session.commit()
        self.client = self.app.test_client()
コード例 #5
0
ファイル: base_test.py プロジェクト: lciamp/formula_api
 def setUp(self):
     self.app = create_app('testing')
     with self.app.app_context():
         db.create_all()
     self.client = self.app.test_client()
     self.app_context = self.app.app_context()
     self.app_context.push()
コード例 #6
0
    def process_deals(self, result):
        """
        Updates deals with klines websockets,
        when price and symbol match existent deal
        """
        if result["k"]["x"]:
            close_price = result["k"]["c"]
            symbol = result["k"]["s"]
            app = create_app()

            # Update Current price
            bot = app.db.bots.find_one_and_update(
                {"pair": symbol},
                {"$set": {
                    "deal.current_price": close_price
                }})

            # Open safety orders
            # When bot = None, when bot doesn't exist (unclosed websocket)
            if (bot and "safety_order_prices" in bot["deal"]
                    and len(bot["deal"]["safety_order_prices"]) > 0):
                for key, value in bot["deal"]["safety_order_prices"]:
                    # Index is the ID of the safety order price that matches safety_orders list
                    if float(value) >= float(close_price):
                        deal = DealUpdates(bot, app)
                        print("Update deal executed")
                        # No need to pass price to update deal
                        # The price already matched market price
                        deal.so_update_deal(key)
コード例 #7
0
ファイル: conftest.py プロジェクト: Sakuten/backend
def client():
    """make a client for testing
        client (class flask.app.Flask): application <Flask 'api.app'>
        test_client (class 'Flask.testing.FlaskClient'):
                        test client <FlaskClient <Flask 'api.app'>>
    """

    # set app config to 'testing'.
    os.environ['FLASK_CONFIGURATION'] = 'testing'
    client = app.create_app()

    json_path = client.config['ID_LIST_FILE']
    id_list = load_id_json_file(json_path)
    admin_cred = next(i for i in id_list if i['authority'] == 'admin')
    admin['secret_id'] = admin_cred['secret_id']
    checker_cred = next(i for i in id_list if i['authority'] == 'checker')
    checker['secret_id'] = checker_cred['secret_id']
    student_cred = next(i for i in id_list if i['kind'] == 'student')
    test_student['secret_id'] = student_cred['secret_id']
    test_creds = (i for i in id_list if i['kind'] == 'visitor')
    for user in [test_user, test_user1, test_user2, test_user3, test_user4]:
        test_cred = next(test_creds)
        user['secret_id'] = test_cred['secret_id']

    with client.app_context():
        app.init_and_generate()

    test_client = client.test_client()

    yield test_client
コード例 #8
0
def test_client():
    flask_app = create_app(config_name='test')
    testing_client = flask_app.test_client()
    ctx = flask_app.app_context()
    ctx.push()
    yield testing_client
    ctx.pop()
コード例 #9
0
ファイル: conftest.py プロジェクト: LePiN/desafio-melhor-rota
def app():
    app = create_app(FORCE_ENV_FOR_DYNACONF="testing")
    with app.app_context():
        db.create_all(app=app)
        populate_db()
        yield app
        db.drop_all(app=app)
コード例 #10
0
ファイル: conftest.py プロジェクト: xuweiwei2011/cmdb-1
def app():
    """Create application for the tests."""
    _app = create_app("tests.settings")
    ctx = _app.test_request_context()
    ctx.push()
    yield _app

    ctx.pop()
コード例 #11
0
ファイル: account.py プロジェクト: carkod/binbot
 def get_symbols(self):
     app = create_app()
     args = {"blacklisted": False}
     project = {"market": 1, "_id": 0}
     query = app.db.correlations.find(args, project)
     symbols_list = list(query.distinct("market"))
     symbols_list.sort()
     return jsonResp({"data": symbols_list}, 200)
コード例 #12
0
    def __init__(self):

        # Buy order
        self.side = EnumDefinitions.order_side[0]
        # Required by API for Limit orders
        self.timeInForce = EnumDefinitions.time_in_force[0]
        # Instance of app for cron jobs
        self.app = create_app()
コード例 #13
0
ファイル: base.py プロジェクト: peterpaints/flights
    def setUp(self):
        """Define test variables and initialize app."""
        self.app = app.create_app(config_obj=settings, TESTING=True)
        self.client = self.app.test_client()

        with self.app.app_context():
            db.session.close()
            db.drop_all()
            db.create_all()
コード例 #14
0
 def setUp(self):
     self.app = create_app('test_config')
     self.ctx = self.app.app_context()
     self.ctx.push()
     db.drop_all()
     db.create_all()
     self.client = TestClient(self.app, None, None)
     self.task = sample.apply()
     self.results = self.task.get()
コード例 #15
0
def app(request):
    app = create_app(__name__)
    ctx = app.app_context()
    ctx.push()

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return app
コード例 #16
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.client = self.app.test_client()
     self.payload1 = json.dumps({
         "email": "*****@*****.**",
         "password": "******"
     })
コード例 #17
0
ファイル: test_api.py プロジェクト: Zabanaa/api-pycon2014
 def setUp(self):
     self.app = create_app("test_config")
     self.ctx = self.app.app_context()
     self.ctx.push()
     db.drop_all()
     db.create_all()
     u = User(username=self.default_username, password=self.default_password)
     db.session.add(u)
     db.session.commit()
     self.client = TestClient(self.app, u.generate_auth_token(), "")
コード例 #18
0
 def setUp(self):
     self.app = create_app('test_config')
     self.ctx = self.app.app_context()
     self.ctx.push()
     db.drop_all()
     db.create_all()
     u = User(username=self.default_username,
              password=self.default_password)
     db.session.add(u)
     db.session.commit()
     self.client = TestClient(self.app, u.generate_auth_token(), '')
コード例 #19
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.drop_all()
     db.create_all()
     user = User(username=self.default_username,
                 password=self.default_password)
     db.session.add(user)
     db.session.commit()
     self.client = self.app.test_client()
コード例 #20
0
ファイル: conftest.py プロジェクト: shaohaojiecoder/cmdb
def app():
    """Create application for the tests."""
    _app = create_app("tests.settings")
    _app.config['SECRET_KEY'] = CMDBTestClient.TEST_APP_SECRET
    _app.test_client_class = CMDBTestClient
    _app.response_class = CMDBTestResponse
    ctx = _app.test_request_context()
    ctx.push()
    yield _app

    ctx.pop()
コード例 #21
0
ファイル: conftest.py プロジェクト: theovoss/ChessApi
def app():
    _app = create_app(TestConfig)
    _app.testing = True
    _app.debug = True

    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()
コード例 #22
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.drop_all()
     db.create_all()
     user = User(username=self.default_username,
                 password=self.default_password)
     db.session.add(user)
     db.session.commit()
     self.client = self.app.test_client()
コード例 #23
0
ファイル: conftest.py プロジェクト: Windact/ml_api
def app(_db_session):
    """ The fixture that create an application in test mode with its own context 
    
    Returns
    -------
    fask application object 
        A flask application object in test mode is yielded
    """

    app = create_app(config_object=TestingConfig(), db_session=_db_session).app
    with app.app_context():
        yield app
コード例 #24
0
ファイル: order_sockets.py プロジェクト: carkod/binbot
    def __init__(self):
        self.key = os.getenv("BINANCE_KEY")
        self.secret = os.getenv("BINANCE_SECRET")
        self.user_datastream_listenkey = os.getenv("USER_DATA_STREAM")
        self.all_orders_url = os.getenv("ALL_ORDERS")
        self.order_url = os.getenv("ORDER")

        # streams
        self.base = os.getenv("WS_BASE")
        self.path = "/stream"
        self.active_ws = None
        self.listenkey = None
        self.app = create_app()
コード例 #25
0
def create_client_mqtt(broker_config):
    from api.app import create_app
    app = create_app()
    db.init_app(app)
    with app.app_context():
        client2mqtt = client_mqtt(broker_config)
        client2mqtt.loop_start()
        while True:
            if client2mqtt._state_msg:
                data_mqtt = client2mqtt._data_payload
                measure_save(data_mqtt)
                client2mqtt._state_msg = False
    return True
コード例 #26
0
    def setUpClass(cls):
        super(APITest, cls).setUpClass()
        app, config = create_app('TESTING')
        cls.DATABASE_URI = config.SQLALCHEMY_DATABASE_URI

        if not database_exists(cls.DATABASE_URI):
            create_database(cls.DATABASE_URI)
        alembic_cfg = Config(os.path.join(config.PROJECT_ROOT, 'alembic.ini'))
        alembic_cfg.set_main_option(
            'script_location', os.path.join(config.PROJECT_ROOT, 'migrations'))
        alembic_cfg.set_main_option('sqlalchemy.url',
                                    config.SQLALCHEMY_DATABASE_URI)

        command.upgrade(alembic_cfg, 'head')
コード例 #27
0
 def __init__(self, interval="30m"):
     self.list_markets = []
     self.markets_streams = None
     self.app = create_app()
     self.interval = interval
     self.last_processed_kline = {}
     # This blacklist is necessary to keep prod and local DB synched
     self.black_list = [
         "TRXBTC", "WPRBTC", "NEOBTC", "BTCUSDT", "ETHBTC", "BNBBTC",
         "ETHBTC", "LTCBTC", "ETHUSDT", "ETCBTC", "BNBETH", "EOSBTC",
         "DASHETH", "FUNBTC", "EOSBTC", "SNGLSBTC", "YOYOBTC", "LINKETH",
         "XVGBTC", "SNTBTC", "DASHBTC", "VIBBTC", "XMRBTC", "WAVESBNB",
         "QSPBTC", "WPRBTC"
     ]
     self.telegram_bot = TelegramBot()
     self.max_request = 300  # Avoid HTTP 411 error by splitting into multiple websockets
コード例 #28
0
    def setUp(self):
        self.app = create_app()

        self.db_fd, self.app.config['DATABASE'] = tempfile.mkstemp()
        self.app.config['TESTING'] = True

        self.ctx = self.app.app_context()
        self.ctx.push()
        db.drop_all()
        db.create_all()
        u = User(username=self.default_username,
                 password=self.default_password)
        db.session.add(u)
        db.session.commit()

        self.client = self.app.test_client()
コード例 #29
0
 def setUp(self):
     self.app = create_app("testing")
     self.client = self.app.test_client()
     self.url_prefix = "api"
     self.api_version = "v1.1"
     self.auth_token = None
     self.user_one = dict({
         "name": "Ahimbisibwe Roland",
         "email": "*****@*****.**",
     })
     self.user_two = dict({
         "name": "Nabaasa Richard",
         "email": "*****@*****.**",
     })
     with self.app.app_context():
         migrate()
コード例 #30
0
ファイル: base.py プロジェクト: Alweezy/stackoverflow-lite
    def setUp(self):
        self.app = create_app("testing")
        self.client = self.app.test_client
        self.question = json.dumps(
            dict({
                "title": "Which instance is this?",
                "user_id": 1
            }))
        self.user = json.dumps(
            dict({
                "username": "******",
                "email": "*****@*****.**",
                "password": "******"
            }))

        # binding app to the current context
        with self.app.app_context():
            db.create_all()
コード例 #31
0
ファイル: manage.py プロジェクト: Bachmann1234/api-pycon2015
def createdb(testdata=False):
    app = create_app()
    with app.app_context():
        db.drop_all()
        db.create_all()
        if testdata:
            classes = ['Algebra', 'Literature', 'Chemistry', 'Spanish',
                       'Game Development', 'History', 'Music', 'Psychology',
                       'Science', 'Photography', 'Drama', 'Business',
                       'Python Programming']
            for name in classes:
                c = Class(name=name)
                db.session.add(c)

            u = User(username='******', password='******')
            db.session.add(u)

            db.session.commit()
コード例 #32
0
    def get_binbot_balance(self):
        """
        More strict balance
        - No locked
        - Minus safety orders
        """
        app = create_app()
        # Get a list of safety orders
        so_list = list(app.db.bots.aggregate(
            [
                {
                    "$addFields": {
                        "so_num": {"$size": {"$objectToArray": "$safety_orders"}},
                    }
                },
                {"$match": {"so_num": {"$ne": 0}}},
                {"$addFields": {"s_os": {"$objectToArray": "$safety_orders"}}},
                {"$unwind": "$safety_orders"},
                {"$group": {"_id": {"so": "$s_os.v.so_size", "pair": "$pair"}}},
            ]
        ))
        data = self.request_data()["balances"]
        df = pd.DataFrame(data)
        df["free"] = pd.to_numeric(df["free"])
        df["asset"] = df["asset"].astype(str)
        df.drop("locked", axis=1, inplace=True)
        df.reset_index(drop=True, inplace=True)
        # Get table with > 0
        balances = df[df["free"] > 0].to_dict("records")

        # Include safety orders
        for b in balances:
            for item in so_list:
                if b["asset"] in item["_id"]["pair"]:
                    decimals = -(Decimal(self.price_filter_by_symbol(item["_id"]["pair"], "tickSize")).as_tuple().exponent)
                    total_so = sum([float(x) if x != "" else 0 for x in item["_id"]["so"]])
                    b["free"] = round_numbers(float(b["free"]) - total_so, decimals)

        # filter out empty
        # Return response
        resp = jsonResp(balances, 200)
        return resp
コード例 #33
0
def createdb(testdata=False):
    app = create_app()
    with app.app_context():
        db.drop_all()
        db.create_all()
        if testdata:
            classes = [
                'Algebra', 'Literature', 'Chemistry', 'Spanish',
                'Game Development', 'History', 'Music', 'Psychology',
                'Science', 'Photography', 'Drama', 'Business',
                'Python Programming'
            ]
            for name in classes:
                c = Class(name=name)
                db.session.add(c)

            u = User(username='******', password='******')
            db.session.add(u)

            db.session.commit()
コード例 #34
0
def app():
    """
    Set up global app for functional tests
    """
    class Response(APIResponse):
        @cached_property
        def json(self):
            return json.loads(self.data)

    class APIClient(FlaskClient):
        def open(self, *args, **kwargs):
            if 'json' in kwargs:
                kwargs['data'] = json.dumps(kwargs.pop('json'))
                kwargs['content_type'] = 'application/json'
            return super(APIClient, self).open(*args, **kwargs)

    _config = Config()
    app = create_app(_config)
    app.response_class = Response
    app.test_client_class = APIClient
    app.testing = True
    return app
コード例 #35
0
def app():
    """ Set up global app for functional testing """
    class Response(APIResponse):
        @cached_property
        def json(self):
            return json.loads(self.data)

    class APIClient(FlaskClient):
        def open(self, *args, **kwargs):
            if 'json' in kwargs:
                kwargs['data'] = json.dumps(kwargs.pop('json'))
                kwargs['content_type'] = 'application/json'
            return super(APIClient, self).open(*args, **kwargs)

    _config = Config()
    app = create_app(_config)
    app.response_class = Response
    app.test_client_class = APIClient
    app.testing = True
    disconnect()  # Disconnets the previous connection with MongoDB
    connect('mockDB', host='mongomock://localhost')  # MongoDB mock connection

    return app
コード例 #36
0
ファイル: manage.py プロジェクト: jacebrowning/coverage-space
import os

from flask_script import Manager, Server

from api.settings import get_config
from api.app import create_app


def find_assets():
    """Yield paths for all static files and templates."""
    for name in ['static', 'templates']:
        directory = os.path.join(app.config['PATH'], name)
        for entry in os.scandir(directory):
            if entry.is_file():
                yield entry.path


config = get_config(os.getenv('FLASK_ENV'))

app = create_app(config)

server = Server(host='0.0.0.0', extra_files=find_assets())

manager = Manager(app)
manager.add_command('run', server)


if __name__ == '__main__':
    manager.run()
コード例 #37
0
ファイル: __init__.py プロジェクト: patallen/markdraft.com
from api.app import create_app, create_redis
import config


app = create_app(config.Development)
redis = create_redis(config.Development)


from api.views import documents, users, tags
from api import errors
コード例 #38
0
    def when_dev():
        _app = app.create_app(settings.DevConfig)

        expect(_app.config['DEBUG']) is True
        expect(_app.config['TESTING']) is False
コード例 #39
0
"""
Contains scripts to manage the application
"""

#!/usr/bin/env python
from flask.ext.script import Manager, prompt_bool, Server
from flask.ext.migrate import Migrate, MigrateCommand
from OpenSSL import SSL

from api.app import create_app
from api.models import User, BucketList, BucketListItem, db

app = create_app('default')
manager = Manager(app)
migrate = Migrate(app, db)

manager.add_command('db', MigrateCommand)
manager.add_command('runserver', Server(ssl_context=(
    '2_nazzyandfamz.com.crt', 'ssl.key')))


@manager.command
def create_db():
    """Creates database tables from sqlalchemy models"""
    app = create_app('default')
    with app.app_context():
        db.create_all()


@manager.command
def drop_db():
コード例 #40
0
    def when_prod():
        _app = app.create_app(settings.ProdConfig)

        expect(_app.config['DEBUG']) is False
        expect(_app.config['TESTING']) is False
コード例 #41
0
    def when_test():
        _app = app.create_app(settings.TestConfig)

        expect(_app.config['DEBUG']) is True
        expect(_app.config['TESTING']) is True
コード例 #42
0
ファイル: manage.py プロジェクト: AlfiyaZi/api-pycon2014
def createdb():
    app = create_app()
    with app.app_context():
        db.drop_all()
        db.create_all()
コード例 #43
0
ファイル: conftest.py プロジェクト: sloria/sir
 def maker(github=None):
     app = create_app(TestConfig)
     # Prevent any inadvertent requests
     app[GITHUB_APP_KEY] = github or BaseMockGitHubClient('id', 'secret')
     return app
コード例 #44
0
ファイル: manage.py プロジェクト: jaredmichaelsmith/grove
from flask_migrate import Migrate, MigrateCommand
from flask_script import Command, Manager, Option, Server, Shell
from flask_script.commands import Clean, ShowUrls

# Project specific modules
from api.app import create_app
from api.database import db
from api.settings import DevConfig, ProdConfig
from api.models import User


CONFIG = ProdConfig if os.environ.get('GROVE_SETTINGS') == 'prod' else DevConfig
HERE = os.path.abspath(os.path.dirname(__file__))
TEST_PATH = os.path.join(HERE, 'tests')

app = create_app(CONFIG)
manager = Manager(app)
migrate = Migrate(app, db)


def _make_context():
    """Return context dict for a shell session so you can access app, db,
    and the User model by default."""
    return {'app': app, 'db': db, 'User': User}


@manager.command
def test():
    """Run the tests."""
    import pytest
    exit_code = pytest.main([TEST_PATH, '--verbose'])
コード例 #45
0
ファイル: wsgi.py プロジェクト: eDeliveryApp/edelivery-api
from api.app import create_app

app = create_app()
コード例 #46
0
ファイル: manage.py プロジェクト: theovoss/ChessApi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from flask_script import Manager, Shell, Server
from flask_migrate import MigrateCommand

from chess.chess import Chess

from api.database import db

from api.app import create_app
from api.settings import ProdConfig, DevConfig

app = None
if os.environ.get("chess_api_ENV") == 'prod':
    app = create_app(ProdConfig)
else:
    app = create_app(DevConfig)

HERE = os.path.abspath(os.path.dirname(__file__))
TEST_PATH = os.path.join(HERE, 'tests')

manager = Manager(app)


def _make_context():
    """Return context dict for a shell session so you can access
    app, db, and the User model by default.
    """
    return {'app': app, 'db': db, 'chess': Chess()}
コード例 #47
0
ファイル: manage.py プロジェクト: punitvanjani/test1
def createdb():
    """Drop all the data from tables and create/rearrange new tables"""
    app = create_app()
    with app.app_context():
        db.drop_all()
        db.create_all()
# Adding default data if data is dropped and created again
#         u1 = User(username='******',       group = 'USER',     password='******')
        u2 = User(username='******',     group = 'ADMIN',    password='******')
        u3 = User(username='******',  group = 'ADMIN',    password='******')
#  
        hub1 = Hub(hub_id=1234, hub_type = 10, description='testinghub',external_url='192.168.0.117',internal_url='10.0.0.2',status=True,activated_at=datetime.today(),last_changed_by='BackendUser',last_changed_on=datetime.today())
# Section Types eg. # Hub Types eg. 10=Switching, 11=TV Remote, 12=Camera, 11=Kitchen, 12=Bedroom, 13=Bathroom etc,
        hub_type1 = HubTypes(hub_type=10,   hub_type_desc='Switching',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        hub_type2 = HubTypes(hub_type=11,   hub_type_desc='TV Remote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        hub_type3 = HubTypes(hub_type=12,   hub_type_desc='Camera',         last_changed_by='BackendUser',    last_changed_on=datetime.today())
# Section Types eg. # Section Types eg. 10=House:Living Room, 11=Kitchen, 12=Bedroom, 13=Bathroom etc,
        sec_type1  = SectionTypes(section_type=10, section_type_desc='Balcony',          last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type2  = SectionTypes(section_type=11, section_type_desc='Bathroom',        last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type3  = SectionTypes(section_type=12, section_type_desc='Bedroom',         last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type4  = SectionTypes(section_type=13, section_type_desc='Cellar',          last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type5  = SectionTypes(section_type=14, section_type_desc='Common Room',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type6  = SectionTypes(section_type=15, section_type_desc='Dining Room',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type7  = SectionTypes(section_type=16, section_type_desc='Drawing Room',    last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type8  = SectionTypes(section_type=17, section_type_desc='Dressing Room',   last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type9  = SectionTypes(section_type=18, section_type_desc='Family Room',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type10 = SectionTypes(section_type=19, section_type_desc='Front Room',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type11 = SectionTypes(section_type=20, section_type_desc='Garden',          last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type12 = SectionTypes(section_type=21, section_type_desc='Guest Room',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type13 = SectionTypes(section_type=22, section_type_desc='Kitchen',         last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type14 = SectionTypes(section_type=23, section_type_desc='Living room',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type15 = SectionTypes(section_type=24, section_type_desc='Lobby',           last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type16 = SectionTypes(section_type=25, section_type_desc='Servant room',    last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type17 = SectionTypes(section_type=26, section_type_desc='Store room',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type18 = SectionTypes(section_type=27, section_type_desc='Terrace',         last_changed_by='BackendUser',    last_changed_on=datetime.today())
        sec_type19 = SectionTypes(section_type=28, section_type_desc='Waiting Room',    last_changed_by='BackendUser',    last_changed_on=datetime.today())

# Node Types eg. 10=Webswitch, 11=TouchPanel, 12=TV, 13=Music, 14=AC
        ep_type1 = EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1000, endpoint_type_desc = 'Switch',        status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type2 = EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1001, endpoint_type_desc = 'Dimmer',        status_min=1, status_max=10,method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type3 = EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1002, endpoint_type_desc = '30A Switch',    status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type4 = EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1003, endpoint_type_desc = 'Curtain',       status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type5 = EndpointTypes(node_type=11, node_type_desc = 'SparshTouchSwitch',    endpoint_type=1100, endpoint_type_desc = 'Switch',        status_min=0, status_max=1, method='touchswitch',   last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type6 = EndpointTypes(node_type=11, node_type_desc = 'SparshTouchSwitch',    endpoint_type=1101, endpoint_type_desc = 'Dimmer',        status_min=1, status_max=10,method='touchswitch',   last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type7 = EndpointTypes(node_type=11, node_type_desc = 'SparshTouchSwitch',    endpoint_type=1102, endpoint_type_desc = '30A Switch',    status_min=0, status_max=1, method='touchswitch',   last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type8 = EndpointTypes(node_type=11, node_type_desc = 'SparshTouchSwitch',    endpoint_type=1103, endpoint_type_desc = 'Curtain',       status_min=0, status_max=1, method='touchswitch',   last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type9 = EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1200, endpoint_type_desc = 'Channel +',     status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type10= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1201, endpoint_type_desc = 'Channel -',     status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type11= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1202, endpoint_type_desc = 'Volume +',      status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type12= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1203, endpoint_type_desc = 'Volume -',      status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type13= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1204, endpoint_type_desc = 'Mute',          status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type14= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1205, endpoint_type_desc = 'Menu',          status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type15= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1206, endpoint_type_desc = 'Ok',            status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type16= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1207, endpoint_type_desc = 'Source',        status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type17= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1208, endpoint_type_desc = 'On/Off',        status_min=2, status_max=2, method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type49= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1299, endpoint_type_desc = 'TV',            status_min=99,status_max=99,method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   node_category='complex')
        ep_type18= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1300, endpoint_type_desc = 'On/Off',        status_min=2, status_max=2, method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type19= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1301, endpoint_type_desc = 'Channel +',     status_min=2, status_max=2, method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type20= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1302, endpoint_type_desc = 'Channel -',     status_min=2, status_max=2, method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type21= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1303, endpoint_type_desc = 'Volume +',      status_min=2, status_max=2, method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type22= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1304, endpoint_type_desc = 'Volume -',      status_min=2, status_max=2, method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type23= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1305, endpoint_type_desc = 'Mute',          status_min=2, status_max=2, method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type24= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1306, endpoint_type_desc = 'Menu',          status_min=2, status_max=2, method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type50= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1399, endpoint_type_desc = 'Settop Box',    status_min=99,status_max=99,method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today(),   node_category='complex')
        ep_type25= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1400, endpoint_type_desc = 'Temp +',        status_min=2, status_max=2, method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type26= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1401, endpoint_type_desc = 'Temp -',        status_min=2, status_max=2, method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type27= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1402, endpoint_type_desc = 'Fan +',         status_min=2, status_max=2, method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type28= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1403, endpoint_type_desc = 'Fan -',         status_min=2, status_max=2, method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type29= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1404, endpoint_type_desc = 'Swing',         status_min=2, status_max=2, method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type30= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1405, endpoint_type_desc = 'Mode',          status_min=2, status_max=2, method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type48= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1406, endpoint_type_desc = 'On/Off',        status_min=2, status_max=2, method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type51= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1499, endpoint_type_desc = 'AC',            status_min=99,status_max=99,method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   node_category='complex')
        ep_type31= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1004, endpoint_type_desc = 'Computer',      status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type32= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1005, endpoint_type_desc = 'Iron',          status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type33= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1006, endpoint_type_desc = 'Refrigerator',  status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type34= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1007, endpoint_type_desc = 'Washing Machine',status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type35= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1008, endpoint_type_desc = 'Printer',       status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type36= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1009, endpoint_type_desc = 'Geyser',        status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type37= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1010, endpoint_type_desc = 'Dressing Table',status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type38= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1011, endpoint_type_desc = 'Microwave',     status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type39= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1012, endpoint_type_desc = 'Tubelight',     status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type40= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1013, endpoint_type_desc = 'Focus Lamp',    status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type41= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1014, endpoint_type_desc = 'Table Lamp',    status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type42= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1015, endpoint_type_desc = 'Outer Light',   status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type43= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1016, endpoint_type_desc = 'CFL',           status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type44= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1017, endpoint_type_desc = 'Socket',        status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type45= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1018, endpoint_type_desc = 'Chandelier',    status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type46= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1019, endpoint_type_desc = 'Music Player',  status_min=0, status_max=1, method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
        ep_type47= EndpointTypes(node_type=10, node_type_desc = 'Webswitch',            endpoint_type=1020, endpoint_type_desc = 'Fan',           status_min=1, status_max=10,method='webswitch',     last_changed_by='BackendUser',    last_changed_on=datetime.today())
#         ep_type48= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1406, endpoint_type_desc = 'On/Off',        status_min=2, status_max=2, method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today())
#         ep_type49= EndpointTypes(node_type=12, node_type_desc = 'TV',                   endpoint_type=1299, endpoint_type_desc = 'TV',            status_min=99,status_max=99,method='tvremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   node_category='complex')
#         ep_type50= EndpointTypes(node_type=13, node_type_desc = 'Settop Box',           endpoint_type=1399, endpoint_type_desc = 'Settop Box',    status_min=99,status_max=99,method='settopbox',     last_changed_by='BackendUser',    last_changed_on=datetime.today(),   node_category='complex')
#         ep_type51= EndpointTypes(node_type=14, node_type_desc = 'AC',                   endpoint_type=1499, endpoint_type_desc = 'AC',            status_min=99,status_max=99,method='acremote',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   node_category='complex')

        dbg_prop = Properties(key='DEBUG',          last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='true')
        ser_prop = Properties(key='ServerAPI',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='http://shubansolutions.com/etct/ws/')
        cph_prop = Properties(key='ContactPh',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='1234567890')
        cad_prop = Properties(key='ContactAd',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='1, street2, area3, city4, pin5')
        cws_prop = Properties(key='ContactWs',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='http://www.etct.in')
        cml_prop = Properties(key='ContactMl',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='*****@*****.**')
        seu_prop = Properties(key='ServerUsr',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='admin')
        sep_prop = Properties(key='ServerPwd',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='et111ct')
        wsc_prop = Properties(key='WbSwtComm',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='/dev/ttyUSB0')
        wsb_prop = Properties(key='WbSwtBaud',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='9600')
        wsf_prop = Properties(key='WbSwtSFrq',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='3')
        stc_prop = Properties(key='StSwtComm',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='/dev/ttyAMA0')
        stb_prop = Properties(key='StSwtBaud',      last_changed_by='BackendUser',    last_changed_on=datetime.today(),   value='19200')
# 
        db.session.add(hub1)
# 
        db.session.add(hub_type1)
        db.session.add(hub_type2)
        db.session.add(hub_type3)
# 
#         db.session.add(u1)
        db.session.add(u2)
        db.session.add(u3)
#
        db.session.add(sec_type1)
        db.session.add(sec_type2)
        db.session.add(sec_type3)
        db.session.add(sec_type4)
        db.session.add(sec_type5)
        db.session.add(sec_type6)
        db.session.add(sec_type7)
        db.session.add(sec_type8)
        db.session.add(sec_type9)
        db.session.add(sec_type10)
        db.session.add(sec_type11)
        db.session.add(sec_type12)
        db.session.add(sec_type13)
        db.session.add(sec_type14)
        db.session.add(sec_type15)
        db.session.add(sec_type16)
        db.session.add(sec_type17)
        db.session.add(sec_type18)
        db.session.add(sec_type19)
#
        db.session.add(ep_type1)
        db.session.add(ep_type2)
        db.session.add(ep_type3)
        db.session.add(ep_type4)
        db.session.add(ep_type5)
        db.session.add(ep_type6)
        db.session.add(ep_type7)
        db.session.add(ep_type8)
        db.session.add(ep_type9)
        db.session.add(ep_type10)
        db.session.add(ep_type11)
        db.session.add(ep_type12)
        db.session.add(ep_type13)
        db.session.add(ep_type14)
        db.session.add(ep_type15)
        db.session.add(ep_type16)
        db.session.add(ep_type17)
        db.session.add(ep_type18)
        db.session.add(ep_type19)
        db.session.add(ep_type20)
        db.session.add(ep_type21)
        db.session.add(ep_type22)
        db.session.add(ep_type23)
        db.session.add(ep_type24)
        db.session.add(ep_type25)
        db.session.add(ep_type26)
        db.session.add(ep_type27)
        db.session.add(ep_type28)
        db.session.add(ep_type29)
        db.session.add(ep_type30)
        db.session.add(ep_type31)
        db.session.add(ep_type32)
        db.session.add(ep_type33)
        db.session.add(ep_type34)
        db.session.add(ep_type35)
        db.session.add(ep_type36)
        db.session.add(ep_type37)
        db.session.add(ep_type38)
        db.session.add(ep_type39)
        db.session.add(ep_type40)
        db.session.add(ep_type41)
        db.session.add(ep_type42)
        db.session.add(ep_type43)
        db.session.add(ep_type44)
        db.session.add(ep_type45)
        db.session.add(ep_type46)
        db.session.add(ep_type47)
        db.session.add(ep_type48)
        db.session.add(ep_type49)
        db.session.add(ep_type50)
        db.session.add(ep_type51)
#
        db.session.add(dbg_prop)
        db.session.add(ser_prop)
        db.session.add(cph_prop)
        db.session.add(cad_prop)
        db.session.add(cws_prop)
        db.session.add(cml_prop)
        db.session.add(seu_prop)
        db.session.add(sep_prop)
        db.session.add(wsc_prop)
        db.session.add(wsb_prop)
        db.session.add(wsf_prop)
        db.session.add(stc_prop)
        db.session.add(stb_prop)
#
        db.session.commit()
コード例 #48
0
def app():
    return create_app(get_config('test'))
コード例 #49
0
def create_db():
    """Creates database tables from sqlalchemy models"""
    app = create_app('default')
    with app.app_context():
        db.create_all()
コード例 #50
0
def drop_db():
    """Drops database tables"""
    if prompt_bool("Are you sure you want to lose all your data?"):
        app = create_app('default')
        with app.app_context():
            db.drop_all()