def setUp(self) -> None:
        print("SET UP")
        with app.app_context():
            example = User()
            example.firstname = 'Admin'
            example.lastname = 'Admin'
            example.email = '*****@*****.**'
            example.dateofbirth = datetime.datetime(2020, 10, 5)
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)

            example2 = User()
            example2.firstname = 'Admin'
            example2.lastname = 'Admin'
            example2.email = '*****@*****.**'
            example2.dateofbirth = datetime.datetime(2020, 10, 5)
            example2.is_admin = True
            example2.set_password('admin')
            db.session.add(example2)

            db.session.commit()

        payload = {'email': '*****@*****.**', 'password': '******'}

        form = LoginForm(data=payload)

        self.client.post('/users/login', data=form.data, follow_redirects=True)
Example #2
0
    def test_getuser(self):
        global _app
        if _app is None:
            tested_app = create_app(debug=True)
            _app = tested_app
        else:
            tested_app = _app
        restart_db_tables(db, tested_app)

        with tested_app.test_client() as client:
            with client.session_transaction() as session:
                user_base = User.query.first()
                # push in the users_table 3 users
                user_a = User()
                user_a.email = '*****@*****.**'
                user_a.set_password('test')

                user_b = User()
                user_b.email = '*****@*****.**'
                user_b.set_password('test')

                user_c = User()
                user_c.email = '*****@*****.**'
                user_c.set_password('test')

                db.session.add(user_a)
                db.session.add(user_b)
                db.session.add(user_c)
                db.session.commit()
                res = get_users()
        correct = [user_base, user_a, user_b, user_c]
        print(res)
        print(correct)
        self.assertEqual(res, correct)
Example #3
0
def _init_database(db):
    '''
    Initializes the database for testing.
    '''
    example1 = User()
    example1.username = '******'
    example1.firstname = 'First1'
    example1.lastname = 'Last1'
    example1.email = '*****@*****.**'
    example1.dateofbirth = datetime.datetime(2020, 10, 5)
    example1.is_admin = False
    example1.set_password('test1123')
    db.session.add(example1)

    example2 = User()
    example2.username = '******'
    example2.firstname = 'First2'
    example2.lastname = 'Last2'
    example2.email = '*****@*****.**'
    example2.dateofbirth = datetime.datetime(2020, 10, 5)
    example2.is_admin = False
    example2.set_password('test2123')
    db.session.add(example2)

    example3 = User()
    example3.username = '******'
    example3.firstname = 'First3'
    example3.lastname = 'Last3'
    example3.email = '*****@*****.**'
    example3.dateofbirth = datetime.datetime(2020, 10, 5)
    example3.is_admin = False
    example3.set_password('test3123')
    db.session.add(example3)

    db.session.commit()
Example #4
0
    def setUp(self) -> None:
        with app.app_context():

            # Create an user with no stories
            q = db.session.query(User).filter(User.email == '*****@*****.**')
            user = q.first()
            if user is None:
                example = User()
                example.firstname = 'Admin'
                example.lastname = 'Admin'
                example.email = '*****@*****.**'
                example.dateofbirth = datetime.datetime(2020, 10, 5)
                example.is_admin = True
                example.set_password('admin')
                db.session.add(example)
                db.session.commit()

            # Create another user
            q = db.session.query(User).filter(User.email == '*****@*****.**')
            user = q.first()
            if user is None:
                example = User()
                example.firstname = 'Admin2'
                example.lastname = 'Admin2'
                example.email = '*****@*****.**'
                example.dateofbirth = datetime.datetime(2020, 10, 5)
                example.is_admin = True
                example.set_password('admin')
                db.session.add(example)
                db.session.commit()

            # Create a not recent story by Admin2
            example = Story()
            example.text = 'This is a story about the end of the world'
            example.date = datetime.datetime.strptime('2012-12-12', '%Y-%m-%d')
            example.author_id = 2
            example.figures = 'story#world'
            example.is_draft = False
            db.session.add(example)
            db.session.commit()

            # Create a recent story saved as draft by Admin2
            example = Story()
            example.text = 'This story is just a draft'
            example.date = datetime.datetime.now()
            example.author_id = 2
            example.figures = 'story#draft'
            example.is_draft = True
            db.session.add(example)
            db.session.commit()

            # Create a recent story by Admin
            example = Story()
            example.text = 'Just another story'
            example.date = datetime.datetime.now()
            example.author_id = 1
            example.figures = 'dice#example'
            example.is_draft = False
            db.session.add(example)
            db.session.commit()
