コード例 #1
0
ファイル: test_user.py プロジェクト: bossjones/ultron8
def test_check_if_user_is_active(db: Session) -> None:
    email = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=email, password=password)
    user = crud.user.create(db, user_in=user_in)
    is_active = crud.user.is_active(user)
    assert is_active is True
コード例 #2
0
def test_check_if_user_is_superuser_normal_user():
    username = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=username, password=password)
    user = crud.user.create(db_session, obj_in=user_in)
    is_superuser = crud.user.is_superuser(user)
    assert is_superuser is False
コード例 #3
0
def test_check_if_user_is_active_inactive():
    email = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=email, password=password, disabled=True)
    user = crud.user.create(db_session, obj_in=user_in)
    is_active = crud.user.is_active(user)
    assert is_active
コード例 #4
0
ファイル: test_packs.py プロジェクト: bossjones/ultron8
def test_get_packs(db: Session) -> None:
    name = random_lower_string()
    description = random_lower_string()
    keywords = random_lower_string()
    version = random_lower_string()
    python_versions = random_lower_string()
    author = random_lower_string()
    email = "*****@*****.**"
    contributors = random_lower_string()
    files = random_lower_string()
    path = random_lower_string()
    ref = random_lower_string()

    packs_in = PacksCreate(
        name=name,
        description=description,
        keywords=keywords,
        version=version,
        python_versions=python_versions,
        author=author,
        email=email,
        contributors=contributors,
        files=files,
        path=path,
        ref=ref,
    )
    packs = crud.packs.create(db, packs_in=packs_in)
    packs_2 = crud.packs.get(db, packs_id=packs.id)
    assert jsonable_encoder(packs) == jsonable_encoder(packs_2)
コード例 #5
0
def test_create_user():
    email = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=email, password=password)
    user = crud.user.create(db_session, obj_in=user_in)
    assert user.email == email
    assert hasattr(user, "hashed_password")
コード例 #6
0
def test_check_if_user_is_superuser():
    email = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=email, password=password, is_superuser=True)
    user = crud.user.create(db_session, obj_in=user_in)
    is_superuser = crud.user.is_superuser(user)
    assert is_superuser is True
コード例 #7
0
ファイル: item.py プロジェクト: bossjones/ultron8
def create_random_item(db: Session, owner_id: int = None):
    if owner_id is None:
        user = create_random_user(db)
        owner_id = user.id
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description, id=id)
    return crud.item.create(db_session=db, item_in=item_in, owner_id=owner_id)
コード例 #8
0
def create_random_item(db: Session, *, owner_id: Optional[int] = None) -> models.Item:
    if owner_id is None:
        user = create_random_user(db)
        owner_id = user.id
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description, id=id)
    return crud.item.create_with_owner(db=db, obj_in=item_in, owner_id=owner_id)
コード例 #9
0
def test_get_user():
    password = random_lower_string()
    username = random_lower_string()
    user_in = UserCreate(email=username, password=password, is_superuser=True)
    user = crud.user.create(db_session, obj_in=user_in)
    user_2 = crud.user.get(db_session, id=user.id)
    assert user.email == user_2.email
    assert jsonable_encoder(user) == jsonable_encoder(user_2)
コード例 #10
0
ファイル: test_user.py プロジェクト: bossjones/ultron8
def test_authenticate_user(db: Session) -> None:
    email = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=email, password=password)
    user = crud.user.create(db, user_in=user_in)
    authenticated_user = crud.user.authenticate(db, email=email, password=password)
    assert authenticated_user
    assert user.email == authenticated_user.email
コード例 #11
0
ファイル: test_item.py プロジェクト: bossjones/ultron8
def test_create_item(db: Session) -> None:
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user(db)
    item = crud.item.create(db_session=db, item_in=item_in, owner_id=user.id)
    assert item.title == title
    assert item.description == description
    assert item.owner_id == user.id
