コード例 #1
0
ファイル: test_shipment.py プロジェクト: boxwise/boxtribute
def test_shipment_mutations_cancel(client, mocker, default_shipment,
                                   another_marked_for_shipment_box,
                                   another_shipment):
    # Test case 3.2.7
    shipment_id = str(default_shipment["id"])
    mutation = f"""mutation {{ cancelShipment(id: {shipment_id}) {{
                    id
                    state
                    canceledBy {{ id }}
                    canceledOn
                    details {{ id }}
                }} }}"""
    shipment = assert_successful_request(client, mutation)
    assert shipment.pop("canceledOn").startswith(date.today().isoformat())
    assert shipment == {
        "id": shipment_id,
        "state": ShipmentState.Canceled.name,
        "canceledBy": {
            "id": "8"
        },
        "details": [],
    }

    identifier = another_marked_for_shipment_box["label_identifier"]
    query = f"""query {{ box(labelIdentifier: "{identifier}") {{ state }} }}"""
    box = assert_successful_request(client, query)
    assert box == {"state": BoxState.InStock.name}

    # Shipment does not have any details assigned
    mocker.patch("jose.jwt.decode").return_value = create_jwt_payload(
        base_ids=[3], organisation_id=2, user_id=2)
    shipment_id = str(another_shipment["id"])
    mutation = f"""mutation {{ cancelShipment(id: {shipment_id}) {{ state }} }}"""
    shipment = assert_successful_request(client, mutation)
    assert shipment == {"state": ShipmentState.Canceled.name}
コード例 #2
0
def test_box_mutations(client, qr_code_without_box, default_size,
                       another_size):
    box_creation_input_string = f"""{{
                    productId: 1,
                    items: 9999,
                    locationId: 1,
                    comment: "",
                    sizeId: {default_size["id"]},
                    qrCode: "{qr_code_without_box["code"]}",
                }}"""
    mutation = f"""mutation {{
            createBox(
                boxCreationInput : {box_creation_input_string}
            ) {{
                id
                labelIdentifier
                items
                location {{ id }}
                product {{ id }}
                size
                qrCode {{ id }}
                state
                createdOn
                createdBy {{ id }}
                lastModifiedOn
                lastModifiedBy {{ id }}
            }}
        }}"""
    created_box = assert_successful_request(client, mutation)
    assert created_box["items"] == 9999
    assert created_box["state"] == "InStock"
    assert created_box["location"]["id"] == "1"
    assert created_box["product"]["id"] == "1"
    assert created_box["size"] == str(default_size["id"])
    assert created_box["qrCode"]["id"] == str(qr_code_without_box["id"])
    assert created_box["createdOn"] == created_box["lastModifiedOn"]
    assert created_box["createdBy"] == created_box["lastModifiedBy"]

    mutation = f"""mutation {{
            updateBox(
                boxUpdateInput : {{
                    items: 7777,
                    labelIdentifier: "{created_box["labelIdentifier"]}"
                    comment: "updatedComment"
                    sizeId: {another_size["id"]},
                }} ) {{
                items
                lastModifiedOn
                createdOn
                qrCode {{ id }}
                comment
                size
            }}
        }}"""
    updated_box = assert_successful_request(client, mutation)
    assert updated_box["comment"] == "updatedComment"
    assert updated_box["items"] == 7777
    assert updated_box["qrCode"] == created_box["qrCode"]
    assert updated_box["size"] == str(another_size["id"])
コード例 #3
0
def test_qr_exists_query(read_only_client, default_qr_code):
    code = default_qr_code["code"]
    query = f"""query CheckQrExistence {{
                qrExists(qrCode: "{code}")
            }}"""
    qr_exists = assert_successful_request(read_only_client, query)
    assert qr_exists

    query = """query CheckQrExistence {
                qrExists(qrCode: "111")
            }"""
    qr_exists = assert_successful_request(read_only_client, query)
    assert not qr_exists
コード例 #4
0
def test_user_query(read_only_client, default_users, default_organisation):
    test_id = 8
    expected_user = default_users[test_id]

    query = f"""query User {{
                user(id: {test_id}) {{
                    id
                    name
                    email
                    validFirstDay
                    validLastDay
                    bases {{ id }}
                    organisation {{ id }}
                    lastLogin
                    lastAction
                }}
            }}"""

    queried_user = assert_successful_request(read_only_client, query)
    assert int(queried_user["id"]) == test_id
    assert queried_user["name"] == expected_user["name"]
    assert queried_user["email"] == expected_user["email"]
    assert queried_user["validFirstDay"] == expected_user["valid_first_day"].isoformat()
    assert queried_user["lastLogin"][:-6] == expected_user["last_login"].isoformat()
    assert [int(b["id"]) for b in queried_user["bases"]] == [1]
    assert int(queried_user["organisation"]["id"]) == default_organisation["id"]