Example #5
0
    def test_get_followed_list(self):
        global _app
        if _app is None:
            tested_app = create_app(debug=True)
            _app = tested_app
        else:
            tested_app = _app
        restart_db_tables(db, tested_app)

        with tested_app.test_client() as client:
            with client.session_transaction() as session:
                # push in the users_table 3 users
                user_a = User()
                user_a.email = '*****@*****.**'
                user_a.set_password('test')

                user_b = User()
                user_b.email = '*****@*****.**'
                user_b.set_password('test')

                user_c = User()
                user_c.email = '*****@*****.**'
                user_c.set_password('test')

                user_d = User()
                user_d.email = '*****@*****.**'
                user_d.set_password('test')

                db.session.add(user_a)
                db.session.add(user_b)
                db.session.add(user_c)
                db.session.add(user_d)
                db.session.commit()

                # Get users ID
                user_a_id = User.query.filter_by(
                    email=user_a.email).first().get_id()
                user_b_id = User.query.filter_by(
                    email=user_b.email).first().get_id()
                user_c_id = User.query.filter_by(
                    email=user_c.email).first().get_id()
                user_d_id = User.query.filter_by(
                    email=user_d.email).first().get_id()

            with client.session_transaction() as session:
                follow_ab = _create_follow(user_a_id, user_b_id)
                follow_ac = _create_follow(user_a_id, user_c_id)
                follow_ad = _create_follow(user_a_id, user_d_id)
                follow_bc = _create_follow(user_b_id, user_c_id)

                db.session.add(follow_ab)
                db.session.add(follow_ac)
                db.session.add(follow_ad)
                db.session.add(follow_bc)
                db.session.commit()

                res = get_followed_list(user_a_id)
                correct = [user_b_id, user_c_id, user_d_id]
                self.assertEqual(res, correct)
    def setUp(self) -> None:
        with app.app_context():
            # user for login
            example = User()
            example.firstname = 'Admin'
            example.lastname = 'Admin'
            example.email = '*****@*****.**'
            example.dateofbirth = datetime.datetime(2020, 10, 5)
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)

            # dummy user
            dummy_user = User()
            dummy_user.firstname = 'Dummy'
            dummy_user.lastname = 'Dummy'
            dummy_user.email = '*****@*****.**'
            dummy_user.dateofbirth = datetime.datetime(2020, 10, 5)
            dummy_user.is_admin = True
            dummy_user.set_password('admin')
            db.session.add(dummy_user)
            db.session.commit()

            dummy_id = User.query.filter(
                User.email == '*****@*****.**').first().id

            test_story = Story()
            test_story.text = "Test story from admin user"
            test_story.author_id = 1
            test_story.is_draft = 0
            test_story.figures = "#Test#admin#"

            dummy_story = Story()
            dummy_story.text = "Test story from dummy user"
            dummy_story.author_id = dummy_id
            dummy_story.is_draft = 0
            dummy_story.figures = "#Test#dummy#"

            db.session.add(test_story)
            db.session.add(dummy_story)
            db.session.commit()

            payload = {'email': '*****@*****.**', 'password': '******'}

            form = LoginForm(data=payload)

            self.client.post('/users/login',
                             data=form.data,
                             follow_redirects=True)
Example #7
0
def create_app():
    app = Flask(__name__)
    app.config[
        'WTF_CSRF_SECRET_KEY'] = 'ec35ae128aa97f834ab848ecf823340875ddf483e9a535440cf68e05b3b38865'
    app.config[
        'SECRET_KEY'] = '58c8f1ffb80e7d48d936cb8a485504498fc6c5dcfce18e3de6dcd3b851ff0540'
    app.config['STRAVA_CLIENT_ID'] = os.environ['STRAVA_CLIENT_ID']
    app.config['STRAVA_CLIENT_SECRET'] = os.environ['STRAVA_CLIENT_SECRET']
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///beepbeep.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a first admin user
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            example = User()
            example.email = '*****@*****.**'
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()
    return app
