示例#1
0
def main(ARGS):

    productsAvailable, bundlesAvailable = getInputData(ARGS.products, ARGS.bundles)
    expectedProducts = readFile(ARGS.expected)

    discount = Cart.fillCartAndComputeDiscount(
        productsAvailable, bundlesAvailable, expectedProducts
    )

    print(f"{discount=}")

    return discount
示例#2
0
def test_no_products_in_cart():
    PATH = "tests/resources/noProductsInCart"

    productsAvailable, bundlesAvailable = getInputData(
        f"{PATH}/products.json", f"{PATH}/bundles.json"
    )

    expectedProducts = readFile(f"{PATH}/expected.txt")

    discount = Cart.fillCartAndComputeDiscount(
        productsAvailable, bundlesAvailable, expectedProducts
    )

    assert 0.0 == discount
示例#3
0
def test_cart_with_more_than_5_no_bundles():
    PATH = "tests/resources/moreThan5NoBundle"

    productsAvailable, bundlesAvailable = getInputData(
        f"{PATH}/products.json", f"{PATH}/bundles.json"
    )

    expectedProducts = readFile(f"{PATH}/expected.txt")

    discount = Cart.fillCartAndComputeDiscount(
        productsAvailable, bundlesAvailable, expectedProducts
    )

    assert 0.36 == discount
示例#4
0
def test_cart():
    PATH = "tests/resources/exampleGist"

    productsAvailable, bundlesAvailable = getInputData(
        f"{PATH}/products.json", f"{PATH}/bundles.json"
    )

    expectedProducts = readFile(f"{PATH}/expected.txt")

    discount = Cart.fillCartAndComputeDiscount(
        productsAvailable, bundlesAvailable, expectedProducts
    )

    assert 104.5 == discount
示例#5
0
def test_cart_step1():
    PATH = "tests/resources/exampleGist"

    productsAvailable, bundlesAvailable = getInputData(
        f"{PATH}/products.json", f"{PATH}/bundles.json"
    )

    expectedProducts = ["ABC"]

    discount = Cart.fillCartAndComputeDiscount(
        productsAvailable, bundlesAvailable, expectedProducts
    )

    assert 0.0 == discount
示例#6
0
def test_no_products():
    with pytest.raises(EmptyJsonFileException) as error:
        PATH = "tests/resources/noProducts"

        productsAvailable, bundlesAvailable = getInputData(
            f"{PATH}/products.json", f"{PATH}/bundles.json"
        )

        expectedProducts = readFile(f"{PATH}/expected.txt")

        discount = Cart.fillCartAndComputeDiscount(
            productsAvailable, bundlesAvailable, expectedProducts
        )

    assert error.type is EmptyJsonFileException