Exemplo n.º 1
0
def user_seeder(db: Session):
    user.Base.metadata.create_all(bind=engine)

    one = UserCreateRequest(
        full_name="Chosen One",
        email="*****@*****.**",
        username=settings.ADMIN_USERNAME,
        password=settings.ADMIN_PASSWORD,
        admin=True,
    )
    two = UserCreateRequest(
        full_name="Morpheus",
        email="*****@*****.**",
        username="******",
        password=settings.ADMIN_PASSWORD,
        admin=False,
    )
    three = UserCreateRequest(
        full_name="Tank",
        email="*****@*****.**",
        username="******",
        password=settings.ADMIN_PASSWORD,
        admin=False,
    )
    one_in_db = crud.get_user_by_username(db, username=one.username)
    two_in_db = crud.get_user_by_username(db, username=two.username)
    three_in_db = crud.get_user_by_username(db, username=three.username)
    if not one_in_db:
        crud.create_user(db, one)
    if not two_in_db:
        crud.create_user(db, two)
    if not three_in_db:
        crud.create_user(db, three)
Exemplo n.º 2
0
def test_create_user(db: Session):
    profile1 = faker.simple_profile()
    user_request = UserCreateRequest(
        full_name=profile1["name"],
        username=profile1["username"],
        email=profile1["mail"],
        password=faker.md5(),
    )
    user = crud.create_user(db, user_request)
    assert user
    assert user.username == user_request.username
Exemplo n.º 3
0
def test_get_user_by_email(db: Session):
    profile3 = faker.simple_profile()
    user_request = UserCreateRequest(
        full_name=profile3["name"],
        username=profile3["username"],
        email=profile3["mail"],
        password=faker.md5(),
    )
    user_in_db = crud.create_user(db, user_request)
    result = crud.get_user_by_email(db, user_in_db.email)
    assert result
    assert user_request.email == result.email
Exemplo n.º 4
0
def db():
    user.Base.metadata.create_all(bind=engine)
    admin_user = UserCreateRequest(
        full_name="Chosen One",
        email="*****@*****.**",
        username=settings.ADMIN_USERNAME,
        password=settings.ADMIN_PASSWORD,
        admin=True,
    )
    crud.create_user(SessionLocal(), admin_user)
    yield SessionLocal()
    drop_database(engine.url)
Exemplo n.º 5
0
def user_token_header(db: SessionLocal()):
    user = UserCreateRequest(
        full_name=faker.name(),
        email=faker.email(),
        username=faker.word(),
        password=faker.md5(),
        admin=False,
    )

    if not crud.get_user_by_username(db, username=user.username):
        crud.create_user(db, user)

    user_token = create_jwt_token(user.username)
    headers = {"Authorization": f"Bearer {user_token}"}
    return headers