def create_database():
    class __generated_db(db.Model):
        id = db.Column(db.Integer, primary_key=True)
	
    try:
        __generated_db.query.all()
    except: # Only way we get here is if the table does not exist
        # Initialize the database, and should it fail to exist, create an empty one 
        db.create_all()
        
        cookie = __generated_db()
        db.session.add(cookie)
        db.session.commit()
 def setUp(self):
     db.create_all()
     self.key_text = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA/YCbN2eau8hwpMrq5J4wLIWdmajP9rEhMx4N5DlUqx6IwbikkJabMrZDXoH57Hqy0IdfwOMh102ggwo7dzG99uKCJVnhlpvBo9IfFbgdHeFBwnDXP/qT1XMOM9oiXHlsiqtpC7aycPqJo7XibhGaOTysyTFdhDnsuIsbliFWTrpT52DbNXFkhqWaGozRbD2D7wTVkeWPGoRNqkCn77GvBkz+KI6ghA8ktsrA2HOCnLnllwJvWNlpQZIkZcm7ksPb+sBjVxUIiz4b3z/xBxGceLcJkA//pV+a8GcubCl0GtKhTdncFWpoMat0JIJmFk3NZZeOq+1UIkXQ9gFjZp5FPwIDAQAB'
     self.user = User(firstname="admin", lastname="admin", active=True, login="******")
     db.session.add(self.user)
     db.session.commit()
     self.publicid = PublicId(idtype=PublicId.TWITTER, account="user", user_id=self.user.id, verifyed=True, code="my_code")
     self.publicid_email = PublicId(idtype=PublicId.EMAIL, account="user", user_id=self.user.id, verifyed=True, code="my_code")
     db.session.add(self.publicid)
     db.session.add(self.publicid_email)
     db.session.commit()
     self.key = Key(publicid_id=self.publicid.id, keytype=Key.RSA, publickey=self.key_text)
     db.session.add(self.key)
     db.session.commit()
Exemple #3
0
def deploy():
    db.drop_all()
    db.create_all()
    horror = Genre(
        name="Horror",
        description=
        "Horror Films are unsettling films designed to frighten and panic, cause dread and alarm, and to invoke our hidden worst fears, often in a terrifying, shocking finale, while captivating and entertaining us at the same time in a cathartic experience."
    )
    action = Genre(
        name="Action",
        description=
        "Action film is a genre in which the protagonist or protagonists end up in a series of challenges that typically include violence, extended fighting, physical feats, and frantic chases."
    )
    romantic = Genre(
        name="Romantic",
        description=
        "Romance films or romance movies are romantic love stories recorded in visual media for broadcast in theaters and on TV that focus on passion, emotion, and the affectionate romantic involvement of the main characters and the journey that their genuinely strong, true and pure romantic love takes them through dating, courtship or marriage."
    )
    split = Movie(
        name="Split",
        director="M. Night Shyamalan",
        actors=
        "James McAvoy, Anya Taylor-Joy, Betty Buckley, Haley Lu Richardson",
        description=
        "Split is a 2016 American psychological horror-thriller film written and directed by M. Night Shyamalan and starring James McAvoy, Anya Taylor-Joy, and Betty Buckley. The film follows a man with 23 different personalities who kidnaps and imprisons three teenage girls in an isolated underground facility.",
        genre=horror)
    darkKnight = Movie(
        name="The Dark Knight",
        director=" Christopher Nolan",
        actors=" Christian Bale, Heath Ledger, Aaron Eckhart",
        description=
        "When the menace known as the Joker emerges from his mysterious past, he wreaks havoc and chaos on the people of Gotham, the Dark Knight must accept one of the greatest psychological and physical tests of his ability to fight injustice.",
        genre=action)
    titanic = Movie(
        name="Titanic",
        director="James Cameron",
        actors=" Leonardo DiCaprio, Kate Winslet, Billy Zane",
        description=
        "A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.",
        genre=romantic)
    db.session.add(horror)
    db.session.add(action)
    db.session.add(romantic)
    db.session.add(split)
    db.session.add(darkKnight)
    db.session.add(titanic)
    db.session.commit()
    def setUp(self):
        db.create_all()

        self.server = Server(server_token="my-server-token",
                             server_id='my-server-id',
                             server_name='My Server Name')
        self.user = User(user_name='My name',
                         user_id='name',
                         user_email='*****@*****.**')
        self.access = Access(auth_token='CShw3okdl5hwrI4V',
                             creation_date=dt.datetime.today(),
                             expiration_date=dt.datetime.today() + dt.timedelta(7))

        self.server.users.append(self.user)
        self.user.access.append(self.access)

        db.session.add(self.server)
        db.session.commit()
Exemple #5
0
def initdb(env):
    """Initialize the ID database"""
    # Mock environment
    app.config.from_object(getattr(configs, env))

    # Remove socket connection
    if env in ['staging', 'production']:
        remote_url = get_item('credential', f"sql-{env}").get('remote_url')
        secho(remote_url, fg='green')
        app.config['SQLALCHEMY_DATABASE_URI'] = remote_url

    secho(f"Init the db -- {env}", fg='green')
    secho(app.config['SQLALCHEMY_DATABASE_URI'])
    db.drop_all()
    db.create_all()
    first_user = User(username='******',
                      email='*****@*****.**',
                      email_verified=True,
                      password=generate_password_hash('Chicago'),
                      university='Northwestern University')

    db.session.add(first_user)
    db.session.commit()

    # Install base set of subreddits
    for group, subreddits in BASE_SUBREDDITS.items():
        for subreddit in subreddits: 
            if type(subreddit) is tuple:
                sub = Subreddit(name=subreddit[0],
                                description=subreddit[1], 
                                group=group,
                                admin_id=first_user.id)
            else:
                sub = Subreddit(name=subreddit, 
                          group=group,
                          admin_id=first_user.id)
            db.session.add(sub)
    db.session.commit()
Exemple #6
0
#Instantiate Api object
fluapi = Api(app)

#Setting the location for the sqlite database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///base.db'
#Adding the configurations for the database
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['PROPAGATE_EXCEPTIONS'] = True

#Import necessary classes from base.py
from base import flu_data, db
#Link the app object to the Movies database
db.init_app(app)
app.app_context().push()
#Create the databases
db.create_all()


#Creating a class to create get, post, put & delete methods
class Movies_List(Resource):

    #Instantiating a parser object to hold data from message payload
    parser = reqparse.RequestParser()
    parser.add_argument('director',
                        type=str,
                        required=False,
                        help='Director of the movie')
    parser.add_argument('genre',
                        type=str,
                        required=False,
                        help='Genre of the movie')
Exemple #7
0
        json_dict = dict(
            id = self.id,
            status_update = self.status_update,
            references_json = ref_json,
            comments = [],
            user = dict(
                id = self.user.id,
                first_name = self.user.first_name,
                last_name = self.user.last_name,
                full_name = self.user.full_name,
                profile_image = self.user.profile_image
            ),
            created_on = self.created_at.toordinal(),
            awesome_list = []
        )
        for user in self.awesome_list:
            json_dict['awesome_list'].append({
                'user_id': user.id,
                'first_name': user.first_name,
                'last_name': user.last_name,
                'full_name': user.full_name,
                'profile_image': user.profile_image
            })

        for comment in self.comments:
            json_dict['comments'].append(comment.to_dict())

        return json.dumps(json_dict)

db.create_all()
def test_clean_db(client):
    db.drop_all()
    db.create_all()
Exemple #9
0
def db_init():
    db.create_all()
    logging.info('Init DB')