def test_update_berth_application(api_client, berth_application,
                                  customer_profile):
    berth_application_id = to_global_id(BerthApplicationNode,
                                        berth_application.id)
    customer_id = to_global_id(ProfileNode, customer_profile.id)

    variables = {
        "id": berth_application_id,
        "customerId": customer_id,
    }

    assert berth_application.customer is None

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

    assert executed == {
        "data": {
            "updateBerthApplication": {
                "berthApplication": {
                    "id": berth_application_id,
                    "customer": {
                        "id": customer_id,
                        "comment": customer_profile.comment,
                    },
                }
            }
        }
    }
def test_update_berth_service_profile(api_client, organization):
    profile = organization.customer

    variables = {
        "id": to_global_id(ProfileNode, profile.id),
        "comment": "Foobar",
        "invoicingType": random.choice(list(InvoicingType)).name,
        "organization": {
            "organizationType": random.choice(list(OrganizationType)).name,
            "name": "East Indian Trading Company",
            "businessId": "12345678-90X",
        },
    }

    assert CustomerProfile.objects.count() == 1
    assert Organization.objects.count() == 1

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

    assert CustomerProfile.objects.count() == 1
    assert Organization.objects.count() == 1

    assert executed["data"]["updateBerthServicesProfile"]["profile"] == {
        "id": variables["id"],
        "comment": variables["comment"],
        "invoicingType": variables["invoicingType"],
        "organization": {
            "id": to_global_id(OrganizationNode, organization.id),
            **variables["organization"],
        },
    }
def test_update_winter_storage_application(api_client,
                                           winter_storage_application,
                                           customer_profile):
    application_id = to_global_id(WinterStorageApplicationNode,
                                  winter_storage_application.id)
    customer_id = to_global_id(ProfileNode, customer_profile.id)

    variables = {
        "id": application_id,
        "customerId": customer_id,
    }

    assert winter_storage_application.customer is None

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

    assert executed == {
        "data": {
            "updateWinterStorageApplication": {
                "winterStorageApplication": {
                    "id": application_id,
                    "customer": {
                        "id": customer_id
                    },
                }
            }
        }
    }
Example #4
0
def test_approve_order_one_success_one_failure(
    superuser_api_client,
    order: Order,
    payment_provider,
    notification_template_orders_approved,
):
    order.status = OrderStatus.DRAFTED
    order.save(update_fields=["status"])

    due_date = (today() + relativedelta(days=14)).date()
    failure_order_id = to_global_id(OrderNode, uuid.uuid4())

    variables = {
        "dueDate":
        due_date,
        "orders": [
            {
                "orderId": failure_order_id,
                "email": "*****@*****.**"
            },
            {
                "orderId": to_global_id(OrderNode, order.id),
                "email": order.lease.application.email,
            },
        ],
    }

    with mock.patch(
            "customers.services.profile.requests.post",
            side_effect=mocked_response_profile(count=1,
                                                data=None,
                                                use_edges=False),
    ):
        executed = superuser_api_client.execute(APPROVE_ORDER_MUTATION,
                                                input=variables)

    payment_url = payment_provider.get_payment_email_url(
        order, lang=order.lease.application.language)

    order = Order.objects.get(id=order.id)

    assert len(executed["data"]["approveOrders"]["failedOrders"]) == 1
    assert executed["data"]["approveOrders"]["failedOrders"][0] == {
        "id": failure_order_id,
        "error": "Order matching query does not exist.",
    }

    assert order.due_date == due_date
    assert order.lease.status == LeaseStatus.OFFERED
    assert order.lease.application.status == ApplicationStatus.OFFER_SENT

    assert len(mail.outbox) == 1
    assert (mail.outbox[0].subject ==
            f"test order approved subject, event: {order.order_number}!")
    assert mail.outbox[0].body == f"{ order.order_number } { payment_url }"
    assert mail.outbox[0].to == [order.lease.application.email]

    assert mail.outbox[0].alternatives == [
        (f"<b>{ order.order_number } { payment_url }</b>", "text/html")
    ]
