Ejemplo n.º 1
0
    def test_update_user_me_by_normal_user(
        self, mocker: MockFixture, fastapi_client: TestClient, db: Session
    ) -> None:
        server_api = get_server_api()
        logger.debug("server_api : %s", server_api)

        # create basic user via crud
        data = _MakeRandomNormalUserFactory()
        logger.debug("data : {}".format(data))
        user_in = UserCreate(email=data.email, password=data.password)
        logger.debug("user_in : {}".format(user_in))
        user_create_crud = crud.user.create(db, user_in=user_in)
        logger.debug("user_create_crud : {}".format(jsonable_encoder(user_create_crud)))

        # get normal user token for update request
        user_token_headers = user_authentication_headers(
            server_api, data.email, data.password
        )

        user_update = UserUpdate(
            email=data.email, password=data.password, full_name=data.full_name
        )
        logger.debug("user_update : {}".format(user_update))

        json_encoded_user_update = jsonable_encoder(user_update)

        r = fastapi_client.put(
            f"{server_api}{settings.API_V1_STR}/users/me",
            headers=user_token_headers,
            json=json_encoded_user_update,
        )

        assert 200 == r.status_code
        r.json()
Ejemplo n.º 2
0
def ordinary_token_headers(client: TestClient) -> dict:
    """
    普通用户
    :param client:
    :return:
    """
    return user_authentication_headers(client=client,
                                       email="*****@*****.**",
                                       password="******")
Ejemplo n.º 3
0
def superuser_token_headers(client: TestClient) -> dict:
    """
    管理员 admin 用户测试, 后续新增 一份测试环境
    :param client:
    :return:
    """
    return user_authentication_headers(client=client,
                                       email="*****@*****.**",
                                       password="******")
Ejemplo n.º 4
0
def test_get_credit_whitout_user(
    db: Session, client: TestClient, faker: Generator) -> None:

    dict_user = create_random_user(db)
    user = dict_user.get('user')
 
    headers = user_authentication_headers(client, user.email, dict_user.get('password'))
    response = client.get(f"{settings.API_V1_STR}/credit-delear?reseller_cpf=teste", headers=headers)

    assert response.status_code == status.HTTP_400_BAD_REQUEST
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
def test_get_credit(
    db: Session, client: TestClient, faker: Generator) -> None:

    dict_user = create_random_user(db)
    user = dict_user.get('user')
    cpf = user.cpf
 
    headers = user_authentication_headers(client, user.email, dict_user.get('password'))
    response = client.get(f"{settings.API_V1_STR}/credit-delear?reseller_cpf={cpf}", headers=headers)

    assert 200 <= response.status_code < 300

    created_purchase = response.json()

    assert schemas.PurcahseCredit.parse_obj(created_purchase).credit
Ejemplo n.º 7
0
 def test_create_user_by_normal_user(
     self, mocker: MockFixture, fastapi_client: TestClient, db: Session
 ) -> None:
     server_api = get_server_api()
     logger.debug("server_api : %s", server_api)
     # username = random_lower_string()
     # password = random_lower_string()
     data = _MakeRandomNormalUserFactory()
     user_in = UserCreate(email=data.email, password=data.password)
     user = crud.user.create(db, user_in=user_in)
     user_token_headers = user_authentication_headers(
         server_api, data.email, data.password
     )
     # data = {"email": username, "password": password}
     r = fastapi_client.post(
         f"{server_api}{settings.API_V1_STR}/users/",
         headers=user_token_headers,
         json=data.dict(),  # pylint: disable=no-member
     )
     assert r.status_code == 400
Ejemplo n.º 8
0
def test_post_new_purchase(
    db: Session, client: TestClient, faker: Generator, value_purchase: int, percente_cashback: int
) -> None:

    dict_user = create_random_user(db)
    user = dict_user.get('user')
    code = faker.word()
    value = value_purchase
    purchase_date = datetime.now().isoformat()
    cpf = user.cpf
    data = {"code": code, "value": value, "purchase_date": purchase_date, "cpf": cpf}

    headers = user_authentication_headers(client, user.email, dict_user.get('password'))
    response = client.post(f"{settings.API_V1_STR}/purchase", json=data, headers=headers)
    
    assert status.HTTP_200_OK == response.status_code

    created_purchase = response.json()
    request_uuid = str(uuid4())
    purchase = crud.purchase.get_purchase_by_code(db, code=code, request_uuid=request_uuid)
    assert schemas.Pusrchase.parse_obj(created_purchase)
    assert purchase
    assert float(purchase.cashback_percente) == percente_cashback
    assert float(purchase.cashback_value) == value * (percente_cashback / 100)