コード例 #5
0
def test_product_query(read_only_client, default_product):
    query = f"""query {{
                product(id: {default_product['id']}) {{
                    id
                    name
                    category {{
                        hasGender
                    }}
                    sizeRange {{ id }}
                    sizes
                    base {{ id }}
                    price
                    gender
                    createdBy {{ id }}
                }}
            }}"""
    queried_product = assert_successful_request(read_only_client, query)
    assert queried_product == {
        "id": str(default_product["id"]),
        "name": default_product["name"],
        "category": {"hasGender": True},
        "sizeRange": {"id": str(default_product["size_range"])},
        "sizes": [],
        "base": {"id": str(default_product["base"])},
        "price": default_product["price"],
        "gender": "Women",
        "createdBy": {"id": str(default_product["created_by"])},
    }
コード例 #6
0
ファイル: test_location.py プロジェクト: boxwise/boxtribute
def test_location_query(read_only_client, default_boxes, default_location):
    query = f"""query {{
                location(id: "{default_location['id']}") {{
                    id
                    base {{ id }}
                    name
                    isShop
                    boxes {{
                        elements {{ id }}
                    }}
                    boxState
                    createdOn
                    createdBy {{ id }}
                }}
            }}"""
    queried_location = assert_successful_request(read_only_client, query)
    assert queried_location == {
        "id": str(default_location["id"]),
        "base": {"id": str(default_location["base"])},
        "name": default_location["name"],
        "isShop": default_location["is_shop"],
        "boxes": {"elements": [{"id": str(b["id"])} for b in default_boxes[1:]]},
        "boxState": BoxState(default_location["box_state"]).name,
        "createdOn": None,
        "createdBy": {"id": str(default_location["created_by"])},
    }
コード例 #7
0
def test_metrics_query_number_of_beneficiaries_served(read_only_client,
                                                      filters, number):
    query = f"query {{ metrics {{ numberOfBeneficiariesServed{filters} }} }}"
    response = assert_successful_request(read_only_client,
                                         query,
                                         field="metrics")
    assert response == {"numberOfBeneficiariesServed": number}
コード例 #8
0
ファイル: test_location.py プロジェクト: boxwise/boxtribute
def test_locations_query(read_only_client, default_location):
    query = """query {
                locations {
                    name
                }
            }"""
    queried_location = assert_successful_request(read_only_client, query)[0]
    assert queried_location["name"] == default_location["name"]
コード例 #9
0
def test_metrics_query_number_of_sales(read_only_client, default_transaction,
                                       filters, number):
    query = f"query {{ metrics {{ numberOfSales{filters} }} }}"
    response = assert_successful_request(read_only_client,
                                         query,
                                         field="metrics")
    # The two test transactions have a count of 2 each
    count = default_transaction["count"]
    assert response == {"numberOfSales": number * count}
コード例 #10
0
ファイル: test_operations.py プロジェクト: boxwise/boxtribute
 def create_shipment():
     mutation = """mutation { createShipment(creationInput: {
                     transferAgreementId: 1,
                     sourceBaseId: 1,
                     targetBaseId: 3
                 }) { id state } }"""
     response = assert_successful_request(auth0_client, mutation)
     shipment_id = response.pop("id")
     assert response == {"state": "Preparing"}
     return shipment_id
コード例 #11
0
def test_box_query_by_qr_code(read_only_client, default_box, default_qr_code):
    query = f"""query {{
                qrCode(qrCode: "{default_qr_code['code']}") {{
                    box {{
                        labelIdentifier
                    }}
                }}
            }}"""
    queried_box = assert_successful_request(read_only_client, query)["box"]
    assert queried_box["labelIdentifier"] == default_box["label_identifier"]
コード例 #12
0
def test_metrics_query_stock_overview(read_only_client, default_transaction,
                                      default_boxes):
    query = "query { metrics { stockOverview { numberOfBoxes numberOfItems } } }"
    response = assert_successful_request(read_only_client,
                                         query,
                                         field="metrics")
    boxes = default_boxes[1:]  # only boxes managed by client's organisation
    assert response == {
        "stockOverview": {
            "numberOfBoxes": len(boxes),
            "numberOfItems": sum(b["items"] for b in boxes),
        }
    }