def test_create_account(db: Session) -> None:
    account_name = random_lower_string()
    account_description = random_lower_string()
    account_in = schemas.AccountCreate(name=account_name,
                                       description=account_description)
    account = crud.account.create(db, obj_in=account_in)
    assert account.name == account_name
    assert account.is_active
    assert hasattr(account, "name")
コード例 #13
0
def test_update_trigger_tags(db: Session) -> None:
    packs_shared_name = random_lower_string()
    packs_name = packs_shared_name
    packs_description = random_lower_string()
    packs_keywords = random_lower_string()
    packs_version = random_lower_string()
    packs_python_versions = random_lower_string()
    packs_author = random_lower_string()
    packs_email = "*****@*****.**"
    packs_contributors = random_lower_string()
    packs_files = random_lower_string()
    packs_path = random_lower_string()
    packs_ref = packs_shared_name

    trigger_name = TRIGGER_0["name"]
    trigger_packs_name = packs_name
    trigger_description = TRIGGER_0["description"]
    trigger_type = TRIGGER_0["type"]
    trigger_parameters = TRIGGER_0["parameters"]

    packs_in = PacksCreate(
        name=packs_name,
        description=packs_description,
        keywords=packs_keywords,
        version=packs_version,
        python_versions=packs_python_versions,
        author=packs_author,
        email=packs_email,
        contributors=packs_contributors,
        files=packs_files,
        path=packs_path,
        ref=packs_ref,
    )

    packs = crud.packs.create(db, packs_in=packs_in)

    trigger_in = TriggerCreate(
        name=trigger_name,
        packs_name=trigger_packs_name,
        description=trigger_description,
        type=trigger_type,
        parameters=trigger_parameters,
    )

    trigger = crud.trigger.create(db, trigger_in=trigger_in, packs_id=packs.id)
    description2 = random_lower_string()
    trigger_update = TriggerUpdate(description=description2)
    trigger2 = crud.trigger.update(db_session=db,
                                   trigger=trigger,
                                   trigger_in=trigger_update)

    assert trigger.name == trigger2.name
    assert trigger.packs_name == trigger2.packs_name
    assert trigger.description == description2
    assert trigger.type == trigger2.type
    assert trigger.parameters == trigger2.parameters
コード例 #14
0
ファイル: test_user.py プロジェクト: bossjones/ultron8
def test_check_if_user_is_active_inactive(db: Session) -> None:
    email = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=email, password=password, disabled=True)
    print(user_in)
    user = crud.user.create(db, user_in=user_in)
    print(user)
    is_active = crud.user.is_active(user)
    print(is_active)
    assert is_active
コード例 #15
0
def create_random_user():
    email = random_lower_string()
    password = random_lower_string()
    relation = random_lower_string()
    user_in = UserCreate(full_name=email,
                         email=email,
                         password=password,
                         relation=relation)
    user = crud.user.create(db_session=db_session, user_in=user_in)
    return user
def test_get_account_by_name(db: Session) -> None:
    account_name = random_lower_string()
    account_description = random_lower_string()
    account_in = schemas.AccountCreate(name=account_name,
                                       description=account_description)
    account = crud.account.create(db, obj_in=account_in)
    account_2 = crud.account.get_by_name(db, name=account_name)
    assert account_2
    assert account.name == account_2.name
    assert jsonable_encoder(account) == jsonable_encoder(account_2)
コード例 #17
0
ファイル: packs.py プロジェクト: bossjones/ultron8
def create_random_packs(db: Session) -> Packs:
    shared_name = random_lower_string()
    name = shared_name
    description = random_lower_string()
    keywords = random_lower_string()
    version = random_lower_string()
    python_versions = random_lower_string()
    author = random_lower_string()
    email = "*****@*****.**"
    # contributors = [random_lower_string()]
    # files = [random_lower_string()]
    contributors = random_lower_string()
    files = random_lower_string()
    path = random_lower_string()
    ref = shared_name

    packs_in = PacksCreate(
        name=name,
        description=description,
        keywords=keywords,
        version=version,
        python_versions=python_versions,
        author=author,
        email=email,
        contributors=contributors,
        files=files,
        path=path,
        ref=ref,
    )

    packs = crud.packs.create(db_session=db, packs_in=packs_in)
    return packs
