Example #1
0
def SetupDb():
    try:
        from flask_app import db
        db.create_all()
        return 'ok'
    except Exception as ex:
        return str(ex)
Example #2
0
    def setUp(self):
        self.config = Config()
        self.app = create_app(self.config)
        self.test_client = self.app.test_client()

        with self.app.app_context():
            db.create_all()
Example #3
0
    def setUp(self):
        self.config = Config()
        self.app = create_app(self.config)
        self.test_client = self.app.test_client()

        with self.app.app_context():
            db.create_all()
Example #4
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
     self.client = self.app.test_client()
Example #5
0
 def setUp(self):
     db.create_all()
     test_user = User(username=self.test_username,
                      password=bcrypt.generate_password_hash(
                          self.test_password),
                      type=self.test_type)
     db.session.add(test_user)
     db.session.commit()
 def setUp(self):
     from flask_app import models
     db.create_all()
     db.session.add(models.Client('test_client'))
     db.session.add(models.Product('test_product'))
     db.session.commit()
     self.app = self.create_app()
     self.client = self.app.test_client()
Example #7
0
 def setUp(self):
     app.config.from_object('config')
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     #the basedir lines could be added like the original db
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
     self.app = app.test_client()
     db.create_all()
     pass
Example #8
0
def my_db(my_app):
    #initialise a clean db
    _db_path = 'flask_app/' + db_path
    if os.path.exists(_db_path):
        os.remove(_db_path)

    with my_app.app_context():
        db.create_all()
    return db
def client(app):
    # db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
    app.config["TESTING"] = True

    with app.test_client() as client:
        with app.app_context():
            db.drop_all()
            db.create_all()
            yield client
Example #10
0
def recreate_db():
    try:
        db.reflect()
        db.drop_all()
    except SQLAlchemyError as e:
        raise ValueError(e)

    db.create_all()

    db.session.commit()
	def setUp(self):
		flask_app.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/testing27.db'
		flask_app.app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
		flask_app.app.config['TESTING'] = True
		
		#this line is from the stackoverflow link below
		flask_app.app.config['WTF_CSRF_ENABLED'] = False
		
		self.app = flask_app.app.test_client()
		db.create_all()
Example #12
0
def recreate_db():
    try:
        db.reflect()
        db.drop_all()
    except SQLAlchemyError as e:
        raise ValueError(e)

    db.create_all()

    db.session.commit()
Example #13
0
def main():
    """
    Code from Miguel Grinberg's Flask tutorial
    :return:
    """
    db.create_all()
    if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
        api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
        api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    else:
        api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO,
                            api.version(SQLALCHEMY_MIGRATE_REPO))
Example #14
0
    def setUpClass(cls):
        # start Chrome
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        try:
            """ cls.client = webdriver.Chrome(chrome_options=options)
                 DeprecationWarning: use options instead of chrome_options
                 cls.client = webdriver.Chrome(chrome_options=options)
            """
            cls.client = webdriver.Chrome(options=options)
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # suppress logging to keep unittest output clean
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # create the database and populate with some fake data
            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            # add an administrator user
            admin_role = Role.query.filter_by(name='Administrator').first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # start the Flask server in a thread
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False})
            cls.server_thread.start()

            # give the server a second to ensure it is up
            time.sleep(1)
Example #15
0
def index():
    db.create_all()
    search = False
    tags = request.args.get('tag')
    if tags:
        search = True
    page_num = request.args.get(get_page_parameter(), type=int, default=1)
    post_query = db.session.query(Post).filter(
        True if not search else Post.tags.contains(tags)).order_by(
            Post.date_posted.desc())
    paginated_posts = post_query.paginate(page=page_num, per_page=10)
    pagination = Pagination(page=page_num,
                            total=len(post_query.all()),
                            record_name='posts',
                            search=search,
                            bs_version=4)
    return render_template("index.html",
                           posts=paginated_posts.items,
                           pagination=pagination)