コード例 #13
0
ファイル: test_shipment.py プロジェクト: boxwise/boxtribute
def test_shipment_query(read_only_client, default_shipment,
                        prepared_shipment_detail):
    # Test case 3.1.2
    shipment_id = str(default_shipment["id"])
    query = f"""query {{
                shipment(id: {shipment_id}) {{
                    id
                    sourceBase {{ id }}
                    targetBase {{ id }}
                    state
                    startedBy {{ id }}
                    startedOn
                    sentBy {{ id }}
                    sentOn
                    completedBy {{ id }}
                    completedOn
                    canceledBy {{ id }}
                    canceledOn
                    transferAgreement {{ id }}
                    details {{ id }}
                }}
            }}"""
    shipment = assert_successful_request(read_only_client, query)
    assert shipment == {
        "id": shipment_id,
        "sourceBase": {
            "id": str(default_shipment["source_base"])
        },
        "targetBase": {
            "id": str(default_shipment["target_base"])
        },
        "state": default_shipment["state"].name,
        "startedBy": {
            "id": str(default_shipment["started_by"])
        },
        "startedOn": default_shipment["started_on"].isoformat() + "+00:00",
        "sentBy": None,
        "sentOn": None,
        "completedBy": None,
        "completedOn": None,
        "canceledBy": None,
        "canceledOn": None,
        "transferAgreement": {
            "id": str(default_shipment["transfer_agreement"])
        },
        "details": [{
            "id": str(prepared_shipment_detail["id"])
        }],
    }
コード例 #14
0
def test_qr_code_mutation(client, box_without_qr_code):
    mutation = "mutation { createQrCode { id } }"
    qr_code = assert_successful_request(client, mutation)
    qr_code_id = int(qr_code["id"])
    assert qr_code_id > 2

    mutation = f"""mutation {{
        createQrCode(boxLabelIdentifier: "{box_without_qr_code['label_identifier']}")
        {{
            id
            box {{
                id
                items
            }}
        }}
    }}"""
    created_qr_code = assert_successful_request(client, mutation)
    assert int(created_qr_code["id"]) == qr_code_id + 1
    assert created_qr_code["box"]["items"] == box_without_qr_code["items"]
    assert int(created_qr_code["box"]["id"]) == box_without_qr_code["id"]

    assert_bad_user_input(
        client,
        """mutation { createQrCode(boxLabelIdentifier: "xxx") { id } }""")
コード例 #15
0
ファイル: test_shipment.py プロジェクト: boxwise/boxtribute
def test_shipments_query(
    read_only_client,
    default_shipment,
    canceled_shipment,
    another_shipment,
    sent_shipment,
):
    # Test case 3.1.1
    query = "query { shipments { id } }"
    shipments = assert_successful_request(read_only_client, query)
    assert shipments == [
        {
            "id": str(s["id"])
        } for s in
        [default_shipment, canceled_shipment, another_shipment, sent_shipment]
    ]
コード例 #16
0
def test_boxes_query_filter(read_only_client, default_location, filters,
                            number):
    filter_input = ", ".join(f"{k}: {v}" for f in filters
                             for k, v in f.items())
    query = f"""query {{ location(id: {default_location['id']}) {{
                boxes(filterInput: {{ {filter_input} }}) {{
                    elements {{ id state }}
                }} }} }}"""
    location = assert_successful_request(read_only_client, query)
    boxes = location["boxes"]["elements"]
    assert len(boxes) == number

    for f in filters:
        if "states" in f and number > 0:
            states = f["states"].strip("[]").split(",")
            assert {b["state"] for b in boxes} == set(states)
コード例 #17
0
def test_organisation_query(read_only_client, default_bases,
                            default_organisation):
    query = f"""query {{
                organisation(id: "{default_organisation['id']}") {{
                    id
                    name
                    bases {{ id }}
                }}
            }}"""
    queried_organisation = assert_successful_request(read_only_client, query)
    assert queried_organisation == {
        "id": str(default_organisation["id"]),
        "name": default_organisation["name"],
        "bases": [{
            "id": str(b["id"])
        } for b in list(default_bases.values())[:2]],
    }
コード例 #18
0
def test_metrics_query_for_god_user(
    read_only_client,
    mocker,
    organisation_id,
    number_of_families_served,
    number_of_sales,
):
    mocker.patch("jose.jwt.decode").return_value = create_jwt_payload(
        permissions=["*"], organisation_id=None)
    query = f"""query {{ metrics(organisationId: {organisation_id}) {{
                numberOfFamiliesServed numberOfSales }} }}"""
    response = assert_successful_request(read_only_client,
                                         query,
                                         field="metrics")
    assert response == {
        "numberOfFamiliesServed": number_of_families_served,
        "numberOfSales": number_of_sales,
    }
コード例 #19
0
def test_qr_code_query(read_only_client, default_box, default_qr_code):
    code = default_qr_code["code"]
    query = f"""query {{
                qrCode(qrCode: "{code}") {{
                    id
                    code
                    box {{ id }}
                    createdOn
                }}
            }}"""
    queried_code = assert_successful_request(read_only_client, query)
    assert queried_code == {
        "id": str(default_qr_code["id"]),
        "code": code,
        "box": {
            "id": str(default_box["id"])
        },
        "createdOn": None,
    }