def test_create_order_winter_storage_lease(api_client, winter_storage_lease):
    lease_id = to_global_id(WinterStorageLeaseNode, winter_storage_lease.id)
    customer_id = to_global_id(ProfileNode, winter_storage_lease.customer.id)
    expected_product = WinterStorageProduct.objects.get(
        winter_storage_area=winter_storage_lease.get_winter_storage_area()
    )
    expected_price = rounded(
        winter_storage_lease.place.place_type.width
        * winter_storage_lease.place.place_type.length
        * expected_product.price_value,
        round_to_nearest=1,
        as_string=True,
    )

    variables = {
        "leaseId": lease_id,
    }

    assert Order.objects.count() == 0

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

    assert Order.objects.count() == 1
    assert executed["data"]["createOrder"]["order"].pop("id") is not None

    assert executed["data"]["createOrder"]["order"] == {
        "price": expected_price,
        "taxPercentage": str(expected_product.tax_percentage),
        "customer": {"id": customer_id},
        "product": {"id": to_global_id(WinterStorageProductNode, expected_product.id)},
        "lease": {"id": to_global_id(WinterStorageLeaseNode, winter_storage_lease.id)},
    }
def test_update_order_berth_product(api_client, status_choice, berth_lease):
    order = OrderFactory(lease=berth_lease, status=OrderStatus.OFFERED,)

    global_id = to_global_id(OrderNode, order.id)
    due_date = today()
    # only valid state transitions
    variables = {
        "orders": [
            {
                "id": global_id,
                "comment": "foobar",
                "dueDate": due_date,
                "status": OrderStatusEnum.get(status_choice.value).name,
            }
        ]
    }

    assert Order.objects.count() == 1

    executed = api_client.execute(UPDATE_ORDERS_MUTATION, input=variables)
    assert Order.objects.count() == 1

    assert len(executed["data"]["updateOrders"]["failedOrders"]) == 0
    assert len(executed["data"]["updateOrders"]["successfulOrders"]) == 1
    assert executed["data"]["updateOrders"]["successfulOrders"][0] == {
        "id": global_id,
        "comment": "foobar",
        "price": str(order.product.price_for_tier(berth_lease.berth.pier.price_tier)),
        "taxPercentage": str(order.product.tax_percentage),
        "dueDate": str(due_date.date()),
        "status": OrderStatusEnum.get(status_choice.value).name,
        "customer": {"id": to_global_id(ProfileNode, order.customer.id)},
        "product": {"id": to_global_id(BerthProductNode, order.product.id)},
        "lease": {"id": to_global_id(BerthLeaseNode, berth_lease.id)},
    }
def test_create_order_berth_product(api_client):
    berth_lease = BerthLeaseFactory(
        start_date=calculate_season_start_date(), berth__berth_type__mooring_type=7
    )
    customer_id = to_global_id(ProfileNode, berth_lease.customer.id)
    lease_id = to_global_id(BerthLeaseNode, berth_lease.id)

    expected_product = BerthProduct.objects.get_in_range(
        berth_lease.berth.berth_type.width,
        get_berth_lease_pricing_category(berth_lease),
    )
    expected_product_id = to_global_id(BerthProductNode, expected_product.id)

    variables = {
        "leaseId": lease_id,
    }

    assert Order.objects.count() == 0

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

    assert Order.objects.count() == 1
    assert executed["data"]["createOrder"]["order"].pop("id") is not None

    assert executed["data"]["createOrder"]["order"] == {
        "price": str(
            expected_product.price_for_tier(berth_lease.berth.pier.price_tier)
        ),
        "taxPercentage": str(expected_product.tax_percentage),
        "customer": {"id": customer_id},
        "product": {"id": expected_product_id},
        "lease": {"id": variables["leaseId"]},
    }
def test_update_winter_storage_product(
    api_client, winter_storage_product, winter_storage_area
):
    variables = {
        "id": to_global_id(WinterStorageProductNode, winter_storage_product.id),
        "priceValue": str(round(random.uniform(1, 999), 2)),
        "winterStorageAreaId": to_global_id(
            WinterStorageAreaNode, winter_storage_area.id
        ),
    }

    assert WinterStorageProduct.objects.count() == 1

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

    assert WinterStorageProduct.objects.count() == 1

    assert executed["data"]["updateWinterStorageProduct"]["winterStorageProduct"] == {
        "id": variables["id"],
        "priceValue": variables["priceValue"],
        "priceUnit": PriceUnitsEnum.AMOUNT.name,
        "winterStorageArea": {"id": variables["winterStorageAreaId"]},
    }