Example #8
0
def signup():
    form = UserForm()
    if request.method == 'POST':
        email = form.data['email']

        q = db.session.query(User).filter(User.email == email)
        check = q.first()
        if check is None:
            user = User()
            user.firstname = form.data['firstname']
            user.lastname = form.data['lastname']
            user.email = form.data['email']
            user.dateofbirth = form.data['dateofbirth']
            user.set_password(form.data['password'])
            db.session.add(user)
            db.session.commit()
            login_user(user)
            return redirect("/")
        else:
            form = UserForm()

            return render_template(
                'signup.html',
                form=form,
                error=True,
                message="The email was used before. Please change the email!")
    if request.method == 'GET':
        return render_template('signup.html', form=form)
Example #9
0
    def setUp(self) -> None:
        with app.app_context():
            # user for login
            example = User()
            example.firstname = 'Admin'
            example.lastname = 'Admin'
            example.email = '*****@*****.**'
            example.dateofbirth = datetime.datetime(2020, 10, 5)
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()

            # reacted story
            test_story = Story()
            test_story.text = "Test story from admin user"
            test_story.author_id = 1
            test_story.is_draft = 0
            test_story.figures = "#Test#admin#"
            db.session.add(test_story)
            db.session.commit()

            # login
            payload = {'email': '*****@*****.**', 'password': '******'}

            form = LoginForm(data=payload)

            self.client.post('/users/login',
                             data=form.data,
                             follow_redirects=True)
Example #10
0
def client():
    """ This function initialize a new DB for every test and creates the app. This function returns a tuple,
    the first element is a test client and the second is the app itself. Test client must be used for sending
    request and the app should be used for getting a context when, for example, we need to query the DB.
    I haven't found a more elegant way to do this."""
    app = create_app()
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db_fd, app.config['DATABASE'] = tempfile.mkstemp()
    print(app.config['DATABASE'])
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DATABASE']
    app.config['TESTING'] = True
    app.config[
        'WTF_CSRF_ENABLED'] = False  # disable CSRF validation -> DO THIS ONLY DURING TESTS!
    client = app.test_client()

    db.create_all(app=app)
    db.init_app(app=app)
    #with app.app_context():
    #db.engine.execute(_data_sql)
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            example = User()
            example.email = '*****@*****.**'
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()

    yield client, app

    os.close(db_fd)
    os.unlink(app.config['DATABASE'])
Example #11
0
def create_app():
    app = Flask(__name__)
    app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY'
    app.config['SECRET_KEY'] = 'ANOTHER ONE'
    app.config['STRAVA_CLIENT_ID'] = os.environ['STRAVA_CLIENT_ID']
    app.config['STRAVA_CLIENT_SECRET'] = os.environ['STRAVA_CLIENT_SECRET']
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///beepbeep.db'

    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a first admin user
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            example = User()
            example.email = '*****@*****.**'
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()
    return app
Example #12
0
def test_runs2(db_instance):
    email = 'mock' + str(random.randint(1, 101)) + '@mock.com'
    password = '******'
    example = User()
    example.email = email
    example.set_password(password)

    runs_id = ['1', '2', '3', '4', '5', '6', '7']

    db_instance.session.add(example)

    for i in runs_id:
        run = Run()
        run.runner = example
        run.strava_id = i
        db_instance.session.add(run)

    db_instance.session.commit()
    user_id = example.get_id()
    runId = 150

    run = db_instance.session.query(Run).filter(
        Run.runner_id == example.get_id(), Run.id == runId).first()
    assert run == None

    _delete_user(example)
