Example #1
0
    def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        database.create_all()
        Role.insert_roles()
        self.client = self.app.test_client(use_cookies=True)

        self.bob = User(username='******',
                        password='******',
                        email='*****@*****.**',
                        confirmed=True)
        self.arthur = User(username='******',
                           password='******',
                           email='*****@*****.**',
                           confirmed=True)
        self.clair = User(username='******',
                          password='******',
                          email='*****@*****.**',
                          confirmed=True)
        self.chat_bob_arthur = Chat()
        self.chat_bob_arthur.add_users([self.bob, self.arthur])
        database.session.add_all(
            [self.bob, self.arthur, self.clair, self.chat_bob_arthur])
        database.session.commit()
Example #2
0
    def __init__(self):
        database.create_all()

        if not os.path.exists(SQLALCHEMY_MIGRATE_CONT):
            api.create(SQLALCHEMY_MIGRATE_CONT, "database container")
            api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_CONT)
        else:
            api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_CONT, api.version(SQLALCHEMY_MIGRATE_CONT))
Example #3
0
def create_new_db():
    # Drop old database, then make a new one.
    print('Clearing current database...')
    database.reflect()
    database.drop_all()
    print('Creating new database...')
    database.create_all()
    database.session.commit()
    print("Database created.")

    print("Loading data from JSON...")
Example #4
0
def client():
    file = tempfile.mkstemp()
    db, app.config["SQLALCHEMY_DATABASE_URI"] = file[
        0], "sqlite:///" + file[1] + ".db"
    app.config["TESTING"] = True
    with app.test_client() as client:
        with app.app_context():
            database.init_app(app)
            database.create_all()
            database.session.commit()

        yield client

    os.close(db)
Example #5
0
    def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        database.create_all()
        Role.insert_roles()
        self.bob = User(username='******',
                        password='******',
                        email='*****@*****.**',
                        confirmed=True)
        self.arthur = User(username='******',
                           password='******',
                           email='*****@*****.**',
                           confirmed=True)
        self.clair = User(username='******',
                          password='******',
                          email='*****@*****.**',
                          confirmed=True)
        self.morgana = User(username='******',
                            password='******',
                            email='*****@*****.**',
                            confirmed=True)
        self.ophelia = User(username='******',
                            password='******',
                            email='*****@*****.**',
                            confirmed=True)
        self.artorias = User(username='******',
                             password='******',
                             email='*****@*****.**',
                             confirmed=True)

        self.chat_bob_arthur = Chat()
        self.chat_bob_artorias = Chat()
        self.chat_bob_clair = Chat()
        self.chat_morgana_arthur = Chat()
        self.chat_morgana_bob = Chat(name='chat_morgana_bob_')
        self.chat_bob_arthur.add_users([self.bob, self.arthur])
        self.chat_bob_artorias.add_users([self.bob, self.artorias])
        self.chat_bob_clair.add_users([self.bob, self.clair])
        self.chat_morgana_arthur.add_users([self.arthur, self.morgana])
        self.chat_morgana_bob.add_users([self.bob, self.morgana])
        database.session.add_all([
            self.bob, self.arthur, self.ophelia, self.artorias, self.clair,
            self.morgana, self.chat_bob_arthur, self.chat_bob_artorias,
            self.chat_bob_clair, self.chat_morgana_arthur,
            self.chat_morgana_bob
        ])
        database.session.commit()
Example #6
0
def app(request):
    app = create_app(TestConfig)
    app.app_context().push()

    # def teardown():
    #     app.app_context().pop()

    # request.addfinalizer(teardown)
    # return app
    with app.app_context():
        # alternative pattern to app.app_context().push()
        # all commands indented under 'with' are run in the app context
        database.create_all()
        yield app  # Note that we changed return for yield, see below for why
        database.session.remove(
        )  # looks like db.session.close() would work as well
        database.drop_all()
    def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        database.create_all()
        Role.insert_roles()

        self.bob = User(username='******',
                        password='******',
                        email='*****@*****.**',
                        confirmed=True)
        self.arthur = User(username='******',
                           password='******',
                           email='*****@*****.**',
                           confirmed=True)

        self.chat_bob_arthur = Chat()
        self.chat_bob_arthur.add_users([self.bob, self.arthur])

        self.message1 = Message(text='hi there1',
                                sender=self.arthur,
                                recipient=self.bob,
                                was_read=True,
                                chat=self.chat_bob_arthur)
        self.message2 = Message(text='hi there2',
                                sender=self.arthur,
                                recipient=self.bob,
                                chat=self.chat_bob_arthur)
        self.message3 = Message(text='hi there3',
                                sender=self.arthur,
                                recipient=self.bob,
                                chat=self.chat_bob_arthur)
        self.message4 = Message(text='hi there4',
                                sender=self.bob,
                                recipient=self.arthur,
                                chat=self.chat_bob_arthur)

        database.session.add_all([
            self.bob, self.arthur, self.chat_bob_arthur, self.message1,
            self.message2, self.message3, self.message4
        ])
        database.session.commit()
