Esempio n. 1
0
def create_user_test(username, email, password):
    with create_app().app_context():
        # Filters the users by username or email address
        user = db.session.query(User).filter(
            or_(User.username.like(username), User.email.like(email))).first()
        # If the user by exist prints the user exist
        if user:
            print(f'User: {user.username} already exist')
            print(f'------------' + '-' * len(user.password))
            print(f'Id: {user.id}')
            print(f'username: {user.username}')
            print(f'email: {user.email}')
            print(f'password: {user.password}')
            print(f'BMIs: {user.BMIs}')
            print(f'------------' + '-' * len(user.password) + '\n')
            return user
        # Else if the user doesn't exist, it creates a user and and fetches it to be displayed
        else:
            hashed_password = bcrypt.generate_password_hash(password)
            user = User(username=username,
                        email=email,
                        password=hashed_password)
            db.session.add(user)
            db.session.commit()
            user = User.query.filter_by(username=username).first()
            print(f'User {user.username} created')
            print(f'------------' + '-' * len(user.password))
            print(f'Id: {user.id}')
            print(f'username: {user.username}')
            print(f'email: {user.email}')
            print(f'------------' + '-' * len(user.password) + '\n')
            return user
Esempio n. 2
0
def create_calorie_test(username, measurement):
    with create_app().app_context():
        # Filters the users by username or email address
        user = User.query.filter_by(username=username).first()
        # If the user by exist prints the user exist
        if user:
            cal = Calorie(user_id=user.id,
                          measurement=measurement,
                          date=datetime.datetime(2020, 10, 1))
            db.session.add(cal)
            db.session.commit()
            cal = Calorie.query.filter_by(user_id=user.id).all()
            print(f'------------')
            print(f'BMI data for {user.username} created')
            print(f'{user.username} BMIs: {cal}')
            print(f'------------\n')
#!/usr/bin/env python3

import os
import sys
import tempfile
import unittest

_dir_ = os.path.dirname(os.path.realpath(__file__))
_root_ = os.path.join(_dir_, '..', '..', '..')

sys.path.append(_root_)

from Application.app import create_app

app = create_app()
app.config['TESTING'] = True


class TestForumCreate(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
        cls.client = app.test_client()

    @classmethod
    def tearDownClass(cls):
        os.close(cls.db_fd)
        os.unlink(app.config['DATABASE'])

    def test_forum_endpoint(self):
        res = self.client.get("/web/forum")
Esempio n. 4
0
def rest_database():
    with create_app().app_context():
        db.drop_all()
        print(f'database tables are dropped')
        db.create_all()
        print(f'New database tables are created')