Example #13
0
def test_runs1(db_instance):
    email = 'mock' + str(random.randint(1, 101)) + '@mock.com'
    password = '******'
    example = User()
    example.email = email
    example.set_password(password)

    runs_id = ['1', '2', '3', '4', '5', '6', '7']

    db_instance.session.add(example)

    for i in runs_id:
        run = Run()
        run.runner = example
        run.strava_id = i
        db_instance.session.add(run)

    db_instance.session.commit()
    user_id = example.get_id()

    previous_run = db_instance.session.query(Run).filter(
        Run.runner_id == example.get_id(),
        Run.id < 7).order_by(Run.id.desc()).first()
    assert previous_run.id == 6

    q = db_instance.session.query(Run).filter(
        Run.runner_id == example.get_id(), Run.id == 4)
    q.delete(synchronize_session=False)
    db_instance.session.commit()
    previous_run = db_instance.session.query(Run).filter(
        Run.runner_id == example.get_id(),
        Run.id < 5).order_by(Run.id.desc()).first()
    assert previous_run.id == 3

    _delete_user(example)
Example #14
0
def create_app():
    app = Flask(__name__)
    app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY'
    app.config['SECRET_KEY'] = 'ANOTHER ONE'
    app.config['STRAVA_CLIENT_ID'] = '31670'
    app.config[
        'STRAVA_CLIENT_SECRET'] = '47874ae3e3f326817f0c8391d181c67cef645482'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/runnerly'

    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a user
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            tarek = User()
            tarek.email = '*****@*****.**'
            tarek.is_admin = True
            tarek.set_password('ok')
            db.session.add(tarek)
            db.session.commit()
    return app
Example #15
0
def restart_db_tables(db, app):
    with app.app_context():
        db.init_app(app)
        db.drop_all(app=app)
        db.create_all(app=app)

        example = User()
        example.firstname = 'Admin'
        example.lastname = 'Admin'
        example.email = '*****@*****.**'
        example.dateofbirth = datetime.datetime(2020, 10, 5)
        example.is_admin = True
        example.set_password('admin')
        db.session.add(example)
        db.session.commit()

        example = Story()
        example.text = 'Trial story of example admin user :)'
        example.likes = 42
        example.author_id = 1
        example.roll = {
            'dice': ['bike', 'tulip', 'happy', 'cat', 'ladder', 'rain']
        }
        example.date = datetime.datetime(2019, 11, 5)
        db.session.add(example)
        db.session.commit()
Example #16
0
def create_app():
    app = Flask(__name__)
    app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY'
    app.config['SECRET_KEY'] = 'ANOTHER ONE'
    app.config['GITLAB_URI'] = 'https://umcs.schneiderp.ovh'
    #app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/gitlab_monolith'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///gitlab-monolith'

    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a user
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            suser = User()
            suser.email = '*****@*****.**'
            suser.is_admin = True
            suser.set_password('ok')
            db.session.add(suser)
            db.session.commit()
    return app
Example #17
0
def populate_user():
    new_user = User()
    new_user.email = "*****@*****.**"
    new_user.phone = '3333333333'
    new_user.firstname = "firstname_test"
    new_user.lastname = "lastname_test"
    new_user.password = "******"
    new_user.dateofbirth = datetime.date(2020, 10, 5)
    new_user.role = "customer"

    return new_user
Example #18
0
 def setUp(self) -> None:
     with app.app_context():
         # create an user Admin
         example = User()
         example.firstname = 'Admin'
         example.lastname = 'Admin'
         example.email = '*****@*****.**'
         example.dateofbirth = datetime.datetime(2010, 10, 5)
         example.is_admin = True
         example.set_password('admin')
         db.session.add(example)
         db.session.commit()
Example #19
0
def add_user(email, phone, firstname, lastname, password, date, role):
    new_user = User()
    new_user.email = email
    new_user.phone = phone
    new_user.firstname = firstname
    new_user.lastname = lastname
    new_user.password = password
    new_user.role = role
    new_user.dateofbirth = date

    db.session.add(new_user)
    db.session.commit()
    return db.session.query(User).filter(User.email == email).first()