Example #8
0
def authenticated_client():
    file = tempfile.mkstemp()
    db, app.config["SQLALCHEMY_DATABASE_URI"] = file[
        0], "sqlite:///" + file[1] + ".db"
    app.config["TESTING"] = True
    with app.test_client() as client:
        with app.app_context():
            database.init_app(app)
            database.create_all()
            database.session.commit()
            login.init_app(app)
            test_user = User(username="******", email="*****@*****.**")
            test_user.set_password("admin")
            database.session.add(test_user)
            database.session.commit()
            test_todo_1 = Todo(task="Cooking", owner=test_user)
            test_todo_2 = Todo(task="Playing", owner=test_user)
            database.session.add(test_todo_1)
            database.session.add(test_todo_2)
            database.session.commit()
        yield client

    os.close(db)
Example #9
0
def client():
    file = tempfile.mkstemp()
    db, app.config["SQLALCHEMY_DATABASE_URI"] = file[
        0], "sqlite:///" + file[1] + ".db"
    app.config["TESTING"] = True
    with app.test_client() as client:
        with app.app_context():
            database.init_app(app)
            database.create_all()
            database.session.commit()
            login.init_app(app)
            test_user = User(username="******", email="*****@*****.**")
            test_user.set_password("admin")
            database.session.add(test_user)
            database.session.commit()

            @login.user_loader
            def load_user(user_id):
                return User.query.get(int(user_id))

        yield client

    os.close(db)
def reset():
    database.drop_all()
    database.create_all()
    importData()
Example #11
0
def initdb():
    create_all()
Example #12
0
from datetime import datetime
from app import database as db


class ChatroomMessages(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    chatroomID = db.Column(db.Integer)
    message = db.Column(db.String(10050), nullable=False)
    sentUserID = db.Column(db.Integer, nullable=False)
    timestamp = db.Column(db.DateTime, nullable=False)

    def addChatroomMessage(cchatroomID, cmessage, csentUserID, ctimestamp):
        cr_message = ChatroomMessages(chatroomID=cchatroomID,
                                      message=cmessage,
                                      sentUserID=csentUserID,
                                      timestamp=ctimestamp)
        db.session.add(cr_message)
        db.session.commit()
        return True

    def getChatroomMessages(cid):
        return ChatroomMessages.query.filter_by(chatroomID=cid)


db.create_all()  #Call this before doing any database stuff
Example #13
0
 def setUp(self):
     database.session.close()
     database.drop_all()
     database.create_all()
Example #14
0
from datetime import datetime
from app import database as db


class UserBadges(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    uid = db.Column(db.Integer, nullable=False)
    badgesID = db.Column(db.Integer, nullable=False)

    def addUserBadges(buid, bbadgesID):
        user_badge = UserBadges(uid=buid, badgesID=bbadgesID)
        db.session.add(user_badge)
        db.session.commit()
        return True


db.create_all()
Example #15
0
 def setUp(self):
     app.config["TESTING"]=True
     app.config["CSRF_ENABLED"]=False
     app.config["SQLALCHEMY_DATABASE_URI"]="postgresql://*****:*****@localhost:5432/database"
     self.app=app.test_client()
     database.create_all()
Example #16
0
 def setUp(self):
     db.create_all(app=app)
     create_user('first', 'last', 'email', 'uname', 'pw')
     self.user_id = get_user_with_username('uname').id
     create_project('name', 'desc', self.user_id)
     self.project = Project.query.filter_by(name='name').first()
Example #17
0
import app

app = app.create_app()

from app import database

with app.app_context():
    database.create_all()
Example #18
0
 def setUp(self):
     db.create_all(app=app)
Example #19
0
 def setUp(self):
     self.app = create_app("test")
     self.app_context = self.app.app_context()
     self.app_context.push()
     database.create_all()
     self.client = self.app.test_client(use_cookies=True)
Example #20
0
class ItemForm(Form):
    name = TextField(
        'Item', validators=[DataRequired()]
    )
    category = TextField(
        'Category', validators=[DataRequired()]
    )
    user = SelectField(
        'Owner', validators=[DataRequired()]
    )
    description = TextAreaField(
        'Description', validators=[DataRequired()]
    )
    submit = SubmitField()
    delete = SubmitField()


class UserForm(Form):
    name = TextField(
        'Name', validators=[DataRequired()]
    )
    email = TextField(
        'Email', validators=[DataRequired(), Length(min=6, max=40)]
    )

blueprint.backend = SQLAlchemyBackend(OAuth, database.session,
                                      cache=cache, user=current_user)

database.create_all()
Example #21
0
def create_table():
    from app import database
    database.create_all()
    return redirect(url_for('basic.home'))
Example #22
0
def create_table():
    from app import database

    database.create_all()
    return redirect(url_for("basic.home"))