Esempio n. 1
0
    def setUp(self):
        """
        Initial set up
        """
        """Set up test variables."""
        self.app = create_app("test_config")
        # initialize the test client
        self.client = self.app.test_client()
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.test_client = self.app.test_client()
        self.category_url = url_for('api/categories.categorylistresource',
                                    _external=True)
        self.category_name = "soup"
        self.test_username = '******'
        self.test_user_password = '******'
        self.test_email = "*****@*****.**"

        self.user_data = {
            "username": "******",
            "password": "******",
            "email": "*****@*****.**"
        }

        with self.app_context:
            # create all tables
            db.create_all()
Esempio n. 2
0
 def setUp(self):
     self.app = create_app('testing')
     self.client = self.app.test_client()
     self.app.app_context().push()
     with self.app.app_context():
         db.create_all()
     self.user1 = Users(
         username='******', email='*****@*****.**',
         password='******')
     self.user1.save()
     self.user2 = Users(
         username='******', email='*****@*****.**',
         password='******')
     self.user2.save()
     self.project1 = Projects(
         name="User1's Project", description='sample project',
         contract_value='5000',
         percentage_return='22',
         start_date=datetime.date.today(),
         end_date=datetime.date.today()+datetime.timedelta(days=10),
         user_email=self.user1.email)
     self.project1.save()
     self.project2 = Projects(
         name="User2's Project", description='sample project',
         contract_value='3000',
         percentage_return='10',
         start_date=datetime.date.today(),
         end_date=datetime.date.today()+datetime.timedelta(days=10),
         user_email=self.user2.email)
     self.project2.save()
     self.bid = Bids(
         amount='200', date=datetime.date.today(),
         user_email=self.user1.email, project_id=self.project2.id,)
     self.bid.save()
Esempio n. 3
0
def db(app, request):
    # Initialize the testdb database if it hasn't been created yet
    engine = sqlalchemy.create_engine(app.config['SQLALCHEMY_DATABASE_ROOT'] +
                                      'postgres')

    # initialize db
    try:
        with engine.connect() as connection:
            connection.execution_options(isolation_level="AUTOCOMMIT")
            connection.execute("CREATE DATABASE testdb")
    except ProgrammingError:
        pass  # testdb already exists

    _db.app = app
    _db.create_all()

    # yield is not used here,
    # since teardown() is always executed
    # even in case of an exception
    def teardown():
        _db.session.close()
        _db.drop_all()

    request.addfinalizer(teardown)

    return _db
Esempio n. 4
0
def app(user, plan_record):
    app = create_app(test_config)

    with app.app_context():
        db.create_all()

        admin_role = Role(name="admin")
        user_role = Role(name="user")
        db.session.add(admin_role)
        db.session.add(user_role)

        # Admin user
        user.roles = [admin_role, user_role]
        db.session.add(user)

        # Non-admin user
        non_admin = User(first="Example",
                         last="Person",
                         email="*****@*****.**")
        non_admin.roles = [user_role]
        db.session.add(non_admin)

        place = Place(name="Lowell, MA", description="A town")
        db.session.add(place)

        plan = PlanSchema().load(plan_record)
        plan.user = user
        db.session.add(plan)

        db.session.commit()

    return app
Esempio n. 5
0
def create_app():

    app = Flask(__name__)


    app.config['MQTT_KEEPALIVE'] = 5  # set the time interval for sending a ping to the broker to 5 seconds
    app.config['MQTT_TLS_ENABLED'] = False  # set TLS to disabled for testing purposes
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@localhost/eter'



    for bp in blueprints:
        app.register_blueprint(bp)


    db.init_app(app)
    db.create_all(app=app)

    #with app.app_context():
    #    measure = Measure(sensor_id=1, device_id=1, value=30)
    #    db.session.add(measure)
    #    db.session.commit()


    return app
Esempio n. 6
0
def get_test_app():
    app = create_app(CONFIG_FILE_DEV)

    with app.app_context():
        db.drop_all()
        db.create_all()
    return app
Esempio n. 7
0
def adduserpass(username, password):
    """Register a new user with password"""
    db.create_all()
    user = User(username=username, password=password)
    db.session.add(user)
    db.session.commit()
    print('User {0} was registered successfully.'.format(username))