def test_update_boat_certificates(api_client, boat):
    boat_id = to_global_id(BoatNode, boat.id)

    file_name_1 = "certificate-1.pdf"
    file_name_2 = "certificate-2.pdf"
    new_checked_by = "John Wick"

    certificate_1 = BoatCertificateFactory(
        boat=boat,
        file=SimpleUploadedFile(name="old-filename-1.pdf", content=None),
        certificate_type=BoatCertificateType.INSURANCE,
        checked_by="Old checked by",
    )
    certificate_1_id = to_global_id(BoatCertificateNode, certificate_1.id)
    certificate_2 = BoatCertificateFactory(
        boat=boat,
        file=SimpleUploadedFile(name="old-filename-2.pdf", content=None),
        certificate_type=BoatCertificateType.INSPECTION,
        checked_by="Old checked by",
    )
    certificate_2_id = to_global_id(BoatCertificateNode, certificate_2.id)

    variables = {
        "id": boat_id,
        "updateBoatCertificates": [
            {
                "id": certificate_1_id,
                "file": SimpleUploadedFile(name=file_name_1, content=None),
                "checkedBy": new_checked_by,
            },
            {
                "id": certificate_2_id,
                "file": SimpleUploadedFile(name=file_name_2, content=None),
                "checkedBy": new_checked_by,
            },
        ],
    }

    assert BoatCertificate.objects.count() == 2

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

    certificates = executed["data"]["updateBoat"]["boat"].get("certificates")

    assert BoatCertificate.objects.count() == 2

    assert len(certificates) == 2

    # Test that all the expected files are in the instance certificates
    expected_urls = [
        get_boat_media_folder(boat, file_name_1),
        get_boat_media_folder(boat, file_name_2),
    ]

    for cert in certificates:
        assert any([expected_url in cert.get("file") for expected_url in expected_urls])
        assert cert.get("checkedBy") == new_checked_by
def test_create_berth_application(superuser_api_client, berth_switch_reason):
    berth = BerthFactory()
    berth_node_id = to_global_id(BerthNode, berth.id)
    harbor_node_id = to_global_id(HarborNode, berth.pier.harbor.id)
    boat_type = BoatTypeFactory()

    variables = {
        "berthSwitch": {
            "berthId": berth_node_id,
            "reason": berth_switch_reason.id
        },
        "berthApplication": {
            "language": "en",
            "firstName": "John",
            "lastName": "Doe",
            "phoneNumber": "1234567890",
            "email": "*****@*****.**",
            "address": "Mannerheimintie 1",
            "zipCode": "00100",
            "municipality": "Helsinki",
            "boatType": boat_type.id,
            "boatWidth": 2,
            "boatLength": 3,
            "informationAccuracyConfirmed": True,
            "acceptFitnessNews": False,
            "acceptLibraryNews": False,
            "acceptOtherCultureNews": False,
            "acceptBoatingNewsletter": True,
            "choices": [{
                "harborId": harbor_node_id,
                "priority": 1
            }],
        },
    }
    executed = superuser_api_client.execute(CREATE_BERTH_APPLICATION_MUTATION,
                                            input=variables)
    assert executed == {
        "data": {
            "createBerthApplication": {
                "berthApplication": {
                    "berthSwitch": {
                        "berth": {
                            "id": berth_node_id
                        },
                        "reason": {
                            "id": str(berth_switch_reason.id)
                        },
                    },
                    "harborChoices": [{
                        "harbor": {
                            "id": harbor_node_id
                        }
                    }],
                }
            }
        }
    }
Example #11
0
def test_create_berth_switch_offer_not_enough_permissions(api_client, order):
    variables = {
        "applicationId": to_global_id(BerthApplicationNode, randint(0, 100)),
        "newBerthId": to_global_id(BerthNode, uuid4()),
    }

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

    assert_not_enough_permissions(executed)
Example #12
0
def test_create_berth_switch_offer_application_does_not_exist(
        superuser_api_client, berth):
    variables = {
        "applicationId": to_global_id(BerthApplicationNode, randint(0, 100)),
        "newBerthId": to_global_id(BerthNode, berth.id),
    }

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

    assert_doesnt_exist("BerthApplication", executed)
