コード例 #1
0
def test_get_piers_filter_error_both_filters(api_client, berth_application,
                                             berth):
    query = """
        {
            piers(forApplication: "%s", minBerthWidth: 1.0, minBerthLength: 1.0) {
                edges {
                    node {
                        id
                        properties {
                            berths {
                                edges {
                                    node {
                                        id
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    """ % to_global_id(BerthApplicationNode._meta.name, berth_application.id)

    executed = api_client.execute(query)

    assert_in_errors(
        "You cannot filter by dimension (width, length) and application a the same time",
        executed,
    )
def test_update_berth_application_no_customer_id(
        api_client, berth_application_with_customer, status):
    berth_application_with_customer.lease = BerthLeaseFactory()
    berth_application_with_customer.status = status
    berth_application_with_customer.save()
    application_id = to_global_id(BerthApplicationNode,
                                  berth_application_with_customer.id)
    variables = {
        "id": application_id,
        "customerId": None,
    }

    executed = api_client.execute(UPDATE_BERTH_APPLICATION_MUTATION,
                                  input=variables)

    if status == ApplicationStatus.PENDING:
        assert executed == {
            "data": {
                "updateBerthApplication": {
                    "berthApplication": {
                        "id": application_id,
                        "customer": None
                    }
                }
            }
        }
    else:
        assert_in_errors(
            "Customer cannot be disconnected from processed applications",
            executed)
def test_update_winter_storage_application_no_customer_id(
        api_client, winter_storage_application_with_customer, status):
    winter_storage_application_with_customer.status = status
    winter_storage_application_with_customer.save()
    application_id = to_global_id(WinterStorageApplicationNode,
                                  winter_storage_application_with_customer.id)
    variables = {
        "id": application_id,
        "customerId": None,
    }

    executed = api_client.execute(UPDATE_WINTER_STORAGE_APPLICATION_MUTATION,
                                  input=variables)

    if status == ApplicationStatus.PENDING:
        assert executed == {
            "data": {
                "updateWinterStorageApplication": {
                    "winterStorageApplication": {
                        "id": application_id,
                        "customer": None,
                    }
                }
            }
        }
    else:
        assert_in_errors(
            "Customer cannot be disconnected from processed applications",
            executed)
コード例 #4
0
def test_fulfill_contract_no_contract_for_order(superuser_api_client,
                                                order: Order):
    order.lease.contract = None
    order.lease.save()
    order.order_number = FULFILL_CONTRACT_MUTATION_INPUT["orderNumber"]
    order.save()
    executed = superuser_api_client.execute(
        FULFILL_CONTRACT_MUTATION, input=FULFILL_CONTRACT_MUTATION_INPUT)
    assert_in_errors("No contract found for given order", executed)
def test_set_stickers_posted_error_when_no_sticker_number(
        superuser_api_client, winter_storage_lease):
    lease_id = to_global_id(WinterStorageLeaseNode, winter_storage_lease.id)
    variables = {"leaseIds": [lease_id], "date": today()}

    executed = superuser_api_client.execute(SET_STICKERS_POSTED_MUTATION,
                                            input=variables)

    assert_in_errors("All leases must have an assigned sticker number",
                     executed)
コード例 #6
0
def test_create_my_berth_profile_does_not_exist(user_api_client):
    variables = {"profileToken": "token"}
    with mock.patch(
        "customers.services.profile.requests.post",
        side_effect=mocked_response_my_profile(None),
    ):
        executed = user_api_client.execute(
            CREATE_MY_BERTH_PROFILE_MUTATION, input=variables
        )

    assert_in_errors("Open city profile not found", executed)
def test_assign_new_sticker_number_error_when_unpaid(sticker_sequences,
                                                     superuser_api_client,
                                                     winter_storage_lease):
    variables = {
        "leaseId": to_global_id(WinterStorageLeaseNode,
                                winter_storage_lease.id)
    }

    executed = superuser_api_client.execute(CONFIRM_PAYMENT_MUTATION,
                                            input=variables)

    assert_in_errors("Lease must be in PAID status", executed)
コード例 #8
0
def test_cancel_unmarked_order_fails(superuser_api_client, order: Order):
    order.status = OrderStatus.OFFERED
    order.save()
    variables = {"orderNumber": order.order_number}

    with mock.patch(
        "payments.providers.bambora_payform.requests.post",
        side_effect=mocked_response_create,
    ):
        executed = superuser_api_client.execute(CANCEL_ORDER_MUTATION, input=variables)

    assert_in_errors("Cannot cancel Unmarked winter storage order", executed)
