def test_create_product_category():
    global product_category_id, valid_product_category
    result = ProductCategories.create_one(valid_product_category)
    assert result['success'] is True
    product_category_id = result['value']['_id']
    assert ObjectId(product_category_id)
    assert result['value']['name'] == valid_product_category["name"]
Пример #2
0
def update_product_category(
    *,
    product_category_id: str = Path(
        ..., title="The product_category ID as a valid ObjectId"),
    ProductCategory: ProductCategoryToUpdate,
    CurrentUser: UserOut = Depends(get_current_user)):
    # Exclude sellerId because it seems there is no reason to update it
    return format_result(
        ProductCategories.update_one(product_category_id, ProductCategory,
                                     {'sellerId'}))
Пример #3
0
def delete_product_category(product_category_id: str,
                            CurrentUser: UserOut = Depends(get_current_user)):
    return format_result(ProductCategories.delete_one(product_category_id))
Пример #4
0
def create_product_category(ProductCategory: ProductCategoryToInsert,
                            CurrentUser: UserOut = Depends(get_current_user)):
    if not (hasattr(CurrentUser, 'sellerId')) or CurrentUser.sellerId is None:
        raise mpapi_exceptions({'error': 'USER-HAS-NO-SELLERID'})
    ProductCategory.sellerId = CurrentUser.sellerId
    return format_result(ProductCategories.create_one(ProductCategory))
Пример #5
0
def get_product_category_by_id(product_category_id: str = Path(
    ..., title="The product category ID as a valid ObjectId")):
    return format_result(ProductCategories.get_one(product_category_id))
Пример #6
0
async def get_product_categories(skip: int = 0, limit: int = 100):
    return format_result(ProductCategories.get_many(skip, limit))
def test_delete_product_category():
    global product_category_id
    result = ProductCategories.delete_one(product_category_id)
    assert result['success'] is True
    result = ProductCategories.get_one(product_category_id)
    assert result['success'] is False
def test_update_product_category():
    global product_category_id
    name = "Test Update"
    result = ProductCategories.update_one(product_category_id, {"name": name})
    assert result['success'] is True
    assert result['value']['name'] == name