def test_create_order_line(api_client, order, additional_product):
    order_id = to_global_id(OrderNode, order.id)
    product_id = to_global_id(AdditionalProductNode, additional_product.id)

    variables = {
        "orderId": order_id,
        "productId": product_id,
    }

    assert OrderLine.objects.count() == 0

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

    assert OrderLine.objects.count() == 1

    expected_price = additional_product.price_value
    if additional_product.price_unit == PriceUnits.PERCENTAGE:
        expected_price = calculate_product_percentage_price(
            order.price, additional_product.price_value
        )

    if additional_product.period == PeriodType.MONTH:
        expected_price = calculate_product_partial_month_price(
            expected_price, order.lease.start_date, order.lease.end_date
        )
    elif additional_product.period == PeriodType.YEAR:
        expected_price = calculate_product_partial_year_price(
            expected_price, order.lease.start_date, order.lease.end_date
        )
    # Season price is the same

    assert executed["data"]["createOrderLine"]["orderLine"].pop("id") is not None
    assert executed["data"]["createOrderLine"] == {
        "orderLine": {
            "price": str(expected_price),
            "taxPercentage": rounded(
                additional_product.tax_percentage,
                decimals=2,
                round_to_nearest=0.05,
                as_string=True,
            ),
            "pretaxPrice": str(
                convert_aftertax_to_pretax(
                    expected_price, additional_product.tax_percentage,
                )
            ),
            "product": {
                "id": to_global_id(AdditionalProductNode, additional_product.id),
                "priceValue": str(additional_product.price_value),
                "priceUnit": PriceUnitsEnum.get(additional_product.price_unit).name,
            },
        },
        "order": {"id": order_id},
    }
def test_create_order_line_not_enough_permissions(api_client):
    variables = {
        "orderId": to_global_id(OrderNode, uuid.uuid4()),
        "productId": to_global_id(ProfileNode, uuid.uuid4()),
    }

    assert OrderLine.objects.count() == 0

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

    assert OrderLine.objects.count() == 0
    assert_not_enough_permissions(executed)
def test_create_order_line_product_does_not_exist(superuser_api_client, order):
    variables = {
        "orderId": to_global_id(OrderNode, order.id),
        "productId": to_global_id(AdditionalProductNode, uuid.uuid4()),
    }

    assert OrderLine.objects.count() == 0

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

    assert OrderLine.objects.count() == 0
    assert_doesnt_exist("AdditionalProduct", executed)
Example #16
0
def test_create_berth_switch_offer_refresh_profile(api_client,
                                                   berth_application, berth):
    faker = Faker("fi_FI")
    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=berth_lease.berth)
    berth_application.save()

    first_name = faker.first_name()
    last_name = faker.last_name()
    email = faker.email()
    phone = faker.phone_number()

    data = {
        "id": to_global_id(ProfileNode, berth_lease.customer.id),
        "first_name": first_name,
        "last_name": last_name,
        "primary_email": {
            "email": email
        },
        "primary_phone": {
            "phone": phone
        },
    }
    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, berth.id),
        "profileToken": "profile-token",
    }
    with mock.patch(
            "customers.services.profile.requests.post",
            side_effect=mocked_response_profile(count=0,
                                                data=data,
                                                use_edges=False),
    ):
        executed = api_client.execute(
            CREATE_BERTH_SWITCH_OFFER_MUTATION_CUSTOMER_FIELDS,
            input=variables)

    assert executed["data"]["createBerthSwitchOffer"]["berthSwitchOffer"] == {
        "customerFirstName": first_name,
        "customerLastName": last_name,
        "customerEmail": email,
        "customerPhone": phone,
    }
def test_resend_order_not_fixed_in_error(
    order: Order,
    superuser_api_client,
    notification_template_orders_approved,
):
    order.status = OrderStatus.ERROR
    order.lease.status = LeaseStatus.ERROR
    order.lease.save()
    order.product.pricing_category = get_berth_product_pricing_category(order)
    order.product.save()
    order.save()

    profile_data = {
        "id": to_global_id(ProfileNode, order.customer.id),
        "first_name": "Foo",
        "last_name": "Bar",
        "primary_email": {
            "email": None
        },
        "primary_phone": {
            "phone": None
        },
    }
    variables = {
        "orders": [to_global_id(OrderNode, order.id)],
        "profileToken": "token"
    }

    with mock.patch(
            "requests.post",
            side_effect=mocked_response_profile(count=0,
                                                data=profile_data,
                                                use_edges=False),
    ):
        executed = superuser_api_client.execute(RESEND_ORDER_MUTATION,
                                                input=variables)

    order.refresh_from_db()
    order.lease.refresh_from_db()

    assert len(executed["data"]["resendOrder"]["failedOrders"]) == 1
    failed_order = executed["data"]["resendOrder"]["failedOrders"][0]

    assert failed_order["id"] == to_global_id(OrderNode, order.id)
    assert "Missing customer email" in str(failed_order["error"])

    assert order.lease.status == LeaseStatus.ERROR
    assert order.status == OrderStatus.ERROR

    assert len(mail.outbox) == 0
