Beispiel #1
0
def create_user():
    data = request.get_json()

    if data['username']:
        username = data['username']

    if data['email']:
        email = data['email']

    if data['password']:
        password = data['password']

    new_user = User(
        username=username,
        email=email,
    )

    new_user.set_password(password)

    user_schema = UserSchema()

    user = user_schema.dump(new_user)

    return make_response(
        jsonify({
            "message": "Resource added successfully",
            "success": True
        }), 201)
def test_password_hashing():
    with app.app_context():
        db.create_all()

        new_user = User(username='******', email='*****@*****.**')

        password = '******'

        new_user.set_password(password)

        new_user.save()

        assert new_user.check_password('password') == True
def test_user_creation():

    with app.app_context():
        db.create_all()

        username = '******'
        email = '*****@*****.**'
        password = '******'

        new_user = User(username=username, email=email)

        new_user.set_password(password)

        new_user.save()

        user = User.query.filter_by(username=username).first()

        assert user.username == username
Beispiel #4
0
from main.models.users import User
from main.utils.database import db
from main import app
from main.config import TestConfig

app.config.from_object(TestConfig)
db.init_app(app)

with app.app_context():
    db.create_all()

    new_user = User(username='******', email='*****@*****.**')

    new_user.set_password('testpassword')

    new_user.save()


def test_password_reset():

    old_password = '******'

    new_password = '******'

    new_user.reset_password(old_password, new_password)

    assert new_user.check_password('newpassword') == True