Beispiel #1
0
def test_close_closed_receipt(service: StoreService) -> None:
    result = service.open_receipt()
    assert result.success
    result = service.close_receipt()
    assert result.success
    result = service.close_receipt()
    assert not result.success
Beispiel #2
0
def test_adding_item_to_receipt(service: StoreService) -> None:
    result = service.open_receipt()
    assert result.success
    request = AddItemRequest(name="Beer", count=2, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    result = service.get_receipt()
    assert result.success
    assert result.receipt == str(
        Receipt([Item(name="Beer", count=2, single_price=1.2)])
    )
Beispiel #3
0
def test_make_x_report_multiple_closed_receipts(service: StoreService) -> None:
    result = service.open_receipt()
    assert result.success
    request = AddItemRequest(name="Bow", count=1, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Bow", count=2, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Sword", count=3, price=2.1)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Axe", count=4, price=1.3)
    result = service.add_item_to_receipt(request)
    assert result.success
    result = service.get_receipt()
    assert result.success
    items: List[IItem] = [
        Item(name="Bow", count=1, single_price=1.2),
        Item(name="Bow", count=2, single_price=1.2),
        Item(name="Sword", count=3, single_price=2.1),
        Item(name="Axe", count=4, single_price=1.3),
    ]
    assert result.receipt == str(Receipt(items))
    result = service.close_receipt()
    assert result.success
    result = service.make_x_report()
    assert result.success
    assert result.total_revenue == 15.1
    assert result.closed_receipts == 1
    sold_items = {"Bow": 3, "Sword": 3, "Axe": 4}
    assert result.sold_items == str(sold_items)
Beispiel #4
0
def test_one_customer_service(service: StoreService) -> None:
    result = service.open_receipt()
    assert result.success
    request = AddItemRequest(name="Milk", count=1, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Milk", count=2, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Diapers", count=3, price=2.1)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Guitar", count=4, price=1.3)
    result = service.add_item_to_receipt(request)
    assert result.success
    result = service.get_receipt()
    assert result.success
    assert result.receipt == str(
        Receipt(
            [
                Item(name="Milk", count=1, single_price=1.2),
                Item(name="Milk", count=2, single_price=1.2),
                Item(name="Diapers", count=3, single_price=2.1),
                Item(name="Guitar", count=4, single_price=1.3),
            ]
        )
    )
    result = service.close_receipt()
    assert result.success
    result = service.get_receipt()
    assert not result.success
    assert result.receipt == ""
Beispiel #5
0
def test_make_x_report_while_receipt_open(service: StoreService) -> None:
    result = service.open_receipt()
    assert result.success
    request = AddItemRequest(name="Milk", count=2, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    result = service.get_receipt()
    assert result.success
    assert result.receipt == str(
        Receipt([Item(name="Milk", count=2, single_price=1.2)])
    )
    result = service.make_x_report()
    assert result.success
    assert result.total_revenue == 0
    assert result.closed_receipts == 0
    assert result.sold_items == str(dict())
Beispiel #6
0
def setup() -> FastAPI:
    app = FastAPI()
    app.include_router(receipt_api)
    app.include_router(report_api)
    store_repository = SQLiteStoreRepository()
    app.state.core = StoreService.create(store_repository=store_repository)
    return app
Beispiel #7
0
def add_item(
        item_name: str,
        count: int,
        single_price: float,
        core: StoreService = Depends(get_core),
) -> Response:
    return core.add_item_to_receipt(
        request=AddItemRequest(item_name, count, single_price))
Beispiel #8
0
def test_make_x_report_closed_receipt(service: StoreService) -> None:
    result = service.open_receipt()
    assert result.success
    request = AddItemRequest(name="Milk", count=2, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    result = service.get_receipt()
    assert result.success
    item = Item(name="Milk", count=2, single_price=1.2)
    assert result.receipt == str(Receipt([item]))
    result = service.close_receipt()
    assert result.success
    result = service.make_x_report()
    assert result.success
    assert result.total_revenue == 2.4
    assert result.closed_receipts == 1
    assert result.sold_items == str(dict({item.get_name(): 2}))
Beispiel #9
0
def test_adding_multiple_items_to_receipt(service: StoreService) -> None:
    result = service.open_receipt()
    assert result.success
    request = AddItemRequest(name="Beer", count=1, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Milk", count=2, price=1.2)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Coca-Cola", count=3, price=2.1)
    result = service.add_item_to_receipt(request)
    assert result.success
    request = AddItemRequest(name="Pepsi", count=4, price=1.3)
    result = service.add_item_to_receipt(request)
    assert result.success
    result = service.get_receipt()
    assert result.success
    assert result.receipt == str(
        Receipt(
            [
                Item(name="Beer", count=1, single_price=1.2),
                Item(name="Milk", count=2, single_price=1.2),
                Item(name="Coca-Cola", count=3, single_price=2.1),
                Item(name="Pepsi", count=4, single_price=1.3),
            ]
        )
    )
Beispiel #10
0
def open_receipt(core: StoreService = Depends(get_core)) -> Response:
    return core.open_receipt()
Beispiel #11
0
def test_get_empty_receipt(service: StoreService) -> None:
    result = service.open_receipt()
    assert result.success
    result = service.get_receipt()
    assert result.success
    assert result.receipt == str(Receipt([]))
Beispiel #12
0
def test_add_item_to_inactive_receipt(service: StoreService) -> None:
    request = AddItemRequest(name="Beer", count=2, price=1.2)
    result = service.add_item_to_receipt(request)
    assert not result.success
Beispiel #13
0
def test_get_inactive_receipt(service: StoreService) -> None:
    result = service.get_receipt()
    assert not result.success
    assert result.receipt == ""
Beispiel #14
0
def get_receipt(core: StoreService = Depends(get_core)) -> GetReceiptResponse:
    response = core.get_receipt()
    # print(response.receipt)
    return response
Beispiel #15
0
def test_open_open_receipt(service: StoreService) -> None:
    service.open_receipt()
    result = service.open_receipt()
    assert not result.success
Beispiel #16
0
def make_x_report(core: StoreService = Depends(get_core)) -> XReportResponse:
    return core.make_x_report()
Beispiel #17
0
def test_make_x_report_empty(service: StoreService) -> None:
    result = service.make_x_report()
    assert result.success
    assert result.total_revenue == 0
    assert result.closed_receipts == 0
    assert result.sold_items == str(dict())
Beispiel #18
0
def service() -> StoreService:
    store_repository = InMemoryStoreRepository()
    return StoreService.create(store_repository=store_repository)
Beispiel #19
0
def close_receipt(core: StoreService = Depends(get_core)) -> Response:
    return core.close_receipt()