Esempio n. 8
0
def app(user, plan_record):
    app = create_app(
        {
            "TESTING": True,
            "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:",
            "SQLALCHEMY_TRACK_MODIFICATIONS": False,
            "SECRET_KEY": b"my_secret_key",
        }
    )

    with app.app_context():
        db.create_all()

        admin_role = Role(name="admin")
        user_role = Role(name="user")
        db.session.add(admin_role)
        db.session.add(user_role)

        user.roles = [admin_role, user_role]

        db.session.add(user)

        place = Place(name="Lowell, MA", description="A town")
        db.session.add(place)

        plan = PlanSchema().load(plan_record)
        plan.user = user
        db.session.add(plan)

        db.session.commit()

    return app
def create_app(testing=False):
    """Flask Application Factory

    config_override isn't current used 
    """
    # Instantiate flask app
    app = Flask(__name__, instance_relative_config=True)

    # Set configurations
    env = os.environ.get("FLASK_ENV", "development")
    app.config.from_object(_config[env])
    if testing:
        app.config["TESTING"] = True

    # TODO: Add logger

    # Register database
    db.init_app(app)

    with app.app_context():
        db.create_all(bind=["users"])

        if env == "development":
            from api.models import User

            user = User(username="******")
            user.hash_password("debug")
            db.session.add(user)
            user = User(username="******")
            user.hash_password("SelfService2020")
            db.session.add(user)
            db.session.commit()

    # Add CORS headers
    CORS(app)

    # proxy support for Nginx
    app.wsgi_app = ProxyFix(app.wsgi_app)

    # Profile
    # app.wsgi_app = ProfilerMiddleware(app.wsgi_app)

    # Register blueprints for API endpoints
    app.register_blueprint(_main._main)
    app.register_blueprint(_filter._filter)
    app.register_blueprint(_patient_history._patient_history)
    app.register_blueprint(_patient_images._patient_images)
    app.register_blueprint(_users._users)
    app.register_blueprint(_elasticsearch._elasticsearch)

    # Register error handler
    app.register_error_handler(Exception, exception_handler)

    # Shell context
    @app.shell_context_processor
    def make_shell_context():
        return dict(db=db, models=models)

    return app
Esempio n. 10
0
def refresh_db():
    if prompt_bool('Are you sure you want to lose all current data'):
        with app.app_context():
            print('Dropping Tables')
            db.drop_all()
            print('Creating Tables')
            db.create_all()
            print('Refresh Complete')
Esempio n. 11
0
def refresh_db():
    if prompt_bool('Are you sure you want to lose all current data'):
        with app.app_context():
            print('Dropping Tables')
            db.drop_all()
            print('Creating Tables')
            db.create_all()
            print('Refresh Complete')
Esempio n. 12
0
def create_database():
    """Create database tables from sqlalchemy models."""
    try:
        db.create_all()
        print("Created tables successfully.")
    except Exception:
        db.session.rollback()
        print("Failed, make sure your database server is running!")
Esempio n. 13
0
def recreate_db():
    """
    Recreates a local database. You probably should not use this on
    production.
    """
    db.drop_all()
    db.create_all()
    db.session.commit()
Esempio n. 14
0
def migrate():
    """
    A migrate command for creating database tables
    :return:
    """
    with app.app_context():
        db.init_app(app)
        db.create_all()
Esempio n. 15
0
def createdb(testdata=False):
    app = create_app()
    with app.app_context():
        db.drop_all()
        db.create_all()
        if testdata:
            u = User(username='******', password_hash='test')
            db.session.add(u)
            db.session.commit()
Esempio n. 16
0
def recreate_db():
    """
    Recreates a database. This should only be used once
    when there's a new database instance. This shouldn't be
    used when you migrate your database.
    """
    db.drop_all()
    db.create_all()
    db.session.commit()
Esempio n. 17
0
def create_app(config_object):
    app = Flask(__name__)
    app.config.from_object(config_object)
    app.register_blueprint(api_bp, url_prefix='/api/v1')
    jwt = JWTManager(app)
    with app.app_context():
        db.init_app(app)
        db.create_all()
    return app
Esempio n. 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()
     self.client = TestClient(self.app, None, None)
     self.task = sample.apply()
     self.results = self.task.get()
Esempio n. 19
0
def createdb(testdata=False):
    app = create_app()
    with app.app_context():
        db.drop_all()
        db.create_all()
        if testdata:
            u = User(username='******', password_hash='test')
            db.session.add(u)
            db.session.commit()