コード例 #18
0
def test_update_password(db: Session) -> None:
    password = random_lower_string()
    email = random_email()
    user_in = UserCreate(email=email, password=password)
    user = crud.user.create(db, obj_in=user_in)
    new_password = random_lower_string()
    user_in_update = UserUpdate(password=new_password)
    crud.user.update(db, db_obj=user, obj_in=user_in_update)
    user_2 = crud.user.get(db, id=user.id)
    assert user_2
    assert user.email == user_2.email
    assert verify_password(password, user_2.hashed_password)
コード例 #19
0
def test_update_user(db: Session) -> None:
    password = random_lower_string()
    email = random_email()
    user_in = UserCreate(email=email, password=password)
    user = crud.user.create(db, obj_in=user_in)
    new_username = random_lower_string()
    user_in_update = UserUpdate(full_name=new_username)
    crud.user.update(db, db_obj=user, obj_in=user_in_update)
    user_2 = crud.user.get(db, id=user.id)
    assert user_2
    assert user.email == user_2.email
    assert new_username == user_2.full_name
コード例 #20
0
def test_get_item(db: Session) -> None:
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user(db)
    item = crud.item.create_with_owner(db=db, obj_in=item_in, owner_id=user.id)
    stored_item = crud.item.get(db=db, id=item.id)
    assert stored_item
    assert item.id == stored_item.id
    assert item.title == stored_item.title
    assert item.description == stored_item.description
    assert item.owner_id == stored_item.owner_id
コード例 #21
0
def test_get_item():
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user()
    item = crud.item.create(db_session=db_session,
                            item_in=item_in,
                            owner_id=users.id)
    stored_item = crud.item.get(db_session=db_session, item_id=item.id)
    assert item.id == stored_item.id
    assert item.title == stored_item.title
    assert item.description == stored_item.description
    assert item.owner_id == stored_item.owner_id
コード例 #22
0
ファイル: test_item.py プロジェクト: bossjones/ultron8
def test_delete_item(db: Session) -> None:
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user(db)
    item = crud.item.create(db_session=db, item_in=item_in, owner_id=user.id)
    item2 = crud.item.remove(db_session=db, id=item.id)
    item3 = crud.item.get(db_session=db, id=item.id)
    assert item3 is None
    assert item2.id == item.id
    assert item2.title == title
    assert item2.description == description
    assert item2.owner_id == user.id
コード例 #23
0
def test_create_user_by_normal_user_is_unauthorized(
        client: TestClient, normal_user_token_headers: dict,
        db: Session) -> None:
    username = random_email()
    password = random_lower_string()
    full_name = random_lower_string()
    data = {"email": username, "password": password, "full_name": full_name}
    r = client.post(
        f"{settings.API_V1_STR}/users",
        headers=normal_user_token_headers,
        json=data,
    )
    assert r.status_code == 401
コード例 #24
0
ファイル: test_item.py プロジェクト: bossjones/ultron8
def test_update_item(db: Session) -> None:
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user(db)
    item = crud.item.create(db_session=db, item_in=item_in, owner_id=user.id)
    description2 = random_lower_string()
    item_update = ItemUpdate(description=description2)
    item2 = crud.item.update(db_session=db, item=item, item_in=item_update)
    assert item.id == item2.id
    assert item.title == item2.title
    assert item2.description == description2
    assert item.owner_id == item2.owner_id
コード例 #25
0
ファイル: test_users.py プロジェクト: AusiasMarch/elapuntador
def test_create_user_by_normal_user():
    server_api = get_server_api()
    username = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=username, password=password)
    user = crud.user.create(db_session, user_in=user_in)  # noqa
    user_token_headers = user_authentication_headers(server_api, username,
                                                     password)
    data = {"email": username, "password": password}
    r = requests.post(f"{server_api}{config.API_V1_STR}/users/",
                      headers=user_token_headers,
                      json=data)
    assert r.status_code == 400