Example #16
0
def create_db():
    db.drop_all()
    db.create_all()
    db.session.commit()

    # Add the admin
    hashed_password = bcrypt.generate_password_hash(PASS_ADMIN).decode('utf-8')
    coordo = Coordinateur(nom="admin",
                          email="*****@*****.**",
                          password=hashed_password)
    db.session.add(coordo)
    db.session.commit()

    # Get the data
    credentials = GOOGLE_APP_CREDS
    client = connect_to_drive(credentials)
    coordo_sheet = client.open("flask-Coordo/Mediation").worksheet(
        "Accueillants")
    liste_accueillants_raw = coordo_sheet.get_all_values()

    # Handle poorly formatted emails
    emails_re = "([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)"
    tel_re = "([0-9][0-9])"
    liste_accueillants_to_add = \
        [Accueillant(
            disponibilite=row[0],
            nom=row[1].title(),
            tel=''.join("; " if i % 15 == 0 else char for i, char in enumerate(
                ".".join(re.findall(tel_re, row[2])), 1)),
            adresse=row[3],
            email="; ".join(re.findall(emails_re, row[4])).lower(),
            next_action=row[5],
            remarques=row[6])
            for i, row in enumerate(liste_accueillants_raw) if i > 1]

    for acc in liste_accueillants_to_add:
        try:
            db.session.add(acc)
            db.session.commit()
        except:
            db.session.close()
Example #17
0
    def setUp(self):
        db.create_all()
        test_user = User(username=self.root_username,
                         password=bcrypt.generate_password_hash(
                             self.root_password),
                         type=self.user_type)
        db.session.add(test_user)
        db.session.commit()

        location_a = Location(lat=25, lon=50)
        location_b = Location(lat=15, lon=20)

        jogg_1 = Jogg(user_id=test_user.id,
                      start_lat=location_a.lat,
                      start_lon=location_a.lon,
                      end_lat=location_b.lat,
                      end_lon=location_b.lon,
                      start_weather='dummy',
                      end_weather='dummy')
        db.session.add(jogg_1)
        db.session.commit()
Example #18
0
def site():
    db.create_all()
    posts = SiteInput.query.all()
    app.logger.info('Processing default request')
    return render_template("index.html", posts=posts)
Example #19
0
def DataBaseInit():
    if os.path.exists('tabero.db'):
        os.remove('tabero.db')
    db.create_all()
Example #20
0
def init():
    db.create_all()
Example #21
0
def index():
    db.create_all()
    posts = Post.query.all()
    return render_template("index.html", posts=posts)
Example #22
0
 def setUp(self):
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
     db.create_all()
Example #23
0
def init_db():
    # db.drop_all(bind=None)
    # db.session.commit()
    db.create_all()
Example #24
0
from flask_app import app, db

from models import *
from db_models import *
from views import *

