Ejemplo n.º 1
0
    def tearDownClass(cls) -> None:
        db.session.remove()
        db.drop_all()
        cls.app_context.pop()
        os.remove(os.path.join(config.basedir, 'test.db'))

        logger.info("Ran the tearDown method")
Ejemplo n.º 2
0
def test_database():
    db.create_all()
    yield db  # testing

    # teardown
    db.session.remove()
    db.drop_all()
Ejemplo n.º 3
0
def seed():
    db.drop_all()
    db.create_all()

    jk = Author(name='JK Rowling')
    jr = Author(name='J. R. R. Tolkein')
    db.session.add(jk)
    db.session.add(jr)
    db.session.commit()

    book1 = Book(id=1, name='Harry Potter and the Chamber of Secrets')
    book1.author = jk
    book2 = Book(id=2, name='Harry Potter and the Prisoner of Azkaban')
    book2.author = jk
    book3 = Book(id=3, name='Harry Potter and the Gobblet of Fire')
    book3.author = jk

    book4 = Book(id=4, name='The Fellowship of the Ring')
    book4.author = jr
    book5 = Book(id=5, name='The Two Towers')
    book5.author = jr

    db.session.add(book1)
    db.session.add(book2)
    db.session.add(book3)
    db.session.add(book4)
    db.session.add(book5)

    db.session.commit()
Ejemplo n.º 4
0
 def setUp(self):
     app.config['TESTING'] = True 
     app.config['DEBUG']= False 
     self.app = app.test_client()
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(BASEDIR, TEST_DB)
     db.drop_all()
     db.create_all()
Ejemplo n.º 5
0
def load_data():
    db.drop_all()
    db.create_all()
    db.session.commit()
    load_admin1_codes()
    load_admin2_codes()
    load_geonames()
Ejemplo n.º 6
0
def recreate_db():
    """
    Recreates a local database. Drops and creates a new database
    """
    db.drop_all()
    db.create_all()
    db.session.commit()
Ejemplo n.º 7
0
 def tearDown(self):
     """
     Called after every test
     """
     with self.app.app_context():
         db.session.remove()
         db.drop_all()
def db(app):
    from api import db
    with app.app_context():
        db.create_all()
        yield db
        db.drop_all()
        db.session.commit()
Ejemplo n.º 9
0
    def setUp(self):

        db.drop_all()
        db.create_all()
        resp_register = register_user(self, '*****@*****.**', '123456')
        res = json.loads(resp_register.data.decode())
        resp_login = login_user(self, '*****@*****.**', '123456')
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
def app():
    app = create_app(TestingConfig)
    with app.app_context():
        db.create_all()
        print("create db")
        yield app
        print("delete db")
        db.drop_all()
Ejemplo n.º 12
0
def job():
    print("Start task...")
    start = time.time()
    scrapper = Scrapper()
    db.drop_all()
    db.create_all()
    scrapper.add_countries()
    end = time.time()
    print("Ending Tasks...{}".format(end-start))
Ejemplo n.º 13
0
def database():
    db.create_all()

    yield db
    """
    TESTS RUN HERE
    """

    db.drop_all()
Ejemplo n.º 14
0
    def setUp(self):
        # cria o objeto flask
        self.current_api = create_api('config')
        with self.current_api.app_context():

            # remove todas as tabelas do banco
            db.drop_all()

            # (re)cria o banco de dados
            db.create_all()
Ejemplo n.º 15
0
def db_create():
    app.config.update({'SQLALCHEMY_DATABASE_URI': "sqlite:///:memory:"})
    with app.app_context():
        db.create_all()

    yield db

    with app.app_context():
        db.session.remove()
        db.drop_all()
Ejemplo n.º 16
0
 def setUp(self):
     self.app = app
     self.ctx = self.app.app_context()
     self.ctx.push()
     db.drop_all()
     db.create_all()
     u = User(username=self.default_username)
     u.set_password(self.default_password)
     db.session.add(u)
     db.session.commit()
     self.client = TestClient(self.app, u.generate_auth_token(), '')
Ejemplo n.º 17
0
    def _app(config_class):
        app = create_app(config_class)
        app.test_request_context().push()

        if config_class is TestingConfig:
            # always start with an empty dn
            db.drop_all()
            from api.models.wikientry import WikiEntry

            db.create_all()
        return app
Ejemplo n.º 18
0
def init_db():
    """
    Initialises a local test db and removes it after testing is finished.
    """
    db.drop_all()
    db.create_all()
    User.create_user("username", "password")
    yield db
    db.session.close()
    db.drop_all()
    red.flushall()
Ejemplo n.º 19
0
 def setUp(self):
     self.app = app
     self.ctx = self.app.app_context()
     self.ctx.push()
     db.drop_all()
     db.create_all()
     u = User(username=self.default_username)
     u.set_password(self.default_password)
     db.session.add(u)
     db.session.commit()
     self.client = TestClient(self.app, u.generate_auth_token(), '')
Ejemplo n.º 20
0
def client():
    app = create_app()
    app.config.from_object(config.TestingConfig)

    app.app_context().push()
    db.create_all()
    db.session.commit()

    yield app.test_client()

    db.session.remove()
    db.drop_all()
Ejemplo n.º 21
0
def db(app):
    """
    Creates an app context for the db and closes the session after execution is completed
    :param app:
    :return:
    """
    app.app_context().push()
    _db.init_app(app)
    _db.create_all()

    yield _db
    _db.session.close()
    _db.drop_all()