Example #20
0
def create_app(debug=False):
    app = Flask(__name__)
    app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY'
    app.config['SECRET_KEY'] = 'ANOTHER ONE'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///storytellers.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    # DEBUGGING AND TESTING
    app.config['SQLALCHEMY_ECHO'] = False
    app.config['TESTING'] = debug
    app.config['LOGIN_DISABLED'] = True
    app.config['WTF_CSRF_ENABLED'] = False

    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a first admin user
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            example = User()
            example.firstname = 'Admin'
            example.lastname = 'Admin'
            example.email = '*****@*****.**'
            example.dateofbirth = datetime.datetime(2020, 10, 5)
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()

        q = db.session.query(Story).filter(Story.id == 1)
        story = q.first()
        if story is None:
            example = Story()
            example.text = 'Trial story of example admin user :)'
            example.likes = 42
            example.author_id = 1
            example.dicenumber = 6
            example.roll = {
                'dice': ['bike', 'tulip', 'happy', 'cat', 'ladder', 'rain']
            }
            example.date = datetime.datetime(2019, 11, 5)
            db.session.add(example)
            db.session.commit()

    return app
Example #21
0
def insert_ha(db, app):
    with app.app_context():
        ha = db.session.query(User).filter_by(
            email='*****@*****.**').first()
        if ha is None:
            example = User()
            example.email = '*****@*****.**'
            example.phone = '3333333333'
            example.firstname = 'ha'
            example.lastname = 'ha'
            example.set_password('ha')
            example.dateofbirth = datetime.date(2020, 10, 5)
            example.is_admin = True
            example.role = 'ha'
            db.session.add(example)
            db.session.commit()
Example #22
0
def insert_admin(db, app):
    with app.app_context():
        admin = db.session.query(User).filter_by(
            email='*****@*****.**').first()
        if admin is None:
            example = User()
            example.email = '*****@*****.**'
            example.phone = '3333333333'
            example.firstname = 'Admin'
            example.lastname = 'Admin'
            example.set_password('admin')
            example.dateofbirth = datetime.date(2020, 10, 5)
            example.is_admin = True
            example.role = 'admin'
            db.session.add(example)
            db.session.commit()
Example #23
0
def new_user(strava_token=None):
    user = User()
    user.email = '*****@*****.**'
    user.firstname = "A"
    user.lastname = "Tester"
    user.strava_token = 0
    user.age = 0
    user.weight = 0
    user.max_hr = 0
    user.rest_hr = 0
    user.vo2max = 0
    user.set_password('test')
    if strava_token is not None:
        user.strava_token = strava_token
    db.session.add(user)
    db.session.commit()
    return user
Example #24
0
def create_app():
    app = Flask(__name__)
    # App
    app.config[
        'SQLALCHEMY_TRACK_MODIFICATIONS'] = False  # suppress pytest warning
    app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY'
    app.config['SECRET_KEY'] = 'ANOTHER ONE'
    app.config['STRAVA_CLIENT_ID'] = os.environ['STRAVA_CLIENT_ID']
    app.config['STRAVA_CLIENT_SECRET'] = os.environ['STRAVA_CLIENT_SECRET']
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///beepbeep.db'

    # Mail
    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USERNAME'] = os.environ['MAIL_USERNAME']
    app.config['MAIL_PASSWORD'] = os.environ['MAIL_PASSWORD']
    app.config['MAIL_USE_TLS'] = False
    app.config['MAIL_USE_SSL'] = True

    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    from monolith.database import db, User, Report
    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a first admin user
    with app.app_context():
        app.register_error_handler(401, render_error_page)
        app.register_error_handler(403, render_error_page)
        app.register_error_handler(404, render_error_page)
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            example = User()
            example.email = '*****@*****.**'
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()
    return app
Example #25
0
def create_app():
    app = Flask(__name__)
    app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY'
    app.config['SECRET_KEY'] = 'ANOTHER ONE'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///gooutsafe.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a first admin user
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            example = User()
            example.firstname = 'Admin'
            example.lastname = 'Admin'
            example.email = '*****@*****.**'
            example.dateofbirth = datetime.datetime(2020, 10, 5)
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()

        q = db.session.query(Restaurant).filter(Restaurant.id == 1)
        restaurant = q.first()
        if restaurant is None:
            example = Restaurant()
            example.name = 'Trial Restaurant'
            example.likes = 42
            example.phone = 555123456
            example.lat = 43.720586
            example.lon = 10.408347
            db.session.add(example)
            db.session.commit()

    return app