コード例 #20
0
def test_bases_query(read_only_client, default_bases, default_beneficiaries):
    query = """query {
                bases {
                    id
                    name
                    currencyName
                    beneficiaries { elements { id } }
                }
            }"""

    all_bases = assert_successful_request(read_only_client, query)
    assert len(all_bases) == 1

    queried_base = all_bases[0]
    queried_base_id = int(queried_base["id"])
    expected_base = default_bases[queried_base_id]

    assert queried_base_id == expected_base["id"]
    assert queried_base["name"] == expected_base["name"]
    assert queried_base["currencyName"] == expected_base["currency_name"]
    assert len(queried_base["beneficiaries"]["elements"]) == len(default_beneficiaries)
コード例 #21
0
def test_base_query(read_only_client, default_location, default_bases):
    test_id = 1
    query = f"""query Base {{
                base(id: {test_id}) {{
                    id
                    name
                    organisation {{ id }}
                    currencyName
                    locations {{ id }}
                }}
            }}"""

    base = assert_successful_request(read_only_client, query)
    expected_base = default_bases[test_id]
    assert int(base["id"]) == expected_base["id"]
    assert base["name"] == expected_base["name"]
    assert base["currencyName"] == expected_base["currency_name"]
    assert int(base["organisation"]["id"]) == expected_base["organisation"]

    locations = base["locations"]
    assert {"id": str(default_location["id"])} in locations
コード例 #22
0
def test_box_query_by_label_identifier(
    read_only_client,
    default_box,
):
    label_identifier = default_box["label_identifier"]
    query = f"""query {{
                box(labelIdentifier: "{label_identifier}") {{
                    id
                    labelIdentifier
                    location {{ id }}
                    items
                    product {{ id }}
                    size
                    state
                    qrCode {{ id }}
                    createdBy {{ id }}
                    comment
                }}
            }}"""
    queried_box = assert_successful_request(read_only_client, query)
    assert queried_box == {
        "id": str(default_box["id"]),
        "labelIdentifier": label_identifier,
        "location": {
            "id": str(default_box["location"])
        },
        "items": default_box["items"],
        "product": {
            "id": str(default_box["product"])
        },
        "size": str(default_box["size"]),
        "state": BoxState.InStock.name,
        "qrCode": {
            "id": str(default_box["qr_code"])
        },
        "createdBy": {
            "id": str(default_box["created_by"])
        },
        "comment": default_box["comment"],
    }
コード例 #23
0
def test_metrics_query_moved_stock_overview(read_only_client,
                                            default_transaction, default_boxes,
                                            filters, box_ids):
    query = f"""query {{ metrics {{ movedStockOverview{filters} {{
                productCategoryName numberOfBoxes numberOfItems }} }} }}"""
    response = assert_successful_request(read_only_client,
                                         query,
                                         field="metrics")

    boxes = [b for b in default_boxes if b["id"] in box_ids]
    number_of_boxes = len(boxes)
    if number_of_boxes == 0:
        assert response == {"movedStockOverview": []}
    else:
        assert response == {
            "movedStockOverview": [{
                "productCategoryName":
                "Underwear / Nightwear",
                "numberOfBoxes":
                number_of_boxes,
                "numberOfItems":
                sum(b["items"] for b in boxes),
            }]
        }