Ejemplo n.º 22
0
    def setUp(self):
        """Set up test variables."""
        self.app = create_app(config_name="testing")
        self.client = self.app.test_client()
        self.user_data = {
            "email": "*****@*****.**",
            "password": "******"
        }

        with self.app.app_context():
            db.session.close()
            db.drop_all()
            db.create_all()
Ejemplo n.º 23
0
def init_db_with_participants():
    """
    Initialises a local test db and removes it after testing is finished.
    """
    db.drop_all()
    db.create_all()
    User.create_user("username", "password")
    Consent.create_consent("John", "Doe", "Signature")
    Participant.create_participant(1, "Ionut", "Cons", 15, Gender.Jongen.value,
                                   [Ethnicity.Nederlands.value], "", Version.A)
    yield db
    db.session.close()
    db.drop_all()
Ejemplo n.º 24
0
Archivo: test.py Proyecto: ahmb/blogapp
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db')
     self.app = app
     self.ctx = self.app.app_context()
     self.ctx.push()
     db.drop_all()
     db.create_all()
     u = User(username=self.default_username)
     u.set_password(self.default_password)
     db.session.add(u)
     db.session.commit()
     self.client = TestClient(self.app, u.generate_auth_token(), '')
Ejemplo n.º 25
0
    def setUp(self):
        db.drop_all()
        db.create_all()

        self.book1 = Books(
            book_title='Geography',
            book_description = 'Description of geography'
        )
        self.book2 = Books(
            book_title='ECG',
            book_description='Decsription of ECG of the patient'
        )
        db.session.add(self.book1)
        db.session.commit()
Ejemplo n.º 26
0
def make_quiz():
    """
    Populates the database and creates a gender-profession IAT
    """
    db.drop_all()
    populate()
    root = os.path.dirname(os.path.abspath(__file__))
    test_file = os.path.join(root, 'test_files/intervention-hobby-female.json')
    QuizFactory(test_file).create_collection_quiz()
    question_3 = Question.query.filter_by(id=24).first()
    question_5 = Question.query.filter_by(id=26).first()
    yield question_3, question_5
    db.session.close()
    db.drop_all()
Ejemplo n.º 27
0
def init_database():
    """
    fixture that initializes the db to be used in the tests
    :return: db
    """
    db.drop_all()
    db.create_all()
    character = Character(name='Jon Test', place_id=1, king=True, alive=True)
    character2 = Character(name='Perrete Test', place_id=2, king=False, alive=False)
    db.session.add(character)
    db.session.add(character2)
    db.session.commit()
    yield db
    db.drop_all()
Ejemplo n.º 28
0
def create_database():
    # Create the database
    app = create_app()
    with app.app_context():
        db.drop_all()
        db.create_all()
        # iterate over the PEOPLE structure and populate the database
        for character in CHARACTERS:
            p = Character(name=character.get("name"),
                          place_id=character.get("place_id"),
                          king=character.get("king"),
                          alive=character.get("alive"))
            db.session.add(p)
        db.session.commit()
Ejemplo n.º 29
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'

        app.register_blueprint(login_bp, url_prefix='/login')
        app.register_blueprint(person_bp, url_prefix='/person')

        self.app = app.test_client()
        self.valid_credentials = base64.b64encode(
            b'user:d48c55d159fcc95789b5243948d64cb3').decode('utf-8')
        self.api_token = self.login()
        db.drop_all()
        db.create_all()
Ejemplo n.º 30
0
    def setUp(self):

        db.drop_all()
        db.create_all()
        resp_register = register_user(self, '*****@*****.**', '123456')
        res = json.loads(resp_register.data.decode())
        resp_login = login_user(self, '*****@*****.**', '123456')

        books = Books(
            book_title='cardiac',
            book_description='heart problem',
        )

        db.session.add(books)
        db.session.commit()
Ejemplo n.º 31
0
 def run(self):
     db.drop_all()
     db.session.execute(
         "DROP FUNCTION IF EXISTS actor_search_vector_update()")
     db.session.execute(
         "DROP FUNCTION IF EXISTS custom_list_search_vector_update()")
     db.session.execute(
         "DROP FUNCTION IF EXISTS movie_search_vector_update()")
     db.session.execute(
         "DROP FUNCTION IF EXISTS user_search_vector_update()")
     db.session.commit()
     db.configure_mappers()
     db.create_all()
     fetch_genres()
     fetch_all_movies(10)
Ejemplo n.º 32
0
def init_database(test_client):
    # Create the database and the database table
    db.create_all()

    # insert data
    user = User(username='******', password='******')
    token = Token(auth_token='secret_token_1', user=user)

    db.session.add(user)
    db.session.add(token)
    db.session.commit()

    yield db

    db.drop_all()
Ejemplo n.º 33
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="******",
            email="*****@*****.**",
        )
        user.hash_password("chiditheboss")
        db.session.add(user)
        db.session.commit()
        g.user = user

        self.client = self.app.test_client()
Ejemplo n.º 34
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
Ejemplo n.º 35
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Ejemplo n.º 36
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.ctx.pop()
Ejemplo n.º 37
0
def reset_db():
	db.drop_all()
	db.create_all()
Ejemplo n.º 38
0
#!/usr/bin/python
# encoding: utf-8
#
# Simple script to trigger deletion of tables
#

from api import db

if __name__ == '__main__':
    db.drop_all()
Ejemplo n.º 39
0
def clear_dbs():
    db.drop_all()
    db.create_all()