Esempio n. 20
0
    def setUp(self):
        """
        Set up test application.
        """
        self.app = create_app('testing')
        self.client = self.app.test_client()
        self.client.headers = {'Authorization': getenv('TEST_TOKEN')}
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.drop_all()
        db.create_all()

        self.board1 = Board()
        self.board2 = Board()
        self.conversation1 = Conversation()
        self.conversation2 = Conversation()
        self.deposit1 = Deposit()
        self.deposit2 = Deposit()
        self.estate1 = Estate(address="Random Address 1")
        self.estate2 = Estate(address="Random Address 2")
        self.estate3 = Estate()
        self.headers = {'Authorization': getenv('TEST_TOKEN')}
        self.message1 = Message(sender=1, content='Random Content')
        self.message2 = Message(sender=2, content='Random Content')
        self.message3 = Message()
        self.payment1 = Payment()
        self.payment2 = Payment()
        self.role1 = Role(title='basic')
        self.role2 = Role(title='admin')
        self.role3 = Role(title='super_admin')
        self.role4 = Role()
        self.unit1 = Unit(name="Random Unit 1")
        self.unit2 = Unit(name="Random Unit 2")
        self.unit3 = Unit()
        self.user1 = User(name="First1 Middle1 Last1",
                          phone_number="000 12 3456781",
                          email="*****@*****.**",
                          password=digest('ABC123!@#'))
        self.user2 = User(name="First2 Middle2 Last2",
                          phone_number="000 12 3456782",
                          email="*****@*****.**",
                          password=digest('ABC123!@#'))
        self.user3 = User()
        self.user_new_data1 = {'phone_number': "000 12 3456783"}
        self.user_new_data2 = {'bad_field': "random"}
        self.wallet1 = Wallet()
        self.wallet2 = Wallet()
        self.user1_dict = {
            "name": "First1 Middle1 Last1",
            "phone_number": "000 12 3456781",
            "email": "*****@*****.**",
            "password": "******"
        }
        self.conversation3_dict = {"participants": [1, 2]}
        self.message4_dict = {"content": "New Message."}
        self.board3_dict = {'members': [1, 2]}
Esempio n. 21
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(), "")
Esempio n. 22
0
def setup_clean_db(PRODUCTION_DB=False):

    if PRODUCTION_DB:
        app = create_app(carshare_config.ProductionConfig)
    else:
        app = create_app(carshare_config.DevelopmentConfig)

    with app.app_context():
        db.drop_all()
        db.create_all()
Esempio n. 23
0
def action_create():
    with app.app_context():
        if options.name == 'oauth':
            oauth.init_app(app)
            oauth.create_all()
            print('oauth tables created')
        if options.name == 'api':
            api.init_app(app)
            api.create_all()
            print('api tables created')
Esempio n. 24
0
def app():
    app = create_app({
        "TESTING": True,
        "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:",
        "SQLALCHEMY_TRACK_MODIFICATIONS": False,
    })

    with app.app_context():
        db.create_all()

    return app
Esempio n. 25
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(), '')
Esempio n. 26
0
def test_client():
    app = create_app('testing')

    with app.test_client() as client:
        ctx = app.app_context()
        ctx.push()
        db.drop_all()
        db.create_all()

        yield client
        db.drop_all()
        ctx.pop()
Esempio n. 27
0
def app(user, plan_record):
    app = create_app(test_config)

    with app.app_context():
        db.create_all()

        admin_role = Role(name="admin")
        user_role = Role(name="user")
        db.session.add(admin_role)
        db.session.add(user_role)

        # Admin user
        user.roles = [admin_role, user_role]
        db.session.add(user)

        # Non-admin user
        non_admin = User(first="Example",
                         last="Person",
                         email="*****@*****.**")
        non_admin.roles = [user_role]
        db.session.add(non_admin)

        place = Place(
            slug="lowell",
            name="Lowell, MA",
            state="Massachusetts",
            description="A town",
            districting_problems=[
                DistrictingProblem(
                    number_of_parts=9,
                    name="Town Council",
                    plural_noun="Town Council Districts",
                )
            ],
            units=[
                UnitSet(
                    name="Blocks",
                    unit_type="block",
                    slug="blocks",
                    bounds="[[0, 100], [0, 100]]",
                )
            ],
        )
        db.session.add(place)

        plan = Plan(**PlanSchema().load(plan_record))
        plan.user = user
        db.session.add(plan)

        db.session.commit()

    return app