db.create_all()
def create_db():
    # write in db
    with open(os.path.join(os.getcwd(), 'user_data', 'skills_for_professions',
                           "filtered_skills_for_IT_professions.json"),
              'r', encoding="utf-8") as skills_for_profession:
        json_skills_for_profession = json.load(skills_for_profession)
        for profession_name in json_skills_for_profession.keys():
            if profession_name[-1] == "2":
                profession_name2 = profession_name[:-1]
                profession_name2 = ' '.join(profession_name2.split("+"))
            else:
                profession_name2 = ' '.join(profession_name.split("+"))

            try:
                p = Profession(name=profession_name2)
                db.session.add(p)
                db.session.commit()

            except sqlite3.IntegrityError:
                pass
            except sqlalchemy.exc.IntegrityError:
                pass
            except Exception:
                continue

            print('profession_name', profession_name2)
            # write skills for the special profession in db
            for skill_name in json_skills_for_profession[profession_name]:
                s = Skill(name=skill_name)
                try:
                    if db.session.query(Skill.id).filter_by(name=skill_name).scalar() is not None:
                        print("Found in db")
                        continue
                    db.session.add(s)
                    db.session.commit()
                except sqlite3.IntegrityError:
                    continue
                except sqlalchemy.exc.IntegrityError:
                    continue
                except sqlalchemy.exc.InvalidRequestError:
                    continue
                except Exception:
                    continue

            try:
                db.session.rollback()
                db.session.commit()
                db.create_all()
            except sqlite3.IntegrityError:
                continue
            except sqlalchemy.exc.IntegrityError:
                continue
            except Exception:
                continue

    num_course = 0

    with open(os.path.join(os.getcwd(), 'user_data', "courses_for_all_professions",
                           "IT_courses", "edx_results.json"),
              'r', encoding="utf-8") as courses_for_profession:
        json_courses_for_profession = json.load(courses_for_profession)
        for course_title in json_courses_for_profession.keys():
            # write courses for the special profession in db
            course_data = json_courses_for_profession[course_title]
            try:
                if db.session.query(Course.id).filter_by(course_title=course_title).scalar() is not None:
                    print("Found in db")
                    continue
            except sqlite3.IntegrityError:
                continue
            except sqlalchemy.exc.IntegrityError:
                continue
            except sqlalchemy.exc.InvalidRequestError:
                continue
            except Exception:
                continue

            if isinstance(course_data["image"], dict):
                if "small" in course_data["image"].keys():
                    course_data["image"] = course_data["image"]["small"]
                else:
                    course_data["image"] = course_data["image"]["image_480x270"]
            try:
                course = Course(course_title=course_title,
                                price=course_data["price"],
                                image=course_data["image"],
                                number_of_students=course_data["number_of_students"],
                                course_duration=course_data["course_duration"],
                                short_description=course_data["short_description"],
                                long_description=course_data["long_description"],
                                url=course_data["url"])
                db.session.add(course)
                db.session.commit()

            # for udemy json which does not have image
            except KeyError:
                course = Course(course_title=course_title,
                                price=course_data["price"],
                                image=course_data["image"],
                                number_of_students="",
                                course_duration="",
                                short_description="",
                                long_description="",
                                url=course_data["url"])
                db.session.add(course)
                db.session.commit()

            except sqlite3.IntegrityError:
                continue
            except sqlalchemy.exc.IntegrityError:
                pass
            except (sqlalchemy.exc.InvalidRequestError and sqlalchemy.exc.DataError):
                continue
            except Exception:
                continue

            num_course += 1
            print("num_course", num_course)
            print(course_title)
            try:
                db.session.rollback()
                db.session.commit()
                db.create_all()

            except sqlite3.IntegrityError:
                continue
            except sqlalchemy.exc.IntegrityError:
                continue
            except sqlalchemy.exc.InvalidRequestError:
                continue
            except Exception:
                continue
from flask_app import create_app, db
db.create_all(app=create_app())
Example #27
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'flask_app/db/flask.db')
     self.app = app.test_client()
     db.create_all()
Example #28
0
from flask_app import db, app

db.create_all(app=app)
Example #29
0
 def setUp(self):
     self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
     app.config['TESTING'] = True
     self.app = app.test_client()
     db.create_all()
 def setUp(self):
     db.create_all()
     db.session.add(models.Client('test_client'))
     db.session.add(models.Product('test_product'))
     db.session.commit()
Example #31
0
 def setUp(self):
     db.drop_all()
     db.create_all()
Example #32
0
 def setUp(self):
     self.app = create_app(TestConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
Example #33
0
def create_db():
    db.create_all()

    test_user = User('test', 'default')
    db.session.add(test_user)
    db.session.commit()
Example #34
0
 def create_db_implementation():
     db.create_all()
Example #35
0
 def setUp(self):
     flask_app.app.config[
         'SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/testing22.db'
     flask_app.app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
     flask_app.app.config['TESTING'] = True
     db.create_all()
 def createTables(self):
     """ Create all tables described in DB """
     db.create_all()
     db.session.commit()
Example #37
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()