コード例 #9
0
def test_winter_storage_applications_statuses_filter_invalid_enum(
        handled_ws_application, superuser_api_client):
    nonexistent_enum_str = "FOOBAR"

    query = (WINTER_STORAGE_APPLICATIONS_WITH_STATUSES_FILTER_QUERY %
             nonexistent_enum_str)

    executed = superuser_api_client.execute(query)

    assert_in_errors(
        "invalid value [%s]." % nonexistent_enum_str,
        executed,
    )
コード例 #10
0
def test_cancel_order_invalid_status(
    superuser_api_client, order: Order, status: OrderStatus
):
    order.status = status
    order.save()
    variables = {"orderNumber": order.order_number}

    with mock.patch(
        "payments.providers.bambora_payform.requests.post",
        side_effect=mocked_response_create,
    ):
        executed = superuser_api_client.execute(CANCEL_ORDER_MUTATION, input=variables)

    assert_in_errors(f"The order is not valid anymore: {status.label}", executed)
コード例 #11
0
def test_berth_filtering_by_pier_and_harbor(api_client, berth):
    base_query = """
        {
            berths(harbor: "%s", pier: "%s") {
                count
            }
        }
    """

    executed = api_client.execute(base_query % (
        to_global_id(HarborNode._meta.name, berth.pier.harbor.id),
        to_global_id(PierNode._meta.name, berth.pier.id),
    ))
    assert_in_errors("Cannot pass both pier and harbor filters", executed)
def test_reject_berth_application_fails_for_lease(api_client,
                                                  berth_application,
                                                  customer_profile):
    variables = {
        "id": to_global_id(BerthApplicationNode, berth_application.id),
    }
    BerthLeaseFactory(application=berth_application)

    executed = api_client.execute(REJECT_BERTH_APPLICATION_MUTATION,
                                  input=variables)

    assert_in_errors("Application has a lease", executed)

    assert (BerthApplication.objects.filter(
        status=ApplicationStatus.NO_SUITABLE_BERTHS).count() == 0)
コード例 #13
0
def test_create_order_lease_does_not_exist(superuser_api_client, lease_type):
    lease_id = to_global_id(
        BerthLeaseNode if lease_type == "berth" else WinterStorageLeaseNode,
        uuid.uuid4(),
    )
    variables = {
        "leaseId": lease_id,
    }

    assert Order.objects.count() == 0

    executed = superuser_api_client.execute(CREATE_ORDER_MUTATION, input=variables)

    assert Order.objects.count() == 0
    assert_in_errors("Lease with the given ID does not exist", executed)
コード例 #14
0
def test_confirm_payment_invalid_status(superuser_api_client, status):
    order = OrderFactory(status=status)
    variables = {"orderNumber": order.order_number}

    with mock.patch(
        "payments.providers.bambora_payform.requests.post",
        side_effect=mocked_response_create,
    ) as mock_call:
        executed = superuser_api_client.execute(
            CONFIRM_PAYMENT_MUTATION, input=variables
        )

    mock_call.assert_not_called()
    assert_in_errors("The order is not valid anymore", executed)
    assert_in_errors(status.label, executed)
def test_berth_applications_statuses_filter_invalid_enum(
        berth_application, api_client):
    berth_application.lease = BerthLeaseFactory()
    berth_application.status = ApplicationStatus.HANDLED
    berth_application.save()

    nonexistent_enum_str = "FOOBAR"

    query = BERTH_APPLICATIONS_WITH_STATUSES_FILTER_QUERY % nonexistent_enum_str

    executed = api_client.execute(query)

    assert_in_errors(
        "invalid value [%s]." % nonexistent_enum_str,
        executed,
    )
コード例 #16
0
def test_create_berth_switch_offer_missing_application_switch(
        api_client, berth_application, berth):
    berth_lease = BerthLeaseFactory(start_date=calculate_season_start_date(),
                                    end_date=calculate_season_end_date())
    berth_application.customer = berth_lease.customer
    berth_application.berth_switch = None
    berth_application.save()

    berth_lease.status = LeaseStatus.PAID
    berth_lease.save()

    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, berth.id),
    }
    executed = api_client.execute(CREATE_BERTH_SWITCH_OFFER_MUTATION,
                                  input=variables)
    assert_in_errors("Application must be a switch application", executed)