コード例 #24
0
ファイル: test_shipment.py プロジェクト: boxwise/boxtribute
def test_shipment_mutations_on_source_side(
    client,
    default_bases,
    default_transfer_agreement,
    default_shipment,
    default_box,
    another_box,
    another_marked_for_shipment_box,
    lost_box,
    marked_for_shipment_box,
    prepared_shipment_detail,
):
    # Test case 3.2.1a
    source_base_id = default_bases[2]["id"]
    target_base_id = default_bases[3]["id"]
    agreement_id = default_transfer_agreement["id"]
    creation_input = f"""sourceBaseId: {source_base_id},
                         targetBaseId: {target_base_id},
                         transferAgreementId: {agreement_id}"""
    mutation = f"""mutation {{ createShipment(creationInput: {{ {creation_input} }} ) {{
                    id
                    sourceBase {{ id }}
                    targetBase {{ id }}
                    state
                    startedBy {{ id }}
                    startedOn
                    sentBy {{ id }}
                    sentOn
                    completedBy {{ id }}
                    completedOn
                    canceledBy {{ id }}
                    canceledOn
                    transferAgreement {{ id }}
                    details {{ id }}
                }} }}"""
    shipment = assert_successful_request(client, mutation)
    shipment_id = str(shipment.pop("id"))
    assert shipment.pop("startedOn").startswith(date.today().isoformat())
    assert shipment == {
        "sourceBase": {
            "id": str(source_base_id)
        },
        "targetBase": {
            "id": str(target_base_id)
        },
        "state": ShipmentState.Preparing.name,
        "startedBy": {
            "id": "8"
        },
        "sentBy": None,
        "sentOn": None,
        "completedBy": None,
        "completedOn": None,
        "canceledBy": None,
        "canceledOn": None,
        "transferAgreement": {
            "id": str(agreement_id)
        },
        "details": [],
    }

    # Test case 3.2.20
    shipment_id = str(default_shipment["id"])
    update_input = f"""{{ id: {shipment_id},
                targetBaseId: {target_base_id} }}"""
    mutation = f"""mutation {{ updateShipment(updateInput: {update_input}) {{
                    id
                    state
                    targetBase {{ id }}
                }} }}"""
    shipment = assert_successful_request(client, mutation)
    assert shipment == {
        "id": shipment_id,
        "state": ShipmentState.Preparing.name,
        "targetBase": {
            "id": str(target_base_id)
        },
    }

    # Test case 3.2.26
    box_label_identifier = default_box["label_identifier"]
    update_input = f"""{{ id: {shipment_id},
                preparedBoxLabelIdentifiers: ["{box_label_identifier}"] }}"""
    mutation = f"""mutation {{ updateShipment(updateInput: {update_input}) {{
                    id
                    state
                    details {{
                        id
                        shipment {{ id }}
                        box {{
                            id
                            state
                        }}
                        sourceProduct {{ id }}
                        targetProduct {{ id }}
                        sourceLocation {{ id }}
                        targetLocation {{ id }}
                        createdBy {{ id }}
                        createdOn
                        deletedBy {{ id }}
                        deletedOn
                    }}
                }} }}"""
    shipment = assert_successful_request(client, mutation)
    assert shipment["details"][0].pop("createdOn").startswith(
        date.today().isoformat())
    assert shipment["details"][1].pop("createdOn").startswith(
        date.today().isoformat())
    shipment_detail_id = shipment["details"][1].pop("id")
    prepared_shipment_detail_id = str(prepared_shipment_detail["id"])
    assert shipment == {
        "id":
        shipment_id,
        "state":
        ShipmentState.Preparing.name,
        "details": [
            {
                "id": prepared_shipment_detail_id,
                "shipment": {
                    "id": shipment_id
                },
                "box": {
                    "id": str(another_marked_for_shipment_box["id"]),
                    "state": BoxState.MarkedForShipment.name,
                },
                "sourceProduct": {
                    "id": str(another_marked_for_shipment_box["product"])
                },
                "targetProduct": None,
                "sourceLocation": {
                    "id": str(another_marked_for_shipment_box["location"])
                },
                "targetLocation": None,
                "createdBy": {
                    "id": "1"
                },
                "deletedBy": None,
                "deletedOn": None,
            },
            {
                "shipment": {
                    "id": shipment_id
                },
                "box": {
                    "id": str(default_box["id"]),
                    "state": BoxState.MarkedForShipment.name,
                },
                "sourceProduct": {
                    "id": str(default_box["product"])
                },
                "targetProduct": None,
                "sourceLocation": {
                    "id": str(default_box["location"])
                },
                "targetLocation": None,
                "createdBy": {
                    "id": "8"
                },
                "deletedBy": None,
                "deletedOn": None,
            },
        ],
    }

    # Verify that another_box is not added to shipment (not located in source base).
    # Same for lost_box (box state different from InStock) and default_box (already
    # added to shipment, hence box state MarkedForShipment different from InStock).
    # A box with unknown label identifier is not added either
    # Test cases 3.2.27, 3.2.28, 3.2.29
    non_existent_box = {"label_identifier": "xxx"}
    for box in [another_box, lost_box, default_box, non_existent_box]:
        box_label_identifier = box["label_identifier"]
        update_input = f"""{{ id: {shipment_id},
                    preparedBoxLabelIdentifiers: ["{box_label_identifier}"] }}"""
        mutation = f"""mutation {{ updateShipment(updateInput: {update_input}) {{
                        details {{ id }}
                    }} }}"""
        shipment = assert_successful_request(client, mutation)
        assert shipment == {
            "details": [{
                "id": i
            } for i in [prepared_shipment_detail_id, shipment_detail_id]]
        }

    # Test case 3.2.30
    boxes = [default_box, another_marked_for_shipment_box]
    box_label_identifiers = ",".join(f'"{b["label_identifier"]}"'
                                     for b in boxes)
    update_input = f"""{{ id: {shipment_id},
                removedBoxLabelIdentifiers: [{box_label_identifiers}] }}"""
    mutation = f"""mutation {{ updateShipment(updateInput: {update_input}) {{
                    id
                    state
                    details {{ id }}
                }} }}"""
    shipment = assert_successful_request(client, mutation)
    assert shipment == {
        "id": shipment_id,
        "state": ShipmentState.Preparing.name,
        "details": [],
    }
    for box in boxes:
        box_label_identifier = box["label_identifier"]
        query = f"""query {{ box(labelIdentifier: "{box_label_identifier}") {{
                        state }} }}"""
        box_response = assert_successful_request(client, query)
        assert box_response == {"state": BoxState.InStock.name}

    # Verify that lost_box is not removed from shipment (box state different from
    # MarkedForShipment).
    # Same for marked_for_shipment_box (not part of shipment), and non-existent box
    # Test cases 3.2.31, 3.2.32
    boxes = [lost_box, marked_for_shipment_box]
    for box in boxes + [non_existent_box]:
        box_label_identifier = box["label_identifier"]
        update_input = f"""{{ id: {shipment_id},
                    removedBoxLabelIdentifiers: ["{box_label_identifier}"] }}"""
        mutation = f"""mutation {{ updateShipment(updateInput: {update_input}) {{
                        details {{ id }}
                    }} }}"""
        shipment = assert_successful_request(client, mutation)
        assert shipment == {"details": []}
    for box in boxes:
        box_label_identifier = box["label_identifier"]
        query = f"""query {{ box(labelIdentifier: "{box_label_identifier}") {{
                        state }} }}"""
        box_response = assert_successful_request(client, query)
        assert box_response == {"state": BoxState(box["state"]).name}

    # Test case 3.2.11
    mutation = f"""mutation {{ sendShipment(id: {shipment_id}) {{
                    id
                    state
                    sentBy {{ id }}
                    sentOn
                }} }}"""
    shipment = assert_successful_request(client, mutation)
    assert shipment.pop("sentOn").startswith(date.today().isoformat())
    assert shipment == {
        "id": shipment_id,
        "state": ShipmentState.Sent.name,
        "sentBy": {
            "id": "8"
        },
    }