def test_update_account(db: Session) -> None:
    account_name = random_lower_string()
    account_description = random_lower_string()
    account_in = schemas.AccountCreate(name=account_name,
                                       description=account_description)
    account = crud.account.create(db, obj_in=account_in)
    new_account_name = random_lower_string()
    account_in_update = schemas.AccountUpdate(name=new_account_name)
    crud.account.update(db, db_obj=account, obj_in=account_in_update)
    account_2 = crud.account.get(db, id=account.id)
    assert account_2
    assert account.description == account_2.description
    assert account_2.name == new_account_name
コード例 #27
0
ファイル: test_users.py プロジェクト: AusiasMarch/elapuntador
def test_create_user_new_email(superuser_token_headers):
    server_api = get_server_api()
    username = random_lower_string()
    password = random_lower_string()
    data = {"email": username, "password": password}
    r = requests.post(
        f"{server_api}{config.API_V1_STR}/users/",
        headers=superuser_token_headers,
        json=data,
    )
    assert 200 <= r.status_code < 300
    created_user = r.json()
    user = crud.user.get_by_email(db_session, email=username)
    assert user.email == created_user["email"]
コード例 #28
0
ファイル: test_users.py プロジェクト: AusiasMarch/elapuntador
def test_get_existing_user(superuser_token_headers):
    server_api = get_server_api()
    username = random_lower_string()
    password = random_lower_string()
    user_in = UserCreate(email=username, password=password)
    user = crud.user.create(db_session, user_in=user_in)
    user_id = users.id
    r = requests.get(
        f"{server_api}{config.API_V1_STR}/users/{user_id}",
        headers=superuser_token_headers,
    )
    assert 200 <= r.status_code < 300
    api_user = r.json()
    user = crud.user.get_by_email(db_session, email=username)
    assert user.email == api_user["email"]
コード例 #29
0
ファイル: test_packs.py プロジェクト: bossjones/ultron8
def test_delete_packs(db: Session) -> None:
    name = random_lower_string()
    description = random_lower_string()
    keywords = random_lower_string()
    version = random_lower_string()
    python_versions = random_lower_string()
    author = random_lower_string()
    email = "*****@*****.**"
    contributors = random_lower_string()
    files = random_lower_string()
    path = random_lower_string()
    ref = random_lower_string()

    packs_in = PacksCreate(
        name=name,
        description=description,
        keywords=keywords,
        version=version,
        python_versions=python_versions,
        author=author,
        email=email,
        contributors=contributors,
        files=files,
        path=path,
        ref=ref,
    )
    packs = crud.packs.create(db, packs_in=packs_in)

    packs2 = crud.packs.remove(db_session=db, id=packs.id)

    packs3 = crud.packs.get(db_session=db, packs_id=packs.id)

    assert packs3 is None

    assert packs2.id == packs.id
    assert packs2.name == name
    assert packs2.description == description
    assert packs2.keywords == keywords
    assert packs2.version == version
    assert packs2.python_versions == python_versions
    assert packs2.author == author
    assert packs2.email == email
    assert packs2.contributors == contributors
    assert packs2.files == files
    assert packs2.path == path
    assert packs2.ref == ref
    assert packs2.created_at == "2019-07-25 01:11:00.740428"
    assert packs2.updated_at == "2019-07-25 01:11:00.740428"
コード例 #30
0
def test_create_user_open(client: TestClient, normal_user_token_headers: dict,
                          db: Session) -> None:
    username = random_email()
    password = random_lower_string()
    full_name = random_lower_string()
    data = {"email": username, "password": password, "full_name": full_name}
    r = client.post(
        f"{settings.API_V1_STR}/users/open",
        headers=normal_user_token_headers,
        json=data,
    )
    assert 200 <= r.status_code < 300
    created_user = r.json()
    user = crud.user.get_by_email(db, email=username)
    assert user
    assert user.email == created_user["email"]