def test_assign_new_sticker_number_error_when_marked_lease(
    sticker_sequences,
    superuser_api_client,
    winter_storage_lease,
    winter_storage_application,
):
    variables = {
        "leaseId": to_global_id(WinterStorageLeaseNode,
                                winter_storage_lease.id)
    }
    winter_storage_application.area_type = ApplicationAreaType.MARKED
    winter_storage_application.save()

    winter_storage_lease.status = LeaseStatus.PAID
    winter_storage_lease.application = winter_storage_application
    winter_storage_lease.save()

    executed = superuser_api_client.execute(CONFIRM_PAYMENT_MUTATION,
                                            input=variables)

    assert_in_errors("Lease must refer to unmarked area", executed)
def test_update_winter_storage_application_by_owner_invalid_status(
        berth_customer_api_client, customer_profile, status):
    winter_storage_application = WinterStorageApplicationFactory(status=status)
    winter_storage_application_id = to_global_id(WinterStorageApplicationNode,
                                                 winter_storage_application.id)

    customer_profile.user = berth_customer_api_client.user
    customer_profile.save()
    winter_storage_application.customer = customer_profile
    winter_storage_application.save()

    variables = {
        "id": winter_storage_application_id,
        "firstName": "Invalid comment"
    }

    executed = berth_customer_api_client.execute(
        UPDATE_WINTER_STORAGE_APPLICATION_OWNER_MUTATION, input=variables)

    assert_in_errors(
        "Cannot modify the application once it has been processed", executed)
def test_update_berth_application_by_owner_invalid_status(
        berth_customer_api_client, customer_profile, status):
    berth_application = BerthApplicationFactory(status=status)
    berth_application_id = to_global_id(BerthApplicationNode,
                                        berth_application.id)
    other_customer = CustomerProfileFactory()

    customer_profile.user = berth_customer_api_client.user
    customer_profile.save()
    berth_application.customer = customer_profile
    berth_application.save()

    variables = {
        "id": berth_application_id,
        "customerId": to_global_id(ProfileNode, other_customer.id),
    }

    executed = berth_customer_api_client.execute(
        UPDATE_BERTH_APPLICATION_OWNER_MUTATION, input=variables)

    assert_in_errors(
        "Cannot modify the application once it has been processed", executed)
def test_update_berth_application_by_owner_cant_update_customer(
        berth_customer_api_client, berth_application, customer_profile):
    berth_application_id = to_global_id(BerthApplicationNode,
                                        berth_application.id)
    other_customer = CustomerProfileFactory()

    customer_profile.user = berth_customer_api_client.user
    customer_profile.save()
    berth_application.customer = customer_profile
    berth_application.save()

    variables = {
        "id": berth_application_id,
        "customerId": to_global_id(ProfileNode, other_customer.id),
    }

    executed = berth_customer_api_client.execute(
        UPDATE_BERTH_APPLICATION_OWNER_MUTATION, input=variables)

    assert_in_errors(
        "A customer cannot modify the customer connected to the application",
        executed)
コード例 #21
0
def test_create_berth_switch_offer_wrong_berth(api_client, berth_application,
                                               berth):
    berth_lease = BerthLeaseFactory(
        start_date=calculate_season_start_date(),
        end_date=calculate_season_end_date(),
        status=LeaseStatus.PAID,
    )
    berth_application.customer = berth_lease.customer

    berth_application.berth_switch = BerthSwitchFactory(
        berth=BerthFactory(number="9999"), )
    berth_application.save()

    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, berth.id),
    }
    executed = api_client.execute(CREATE_BERTH_SWITCH_OFFER_MUTATION,
                                  input=variables)

    assert_in_errors("NO_LEASE", executed)
def test_update_winter_storage_application_by_owner_cant_update_customer(
        berth_customer_api_client, winter_storage_application,
        customer_profile):
    winter_storage_application_id = to_global_id(WinterStorageApplicationNode,
                                                 winter_storage_application.id)
    other_customer = CustomerProfileFactory()

    customer_profile.user = berth_customer_api_client.user
    customer_profile.save()
    winter_storage_application.customer = customer_profile
    winter_storage_application.save()

    variables = {
        "id": winter_storage_application_id,
        "customerId": to_global_id(ProfileNode, other_customer.id),
    }

    executed = berth_customer_api_client.execute(
        UPDATE_WINTER_STORAGE_APPLICATION_OWNER_MUTATION, input=variables)

    assert_in_errors(
        "A customer cannot modify the customer connected to the application",
        executed)
コード例 #23
0
def test_fulfill_contract_no_order(superuser_api_client):
    executed = superuser_api_client.execute(
        FULFILL_CONTRACT_MUTATION, input=FULFILL_CONTRACT_MUTATION_INPUT)
    assert_in_errors("No order found for given order number", executed)