def test_get_order_refunds(superuser_api_client, order):
    order.status = OrderStatus.PAID
    order.save(update_fields=["status"])
    refund = OrderRefundFactory(order=order)

    executed = superuser_api_client.execute(ORDER_REFUNDS_QUERY %
                                            to_global_id(OrderNode, order.id))

    assert len(executed["data"]["orderRefunds"]["edges"]) == 1
    assert executed["data"]["orderRefunds"]["edges"][0]["node"] == {
        "id": to_global_id(OrderRefundNode, refund.id),
        "status": refund.status.name,
        "refundId": refund.refund_id,
        "amount": str(order.price),
    }
def test_update_winter_storage_application_not_enough_permissions(
        api_client, winter_storage_application, customer_profile):
    winter_storage_application_id = to_global_id(WinterStorageApplicationNode,
                                                 winter_storage_application.id)
    customer_id = to_global_id(ProfileNode, customer_profile.id)

    variables = {
        "id": winter_storage_application_id,
        "customerId": customer_id,
    }

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

    assert winter_storage_application.customer is None
    assert_not_enough_permissions(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)
Example #21
0
    def get_profile(self, id: UUID) -> HelsinkiProfileUser:
        from ..schema import ProfileNode

        global_id = to_global_id(ProfileNode, id)

        query = f"""
            query GetProfile {{
                profile(serviceType: BERTH, id: "{global_id}") {{
                    id
                    first_name: firstName
                    last_name: lastName
                    primary_email: primaryEmail {{
                        email
                    }}
                    primary_phone: primaryPhone {{
                        phone
                    }}
                    primary_address: primaryAddress {{
                        address
                        postal_code: postalCode
                        city
                    }}
                }}
            }}
        """

        response = self.query(query)
        user = self.parse_user(response.pop("profile"))
        return user
def test_update_berth_application_not_enough_permissions(
        api_client, berth_application, customer_profile):
    berth_application_id = to_global_id(BerthApplicationNode,
                                        berth_application.id)
    customer_id = to_global_id(ProfileNode, customer_profile.id)

    variables = {
        "id": berth_application_id,
        "customerId": customer_id,
    }

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

    assert berth_application.customer is None
    assert_not_enough_permissions(executed)
def test_reject_berth_application(
    api_client,
    berth_application,
    customer_profile,
    notification_template_berth_application_rejected,
):
    variables = {
        "id": to_global_id(BerthApplicationNode, berth_application.id),
    }

    assert (BerthApplication.objects.filter(
        status=ApplicationStatus.NO_SUITABLE_BERTHS).count() == 0)

    api_client.execute(REJECT_BERTH_APPLICATION_MUTATION, input=variables)

    assert (BerthApplication.objects.filter(
        status=ApplicationStatus.NO_SUITABLE_BERTHS).count() == 1)
    assert len(mail.outbox) == 1
    assert (
        mail.outbox[0].subject ==
        f"test berth application rejected subject, event: {berth_application.first_name}!"
    )
    assert mail.outbox[0].body == "test berth application rejected body text!"
    assert mail.outbox[0].to == [berth_application.email]

    assert mail.outbox[0].alternatives == [(
        "<b>test berth application rejected body HTML!</b>",
        "text/html",
    )]