Esempio n. 28
0
    def setUp(self):
        """Setup function to configure test enviroment."""
        self.app = create_app("Testing")
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.drop_all()
        db.create_all()

        # test client
        self.client = self.app.test_client()

        self.header = {"Authorization": self.generate_token(self.test_payload)}

        # mock user
        self.member = User(email="someonecool.andela.com",
                           name="thecoolest",
                           uuid="-Ksomeid",
                           role="member",
                           country="ke/ug/niger/ny/sa/tz/rw")

        self.admin = User(email="coolAdmin.andela.com",
                          name="thecoolestAdmin",
                          uuid="-KsomeidAdmin",
                          role="admin",
                          country="ke/ug/niger/ny/sa/tz/rw")

        # mock societies
        self.istelle = Society(name="istelle",
                               photo="url/imgae",
                               logo="url/image",
                               color_scheme="#00ff4567")

        self.sparks = Society(name="sparks",
                              photo="url/imgae",
                              logo="url/image",
                              color_scheme="#00ff4567")

        self.phenix = Society(name="phenix",
                              photo="url/imgae",
                              logo="url/image",
                              color_scheme="#00ff4567")
        self.phenix.save()

        # mock points
        self.point = Point(value=2500, name="interview-2017-sep-23rd")

        # mock interview
        self.activity = Activity(
            name="Interview",
            value=50,
            description="members earn 50 points per activity",
            photo="cool/icon/url")
Esempio n. 29
0
def adduser(username):
    """Register a new user."""
    from getpass import getpass
    password = getpass()
    password2 = getpass(prompt='Confirm: ')
    if password != password2:
        import sys
        sys.exit('Error: passwords do not match.')
    db.create_all()
    user = User(username=username, password=password)
    db.session.add(user)
    db.session.commit()
    print('User {0} was registered successfully.'.format(username))
    def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context
        self.client = self.app.test_client()

        self.user_login = {
            'email': '*****@*****.**',
            'password': '******'
        }

        with self.app.app_context():
            db.drop_all()
            db.create_all()
Esempio n. 31
0
def adduser(username):
    """Register a new user."""
    from getpass import getpass
    password = getpass()
    password2 = getpass(prompt='Confirm: ')
    if password != password2:
        import sys
        sys.exit('Error: passwords do not match.')
    db.create_all()
    user = User(username=username, password=password)
    db.session.add(user)
    db.session.commit()
    print('User {0} was registered successfully.'.format(username))
Esempio n. 32
0
def seed():
    """Seed database tables with initial data."""
    if prompt_bool("\n\n\nThis operation will remove all existing data."
                   " Are you sure you want to continue?"):
        try:
            db.drop_all()
            db.create_all()
            db.session.add_all(all_data)
            print("\n\n\nTables seeded successfully.\n\n\n")
        except Exception:
            db.session.rollback()
            print("\n\n\nFailed, make sure your database server is"
                  " running!\n\n\n")
Esempio n. 33
0
def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///mydb.sqlite3'
    app.config['SECRET_KEY'] = '12332432432432'
    db.init_app(app)
    migrate.init_app(app, db)

    from api.routes.main import main
    app.register_blueprint(main)

    from api.models import Symbol
    with app.app_context():
        db.create_all()
    return app
    def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context
        self.client = self.app.test_client()

        self.user_registration_payload = {
            'email': '*****@*****.**',
            'password': '******',
            'password_confirmation': 'password'
        }

        with self.app.app_context():
            db.drop_all()
            db.create_all()
Esempio n. 35
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()
Esempio n. 36
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()
Esempio n. 37
0
 def setUp(self):
     db.create_all()
Esempio n. 38
0
def init_db():
    db.create_all()
Esempio n. 39
0
def createdb():
    app = create_app()
    with app.app_context():
        db.drop_all()
        db.create_all()
Esempio n. 40
0
def create_db():
    """Creates database tables from sqlalchemy models"""
    app = create_app('default')
    with app.app_context():
        db.create_all()
Esempio n. 41
0
def create_db():
    from api import db

    db.create_all()
Esempio n. 42
0
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()
Esempio n. 43
0
from api.decorators import api_wrapper

app.config.from_object(config.options)
app.secret_key = config.SECRET_KEY
app.api = api

if not os.path.exists(app.config["UPLOAD_FOLDER"]):
	os.makedirs(app.config["UPLOAD_FOLDER"])
if not os.path.exists(app.config["PFP_FOLDER"]):
	os.makedirs(app.config["PFP_FOLDER"])

with app.app_context():
	from api.models import db, Config, Users, UserActivity, Teams, Problems, Files, Solves, LoginTokens, TeamInvitations, Tickets, TicketReplies, ProgrammingSubmissions
	db.init_app(app)
	try:
		db.create_all()
	except:
		import traceback
		print traceback.format_exc()
	app.db = db

@app.route("/api")
@api_wrapper
def hello_world():
	return { "success": 1, "message": "The API is apparently functional." }

@app.route("/files/<path:path>")
def get_file(path):
	request_path = os.path.join(app.config["UPLOAD_FOLDER"], path)
	if os.path.exists(request_path):
		return send_file(request_path)