コード例 #25
0
ファイル: test_operations.py プロジェクト: boxwise/boxtribute
 def _assert_successful_request(*args, **kwargs):
     return assert_successful_request(*args, **kwargs, endpoint=endpoint)
コード例 #26
0
def test_transfer_agreement_query(read_only_client, default_transfer_agreement,
                                  default_shipment, sent_shipment):
    # Test case 2.1.3
    agreement_id = str(default_transfer_agreement["id"])
    query = f"""query {{
                transferAgreement(id: {agreement_id}) {{
                    id
                    sourceOrganisation {{ id }}
                    targetOrganisation {{ id }}
                    state
                    type
                    requestedBy {{ id }}
                    requestedOn
                    acceptedBy {{ id }}
                    acceptedOn
                    terminatedBy {{ id }}
                    terminatedOn
                    validFrom
                    validUntil
                    comment
                    sourceBases {{ id }}
                    targetBases {{ id }}
                    shipments {{ id }}
                }}
            }}"""
    agreement = assert_successful_request(read_only_client, query)
    assert agreement == {
        "id":
        agreement_id,
        "sourceOrganisation": {
            "id": str(default_transfer_agreement["source_organisation"])
        },
        "targetOrganisation": {
            "id": str(default_transfer_agreement["target_organisation"])
        },
        "state":
        default_transfer_agreement["state"].name,
        "type":
        default_transfer_agreement["type"].name,
        "requestedBy": {
            "id": str(default_transfer_agreement["requested_by"])
        },
        "requestedOn":
        default_transfer_agreement["requested_on"].isoformat() + "+00:00",
        "acceptedBy":
        None,
        "acceptedOn":
        None,
        "terminatedBy":
        None,
        "terminatedOn":
        None,
        "comment":
        default_transfer_agreement["comment"],
        "validFrom":
        default_transfer_agreement["valid_from"].isoformat() + "+00:00",
        "validUntil":
        None,
        "sourceBases": [{
            "id": "1"
        }, {
            "id": "2"
        }],
        "targetBases": [{
            "id": "3"
        }],
        "shipments": [{
            "id": str(s["id"])
        } for s in [default_shipment, sent_shipment]],
    }