def test_create_my_berth_profile(user_api_client, hki_profile_address):
    customer_id = to_global_id(ProfileNode, uuid.uuid4())

    variables = {"profileToken": "token"}

    assert CustomerProfile.objects.count() == 0

    with mock.patch(
        "customers.services.profile.requests.post",
        side_effect=mocked_response_my_profile(
            data={
                "id": customer_id,
                "first_name": "test",
                "last_name": "test",
                "primary_email": {"email": "*****@*****.**"},
                "primary_phone": {"phone": "0501234567"},
                "primary_address": hki_profile_address,
            },
        ),
    ):
        executed = user_api_client.execute(
            CREATE_MY_BERTH_PROFILE_MUTATION, input=variables
        )

    assert CustomerProfile.objects.count() == 1
    assert executed["data"]["createMyBerthProfile"]["profile"] == {
        "id": customer_id,
    }
    profile = CustomerProfile.objects.all().first()
    assert profile.user is not None
    assert profile.user.groups.count() == 1
    assert profile.user.groups.first() == get_berth_customers_group()
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_assign_new_sticker_number_resets_posted_date(
    sticker_sequences,
    superuser_api_client,
    winter_storage_lease,
    winter_storage_application,
):
    lease_id = to_global_id(WinterStorageLeaseNode, winter_storage_lease.id)
    variables = {"leaseId": lease_id}
    winter_storage_application.area_type = ApplicationAreaType.UNMARKED
    winter_storage_application.save()

    date_to_test = today()

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

    executed = superuser_api_client.execute(QUERY_WINTER_STORAGE_LEASE %
                                            lease_id)
    assert executed["data"]["winterStorageLease"]["stickerPosted"] == str(
        date_to_test.date())

    superuser_api_client.execute(CONFIRM_PAYMENT_MUTATION, input=variables)
    executed = superuser_api_client.execute(QUERY_WINTER_STORAGE_LEASE %
                                            lease_id)
    assert executed["data"]["winterStorageLease"]["stickerPosted"] is None
def test_assign_new_sticker_number(
    sticker_sequences,
    superuser_api_client,
    winter_storage_lease,
    winter_storage_application,
):
    lease_id = to_global_id(WinterStorageLeaseNode, winter_storage_lease.id)
    variables = {"leaseId": lease_id}
    winter_storage_application.area_type = ApplicationAreaType.UNMARKED
    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 executed["data"]["assignNewStickerNumber"]["stickerNumber"] == 1

    query = QUERY_WINTER_STORAGE_LEASE % lease_id
    executed = superuser_api_client.execute(query)

    assert executed["data"]["winterStorageLease"]["stickerNumber"] == 1

    sticker_season = executed["data"]["winterStorageLease"]["stickerSeason"]
    assert len(sticker_season) == 9
def test_update_berth_service_profile_create_organization(api_client, customer_profile):
    variables = {
        "id": to_global_id(ProfileNode, customer_profile.id),
        "organization": {
            "organizationType": random.choice(list(OrganizationType)).name,
            "name": "East Indian Trading Company",
            "businessId": "12345678-90X",
        },
    }

    assert CustomerProfile.objects.count() == 1
    assert Organization.objects.count() == 0

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

    assert CustomerProfile.objects.count() == 1
    assert Organization.objects.count() == 1

    assert (
        executed["data"]["updateBerthServicesProfile"]["profile"]["organization"].pop(
            "id"
        )
        is not None
    )
    assert executed["data"]["updateBerthServicesProfile"]["profile"] == {
        "id": variables["id"],
        "comment": customer_profile.comment,
        "invoicingType": customer_profile.invoicing_type.name,
        "organization": variables["organization"],
    }
Example #29
0
def test_create_berth_switch_offer_berth_does_not_exist(
        superuser_api_client, berth_application, customer_profile):
    berth_application.berth_switch = BerthSwitchFactory()
    berth_application.customer = customer_profile
    berth_application.save()

    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, uuid4()),
    }

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

    assert_doesnt_exist("Berth", executed)
def test_update_berth_service_profile_delete_organization(api_client, organization):
    profile = organization.customer

    variables = {
        "id": to_global_id(ProfileNode, profile.id),
        "comment": "Foobar",
        "invoicingType": random.choice(list(InvoicingType)).name,
        "deleteOrganization": True,
    }

    assert CustomerProfile.objects.count() == 1
    assert Organization.objects.count() == 1

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

    assert CustomerProfile.objects.count() == 1
    assert Organization.objects.count() == 0

    assert executed["data"]["updateBerthServicesProfile"]["profile"] == {
        "id": variables["id"],
        "comment": variables["comment"],
        "invoicingType": variables["invoicingType"],
        "organization": None,
    }