Example #26
0
def create_app():
    app = Flask(__name__)
    app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY'
    app.config['SECRET_KEY'] = 'ANOTHER ONE'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///storytellers.db'

    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a first admin user
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            example = User()
            example.firstname = 'Admin'
            example.lastname = 'Admin'
            example.email = '*****@*****.**'
            example.dateofbirth = datetime.datetime(2020, 10, 5)
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()

        q = db.session.query(Story).filter(Story.id == 1)
        story = q.first()
        if story is None:
            example = Story()
            example.text = 'Trial story of example admin user :)'
            example.likes = 42
            example.author_id = 1
            print(example)
            db.session.add(example)
            db.session.commit()

    return app
Example #27
0
    def setUp(self) -> None:
        with app.app_context():
            # user for login
            example = User()
            example.firstname = 'Admin'
            example.lastname = 'Admin'
            example.email = '*****@*****.**'
            example.dateofbirth = datetime.datetime(2020, 10, 5)
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()

            # reacted story
            test_story = Story()
            test_story.text = "Test story from admin user"
            test_story.author_id = 1
            test_story.is_draft = 0
            test_story.figures = "#admin#cat#"
            db.session.add(test_story)
            db.session.commit()
Example #28
0
def create_app():
    app = Flask(__name__)
    app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY'
    app.config['SECRET_KEY'] = 'ANOTHER ONE'
    # app.config['STRAVA_CLIENT_ID'] = 29641
    # app.config['STRAVA_CLIENT_SECRET'] = "097321492b94a769fe8be68a50ab2a780f30b6dc"

    app.config['STRAVA_CLIENT_ID'] = os.environ['STRAVA_CLIENT_ID']
    app.config['STRAVA_CLIENT_SECRET'] = os.environ['STRAVA_CLIENT_SECRET']
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///beepbeep.db'
    app.config['MAIL_SERVER']='smtp.gmail.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USERNAME'] = os.environ['EMAIL_ID']
    app.config['MAIL_PASSWORD'] = os.environ['EMAIL_PASS']
    app.config['MAIL_USE_TLS'] = False
    app.config['MAIL_USE_SSL'] = True




    for bp in blueprints:
        app.register_blueprint(bp)
        bp.app = app

    db.init_app(app)
    login_manager.init_app(app)
    db.create_all(app=app)

    # create a first admin user
    with app.app_context():
        q = db.session.query(User).filter(User.email == '*****@*****.**')
        user = q.first()
        if user is None:
            example = User()
            example.email = '*****@*****.**'
            example.is_admin = True
            example.set_password('admin')
            db.session.add(example)
            db.session.commit()
    return app
Example #29
0
    def test_email_sender(self):
        global _app
        if _app is None:
            tested_app = create_app(debug=True)
            _app = tested_app
        else:
            tested_app = _app
        restart_db_tables(db, tested_app)

        with tested_app.test_client() as client:
            with client.session_transaction() as session:
                example2 = User()
                example2.firstname = 'Daniele'
                example2.lastname = 'Arioli'
                example2.email = '*****@*****.**'
                example2.dateofbirth = datetime(2020, 10, 5)
                example2.is_admin = True
                example2.set_password('admin')
                db.session.add(example2)
                db.session.commit()

                self.assertTrue(send_emails())
Example #30
0
    def test_die_init(self):
        example = User()
        example.id = random.randint(0, 2048)
        example.firstname = 'userwall'
        example.lastname = 'theWall'
        example.email = '*****@*****.**'
        example.dateofbirth = datetime.datetime(2020, 10, 5)
        example.is_admin = True
        example.set_password('daddysflownacrosstheocean')

        some_stories = [
            'story1', 'story2', 'story3', 'story4', 'story5', 'story6'
        ]

        wall = Wall(example)

        for s in some_stories:
            story = Story()
            story.id = random.randint(0, 2048)
            story.text = s
            story.likes = 0
            story.dislikes = 0
            wall.add_story(story)

        wall.storyLimit = len(wall.stories)

        story = Story()
        story.id = random.randint(0, 2048)
        story.text = 'an extra story'
        story.likes = 0
        story.dislikes = 0
        wall.add_story(story)

        wall.add_story(story)

        self.assertEqual(len(wall.stories), wall.storyLimit)