コード例 #27
0
def test_transfer_agreement_mutations(
    client,
    default_organisation,
    another_organisation,
    mocker,
):
    def _create_mutation(creation_input):
        return f"""mutation {{ createTransferAgreement(
                    creationInput: {{ {creation_input} }}
                    ) {{
                        id
                        sourceOrganisation {{ id }}
                        targetOrganisation {{ id }}
                        state
                        type
                        requestedBy {{ id }}
                        validFrom
                        validUntil
                        sourceBases {{ id }}
                        targetBases {{ id }}
                        shipments {{ id }}
                    }}
                }}"""

    # Leave all optional fields empty in input
    # Test case 2.2.1
    creation_input = f"""targetOrganisationId: {another_organisation['id']},
        type: {TransferAgreementType.Bidirectional.name}"""
    agreement = assert_successful_request(client,
                                          _create_mutation(creation_input))
    first_agreement_id = agreement.pop("id")
    assert agreement.pop("validFrom").startswith(date.today().isoformat())
    assert agreement == {
        "sourceOrganisation": {
            "id": str(default_organisation["id"])
        },
        "targetOrganisation": {
            "id": str(another_organisation["id"])
        },
        "state": TransferAgreementState.UnderReview.name,
        "type": TransferAgreementType.Bidirectional.name,
        "requestedBy": {
            "id": "8"
        },
        "validUntil": None,
        "sourceBases": [{
            "id": "1"
        }, {
            "id": "2"
        }],
        "targetBases": [{
            "id": "3"
        }, {
            "id": "4"
        }],
        "shipments": [],
    }

    # Provide all available fields in input
    # Test case 2.2.2
    valid_from = "2021-12-15"
    valid_until = "2022-06-30"
    creation_input = f"""targetOrganisationId: {another_organisation['id']},
        type: {TransferAgreementType.Bidirectional.name},
        validFrom: "{valid_from}",
        validUntil: "{valid_until}",
        timezone: "Europe/London",
        sourceBaseIds: [1],
        targetBaseIds: [3]"""
    agreement = assert_successful_request(client,
                                          _create_mutation(creation_input))
    second_agreement_id = agreement.pop("id")
    assert agreement.pop("validFrom").startswith(valid_from)
    assert agreement.pop("validUntil").startswith(valid_until)
    assert agreement == {
        "sourceOrganisation": {
            "id": str(default_organisation["id"])
        },
        "targetOrganisation": {
            "id": str(another_organisation["id"])
        },
        "state": TransferAgreementState.UnderReview.name,
        "type": TransferAgreementType.Bidirectional.name,
        "requestedBy": {
            "id": "8"
        },
        "sourceBases": [{
            "id": "1"
        }],
        "targetBases": [{
            "id": "3"
        }],
        "shipments": [],
    }

    mocker.patch("jose.jwt.decode").return_value = create_jwt_payload(
        base_ids=[3], organisation_id=2, user_id=2)
    # Test case 2.2.3
    mutation = f"""mutation {{ acceptTransferAgreement(id: {first_agreement_id}) {{
                    state
                    acceptedBy {{ id }}
                    acceptedOn
                }}
            }}"""
    agreement = assert_successful_request(client, mutation)
    assert agreement.pop("acceptedOn").startswith(date.today().isoformat())
    assert agreement == {
        "state": TransferAgreementState.Accepted.name,
        "acceptedBy": {
            "id": "2"
        },
    }

    # Test case 2.2.7
    mutation = f"""mutation {{ cancelTransferAgreement(id: {first_agreement_id}) {{
                    state
                    terminatedBy {{ id }}
                    terminatedOn
                }}
            }}"""
    agreement = assert_successful_request(client, mutation)
    assert agreement.pop("terminatedOn").startswith(date.today().isoformat())
    assert agreement == {
        "state": TransferAgreementState.Canceled.name,
        "terminatedBy": {
            "id": "2"
        },
    }

    # Test case 2.2.5
    mutation = f"""mutation {{ rejectTransferAgreement(id: {second_agreement_id}) {{
                    state
                    terminatedBy {{ id }}
                    terminatedOn
                }}
            }}"""
    agreement = assert_successful_request(client, mutation)
    assert agreement.pop("terminatedOn").startswith(date.today().isoformat())
    assert agreement == {
        "state": TransferAgreementState.Rejected.name,
        "terminatedBy": {
            "id": "2"
        },
    }
コード例 #28
0
def test_transfer_agreements_query(read_only_client, filter_input,
                                   transfer_agreement_ids):
    # Test cases 2.1.1, 2.1.2
    query = f"""query {{ transferAgreements{filter_input} {{ id }} }}"""
    agreements = assert_successful_request(read_only_client, query)
    assert agreements == [{"id": i} for i in transfer_agreement_ids]
