Beispiel #1
0
def test_create_seller():
    global seller_id
    result = Sellers.create_one(valid_seller)
    assert result['success'] is True
    seller_id = result['value']['_id']
    assert ObjectId(seller_id)
    assert result['value']['name'] == valid_seller['name']
Beispiel #2
0
def create_seller(Seller: SellerToInsert,
                  CurrentUser: UserOut = Depends(get_current_user)):
    result = Sellers.create_one(Seller)
    if result['success'] and result['value']:
        seller_id = result['value']['_id']
        if not (hasattr(CurrentUser,
                        'sellerId')) or CurrentUser.sellerId is None:
            Users.update_one(CurrentUser.id, {"sellerId": seller_id})
    return format_result(result)
Beispiel #3
0
def db_init(database_uri, database_name, delete=False):
    if delete:
        db_drop(database_uri, database_name)
    user_id = Users.create_one({
        "username": "******",
        "email": "*****@*****.**",
        "password": "******"
    })['value']['_id']
    seller_id = Sellers.create_one({"name": "Company1"})['value']['_id']
    Users.update_one(user_id, {'sellerId': seller_id})
Beispiel #4
0
def test_delete_seller():
    global seller_id
    result = Sellers.delete_one(seller_id)
    assert result['success'] is True
    result = Sellers.get_one(seller_id)
    assert result['success'] is False
Beispiel #5
0
def test_update_seller():
    global seller_id
    valid_seller["name"] = "Test Update"
    result = Sellers.update_one(seller_id, valid_seller)
    assert result['success'] is True
    assert result['value']['name'] == valid_seller['name']
Beispiel #6
0
def delete_seller(seller_id: str,
                  CurrentUser: UserOut = Depends(get_current_user)):
    return format_result(Sellers.delete_one(seller_id))
Beispiel #7
0
def update_seller(*,
                  seller_id: str = Path(
                      ..., title="The seller ID as a valid ObjectId"),
                  Seller: SellerToUpdate,
                  CurrentUser: UserOut = Depends(get_current_user)):
    return format_result(Sellers.update_one(seller_id, Seller))
Beispiel #8
0
def get_seller_by_id(seller_id: str = Path(
    ..., title="The seller ID as a valid ObjectId")):
    return format_result(Sellers.get_one(seller_id))
Beispiel #9
0
async def get_sellers(skip: int = 0, limit: int = 100):
    return format_result(Sellers.get_many(skip, limit))