コード例 #29
0
ファイル: test_shipment.py プロジェクト: boxwise/boxtribute
def test_shipment_mutations_on_target_side(
    client,
    mocker,
    default_transfer_agreement,
    unidirectional_transfer_agreement,
    default_bases,
    sent_shipment,
    default_shipment_detail,
    another_shipment_detail,
    another_location,
    another_product,
    default_product,
    default_location,
    box_without_qr_code,
    marked_for_shipment_box,
):
    mocker.patch("jose.jwt.decode").return_value = create_jwt_payload(
        base_ids=[3], organisation_id=2, user_id=2)

    # Test cases 3.2.1b, 3.2.1c
    for agreement in [
            default_transfer_agreement, unidirectional_transfer_agreement
    ]:
        source_base_id = str(default_bases[3]["id"])
        target_base_id = str(default_bases[2]["id"])
        agreement_id = agreement["id"]
        creation_input = f"""sourceBaseId: {source_base_id},
                             targetBaseId: {target_base_id},
                             transferAgreementId: {agreement_id}"""
        mutation = f"""mutation {{ createShipment(creationInput: {{ {creation_input} }})
                    {{
                        sourceBase {{ id }}
                        targetBase {{ id }}
                        state
                    }} }}"""
        shipment = assert_successful_request(client, mutation)
        assert shipment == {
            "sourceBase": {
                "id": source_base_id
            },
            "targetBase": {
                "id": target_base_id
            },
            "state": ShipmentState.Preparing.name,
        }

    target_product_id = str(another_product["id"])
    target_location_id = str(another_location["id"])
    shipment_id = str(sent_shipment["id"])
    detail_id = str(default_shipment_detail["id"])
    another_detail_id = str(another_shipment_detail["id"])

    def _create_mutation(*, detail_id, target_product_id, target_location_id):
        update_input = f"""id: {shipment_id},
                receivedShipmentDetailUpdateInputs: {{
                        id: {detail_id},
                        targetProductId: {target_product_id},
                        targetLocationId: {target_location_id}
                    }}"""
        return f"""mutation {{ updateShipment(updateInput: {{ {update_input} }}) {{
                        id
                        state
                        completedBy {{ id }}
                        completedOn
                        details {{
                            id
                            targetProduct {{ id }}
                            targetLocation {{ id }}
                            box {{
                                state
                            }}
                        }}
                    }} }}"""

    # Test case 3.2.34a
    shipment = assert_successful_request(
        client,
        _create_mutation(
            detail_id=detail_id,
            target_product_id=target_product_id,
            target_location_id=target_location_id,
        ),
    )
    expected_shipment = {
        "id":
        shipment_id,
        "state":
        ShipmentState.Sent.name,
        "completedBy":
        None,
        "completedOn":
        None,
        "details": [
            {
                "id": detail_id,
                "box": {
                    "state": BoxState.Received.name
                },
                "targetProduct": {
                    "id": target_product_id
                },
                "targetLocation": {
                    "id": target_location_id
                },
            },
            {
                "id": another_detail_id,
                "box": {
                    "state": BoxState.MarkedForShipment.name
                },
                "targetProduct": None,
                "targetLocation": None,
            },
        ],
    }
    assert shipment == expected_shipment

    # Verify that another_detail_id is not updated (invalid product)
    # Test cases 3.2.39ab
    for product in [default_product, {"id": 0}]:
        shipment = assert_successful_request(
            client,
            _create_mutation(
                detail_id=another_detail_id,
                target_product_id=product["id"],
                target_location_id=target_location_id,
            ),
        )
        assert shipment == expected_shipment

    # Verify that another_detail_id is not updated (invalid location)
    # Test cases 3.2.38ab
    for location in [default_location, {"id": 0}]:
        shipment = assert_successful_request(
            client,
            _create_mutation(
                detail_id=another_detail_id,
                target_product_id=target_product_id,
                target_location_id=location["id"],
            ),
        )
        assert shipment == expected_shipment

    # Test case 3.2.40, 3.2.34b
    box_label_identifier = marked_for_shipment_box["label_identifier"]
    mutation = f"""mutation {{ updateShipment( updateInput: {{
                id: {shipment_id},
                lostBoxLabelIdentifiers: ["{box_label_identifier}"]
            }} ) {{
                id
                state
                completedBy {{ id }}
                completedOn
                details {{ id }}
            }} }}"""
    shipment = assert_successful_request(client, mutation)
    assert shipment.pop("completedOn").startswith(date.today().isoformat())
    assert shipment == {
        "id": shipment_id,
        "state": ShipmentState.Completed.name,
        "completedBy": {
            "id": "2"
        },
        "details": [],
    }
    box_label_identifier = box_without_qr_code["label_identifier"]
    query = f"""query {{ box(labelIdentifier: "{box_label_identifier}") {{
                    state
                    product {{ id }}
                    location {{ id }}
    }} }}"""
    box = assert_successful_request(client, query)
    assert box == {
        "state": BoxState.InStock.name,
        "product": {
            "id": target_product_id
        },
        "location": {
            "id": target_location_id
        },
    }

    # The box is still registered in the source base, hence any user from the target
    # organisation can't access it
    mocker.patch("jose.jwt.decode").return_value = create_jwt_payload()
    box_label_identifier = marked_for_shipment_box["label_identifier"]
    query = f"""query {{ box(labelIdentifier: "{box_label_identifier}") {{
                    state }} }}"""
    box = assert_successful_request(client, query)
    assert box == {"state": BoxState.Lost.name}
コード例 #30
0
ファイル: test_shipment.py プロジェクト: boxwise/boxtribute
def test_shipment_mutations_update_without_arguments(read_only_client,
                                                     default_shipment):
    # Test case 3.2.33
    mutation = _generate_update_shipment_mutation(shipment=default_shipment)
    shipment = assert_successful_request(read_only_client, mutation)
    assert shipment == {"id": str(default_shipment["id"])}