def test_update_boats_berth_applications(berth_application_with_customer):
    # Renaming for simplicity
    application = berth_application_with_customer
    boat_type = BoatTypeFactory(id=application.boat_type_id)

    application.boat_name = "New name"
    application.boat_registration_number = "NUMBER"
    application.status = ApplicationStatus.OFFER_SENT
    BerthLeaseFactory(
        application=application,
        customer=application.customer,
        status=LeaseStatus.PAID,
        boat=BoatFactory(
            owner=application.customer,
            registration_number="NUMBER",
            name="Old name",
            boat_type=boat_type,
        ),
    )
    application.save()

    assert application.customer.boats.count() == 1

    call_command("create_boat_for_existing_applications")

    assert application.customer.boats.count() == 1
    boat = application.customer.boats.first()

    assert boat.registration_number == application.boat_registration_number
    assert boat.name == application.boat_name == "New name"
Exemplo n.º 2
0
def test_get_full_profile_information_from_gdpr_api(
    rest_api_client, requests_mock, settings
):
    customer_profile = CustomerProfileFactory()
    boat = BoatFactory(owner=customer_profile)
    berth_application = BerthApplicationFactory(customer=customer_profile)
    berth_lease = BerthLeaseFactory(
        customer=customer_profile, boat=boat, status=LeaseStatus.PAID
    )
    winter_storage_application = WinterStorageApplicationFactory(
        customer=customer_profile
    )
    winter_storage_lease = WinterStorageLeaseFactory(
        customer=customer_profile, boat=boat
    )
    order = OrderFactory(lease=berth_lease)
    berth_switch_offer = BerthSwitchOfferFactory(
        customer=customer_profile, lease=berth_lease
    )
    organization = OrganizationFactory(customer=customer_profile)

    auth_header = get_api_token_for_user_with_scopes(
        customer_profile.user, [settings.GDPR_API_QUERY_SCOPE], requests_mock
    )
    rest_api_client.credentials(HTTP_AUTHORIZATION=auth_header)
    response = rest_api_client.get(
        reverse("helsinki_gdpr:gdpr_v1", kwargs={"pk": customer_profile.id})
    )

    resp = json.loads(response.content)

    assert response.status_code == 200

    assert {
        "key": "INVOICING_TYPE",
        "value": dict(InvoicingType.choices)[customer_profile.invoicing_type],
    } in resp["children"]

    assert {"key": "COMMENT", "value": customer_profile.comment} in resp["children"]

    assert {
        "key": "CREATED_AT",
        "value": customer_profile.created_at.strftime("%d-%m-%Y %H:%M:%S"),
    } in resp["children"]

    assert {
        "key": "MODIFIED_AT",
        "value": customer_profile.modified_at.strftime("%d-%m-%Y %H:%M:%S"),
    } in resp["children"]

    berth_applications_dict = {}
    berth_leases_dict = {}
    boats_dict = {}
    offers_dict = {}
    orders_dict = {}
    organization_dict = {}
    winter_storage_applications_dict = {}
    winter_storage_leases_dict = {}
    for child_dict in resp["children"]:
        if child_dict["key"] == "BERTH_APPLICATIONS":
            berth_applications_dict = child_dict
        elif child_dict["key"] == "BERTH_LEASES":
            berth_leases_dict = child_dict
        elif child_dict["key"] == "BOATS":
            boats_dict = child_dict
        elif child_dict["key"] == "OFFERS":
            offers_dict = child_dict
        elif child_dict["key"] == "ORDERS":
            orders_dict = child_dict
        elif child_dict["key"] == "ORGANIZATION":
            organization_dict = child_dict
        elif child_dict["key"] == "WINTER_STORAGE_APPLICATIONS":
            winter_storage_applications_dict = child_dict
        elif child_dict["key"] == "WINTER_STORAGE_LEASES":
            winter_storage_leases_dict = child_dict

    # Using a TestCase here since assertDictEqual is better for comparing dicts
    test_case = TestCase()

    test_case.assertDictEqual(
        {
            "key": "BERTH_APPLICATIONS",
            "children": [
                {
                    "key": "BERTHAPPLICATION",
                    "children": [
                        {"key": "ID", "value": berth_application.id},
                        {
                            "key": "CREATED_AT",
                            "value": berth_application.created_at.strftime(
                                "%d-%m-%Y %H:%M:%S"
                            ),
                        },
                        {
                            "key": "STATUS",
                            "value": dict(ApplicationStatus.choices)[
                                berth_application.status
                            ],
                        },
                        {"key": "LANGUAGE", "value": berth_application.language},
                        {"key": "FIRST_NAME", "value": berth_application.first_name},
                        {"key": "LAST_NAME", "value": berth_application.last_name},
                        {"key": "EMAIL", "value": berth_application.email},
                        {
                            "key": "PHONE_NUMBER",
                            "value": berth_application.phone_number,
                        },
                        {"key": "ADDRESS", "value": berth_application.address},
                        {"key": "ZIP_CODE", "value": berth_application.zip_code},
                        {
                            "key": "MUNICIPALITY",
                            "value": berth_application.municipality,
                        },
                        {
                            "key": "COMPANY_NAME",
                            "value": berth_application.company_name,
                        },
                        {"key": "BUSINESS_ID", "value": berth_application.business_id},
                        {"key": "BOAT_TYPE", "value": berth_application.boat_type.name},
                        {
                            "key": "BOAT_REGISTRATION_NUMBER",
                            "value": berth_application.boat_registration_number,
                        },
                        {"key": "BOAT_NAME", "value": berth_application.boat_name},
                        {"key": "BOAT_MODEL", "value": berth_application.boat_model},
                        {
                            "key": "BOAT_LENGTH",
                            "value": float(berth_application.boat_length),
                        },
                        {
                            "key": "BOAT_WIDTH",
                            "value": float(berth_application.boat_width),
                        },
                        {
                            "key": "ACCEPT_BOATING_NEWSLETTER",
                            "value": berth_application.accept_boating_newsletter,
                        },
                        {
                            "key": "ACCEPT_FITNESS_NEWS",
                            "value": berth_application.accept_fitness_news,
                        },
                        {
                            "key": "ACCEPT_LIBRARY_NEWS",
                            "value": berth_application.accept_library_news,
                        },
                        {
                            "key": "ACCEPT_OTHER_CULTURE_NEWS",
                            "value": berth_application.accept_other_culture_news,
                        },
                        {
                            "key": "INFORMATION_ACCURACY_CONFIRMED",
                            "value": berth_application.information_accuracy_confirmed,
                        },
                        {
                            "key": "APPLICATION_CODE",
                            "value": berth_application.application_code,
                        },
                        {"key": "HARBORCHOICE_SET", "value": []},
                        {
                            "key": "BERTH_SWITCH",
                            "value": berth_application.berth_switch,
                        },
                        {
                            "key": "BOAT_DRAUGHT",
                            "value": berth_application.boat_draught,
                        },
                        {"key": "BOAT_WEIGHT", "value": berth_application.boat_weight},
                        {
                            "key": "ACCESSIBILITY_REQUIRED",
                            "value": berth_application.accessibility_required,
                        },
                        {
                            "key": "BOAT_PROPULSION",
                            "value": berth_application.boat_propulsion,
                        },
                        {
                            "key": "BOAT_HULL_MATERIAL",
                            "value": berth_application.boat_hull_material,
                        },
                        {
                            "key": "BOAT_INTENDED_USE",
                            "value": berth_application.boat_intended_use,
                        },
                        {
                            "key": "RENTING_PERIOD",
                            "value": berth_application.renting_period,
                        },
                        {"key": "RENT_FROM", "value": berth_application.rent_from},
                        {"key": "RENT_TILL", "value": berth_application.rent_till},
                        {
                            "key": "BOAT_IS_INSPECTED",
                            "value": berth_application.boat_is_inspected,
                        },
                        {
                            "key": "BOAT_IS_INSURED",
                            "value": berth_application.boat_is_insured,
                        },
                        {
                            "key": "AGREE_TO_TERMS",
                            "value": berth_application.agree_to_terms,
                        },
                    ],
                }
            ],
        },
        berth_applications_dict,
    )

    test_case.assertDictEqual(
        {
            "key": "BERTH_LEASES",
            "children": [
                {
                    "key": "BERTHLEASE",
                    "children": [
                        {"key": "ID", "value": str(berth_lease.id)},
                        {"key": "BOAT", "value": str(boat.id)},
                        {
                            "key": "STATUS",
                            "value": dict(LeaseStatus.choices)[berth_lease.status],
                        },
                        {"key": "ORDERS", "value": [str(order.id)]},
                        {"key": "COMMENT", "value": berth_lease.comment},
                        {
                            "key": "BERTH",
                            "value": {
                                "key": "BERTH",
                                "children": [
                                    {
                                        "key": "NUMBER",
                                        "value": berth_lease.berth.number,
                                    },
                                    {
                                        "key": "PIER",
                                        "value": {
                                            "key": "PIER",
                                            "children": [
                                                {
                                                    "key": "IDENTIFIER",
                                                    "value": berth_lease.berth.pier.identifier,
                                                }
                                            ],
                                        },
                                    },
                                ],
                            },
                        },
                        {"key": "APPLICATION", "value": None},
                        {
                            "key": "START_DATE",
                            "value": berth_lease.start_date.strftime("%d-%m-%Y"),
                        },
                        {
                            "key": "END_DATE",
                            "value": berth_lease.end_date.strftime("%d-%m-%Y"),
                        },
                    ],
                }
            ],
        },
        berth_leases_dict,
    )

    test_case.assertDictEqual(
        {
            "key": "BOATS",
            "children": [
                {
                    "key": "BOAT",
                    "children": [
                        {"key": "ID", "value": str(boat.id)},
                        {"key": "CERTIFICATES", "children": []},
                        {
                            "key": "REGISTRATION_NUMBER",
                            "value": boat.registration_number,
                        },
                        {"key": "LENGTH", "value": float(boat.length)},
                        {"key": "WIDTH", "value": float(boat.width)},
                        {"key": "DRAUGHT", "value": boat.draught},
                    ],
                }
            ],
        },
        boats_dict,
    )

    test_case.assertDictEqual(
        {
            "key": "OFFERS",
            "children": [
                {
                    "key": "BERTHSWITCHOFFER",
                    "children": [
                        {"key": "ID", "value": str(berth_switch_offer.id)},
                        {
                            "key": "STATUS",
                            "value": dict(OfferStatus.choices)[
                                berth_switch_offer.status
                            ],
                        },
                        {
                            "key": "DUE_DATE",
                            "value": berth_switch_offer.due_date.strftime("%d-%m-%Y")
                            if berth_switch_offer.due_date
                            else None,
                        },
                        {
                            "key": "CUSTOMER_FIRST_NAME",
                            "value": berth_switch_offer.customer_first_name,
                        },
                        {
                            "key": "CUSTOMER_LAST_NAME",
                            "value": berth_switch_offer.customer_last_name,
                        },
                        {
                            "key": "CUSTOMER_EMAIL",
                            "value": berth_switch_offer.customer_email,
                        },
                        {
                            "key": "CUSTOMER_PHONE",
                            "value": berth_switch_offer.customer_phone,
                        },
                        {
                            "key": "APPLICATION",
                            "value": berth_switch_offer.application.id,
                        },
                        {"key": "LEASE", "value": str(berth_switch_offer.lease.id)},
                        {"key": "BERTH", "value": str(berth_switch_offer.berth.id)},
                    ],
                }
            ],
        },
        offers_dict,
    )

    test_case.assertDictEqual(
        {
            "key": "ORDERS",
            "children": [
                {
                    "key": "ORDER",
                    "children": [
                        {"key": "ID", "value": str(order.id)},
                        {
                            "key": "PRODUCT",
                            "value": {
                                "key": "BERTHPRODUCT",
                                "children": [
                                    {
                                        "key": "MIN_WIDTH",
                                        "value": float(order.product.min_width),
                                    },
                                    {
                                        "key": "MAX_WIDTH",
                                        "value": float(order.product.max_width),
                                    },
                                    {
                                        "key": "TIER_1_PRICE",
                                        "value": float(order.product.tier_1_price),
                                    },
                                    {
                                        "key": "TIER_2_PRICE",
                                        "value": float(order.product.tier_2_price),
                                    },
                                    {
                                        "key": "TIER_3_PRICE",
                                        "value": float(order.product.tier_3_price),
                                    },
                                    {
                                        "key": "PRICE_UNIT",
                                        "value": order.product.price_unit,
                                    },
                                    {
                                        "key": "TAX_PERCENTAGE",
                                        "value": float(order.product.tax_percentage),
                                    },
                                ],
                            },
                        },
                        {"key": "LEASE", "value": str(order.lease.id)},
                        {
                            "key": "STATUS",
                            "value": dict(OrderStatus.choices)[order.status],
                        },
                        {"key": "COMMENT", "value": order.comment},
                        {"key": "PRICE", "value": float(order.price)},
                        {"key": "TAX_PERCENTAGE", "value": float(order.tax_percentage)},
                        {"key": "PRETAX_PRICE", "value": float(order.pretax_price)},
                        {"key": "TOTAL_PRICE", "value": float(order.total_price)},
                        {
                            "key": "TOTAL_PRETAX_PRICE",
                            "value": float(order.total_pretax_price),
                        },
                        {
                            "key": "TOTAL_TAX_PERCENTAGE",
                            "value": float(order.total_tax_percentage),
                        },
                        {
                            "key": "DUE_DATE",
                            "value": order.due_date.strftime("%d-%m-%Y"),
                        },
                        {"key": "ORDER_LINES", "children": []},
                        {"key": "LOG_ENTRIES", "children": []},
                        {"key": "PAID_AT", "value": None},
                        {"key": "CANCELLED_AT", "value": None},
                        {"key": "REJECTED_AT", "value": None},
                    ],
                }
            ],
        },
        orders_dict,
    )

    test_case.assertDictEqual(
        {
            "key": "ORGANIZATION",
            "children": [
                {"key": "ID", "value": str(organization.id)},
                {"key": "BUSINESS_ID", "value": organization.business_id},
                {"key": "NAME", "value": organization.name},
                {"key": "ADDRESS", "value": organization.address},
                {"key": "POSTAL_CODE", "value": organization.postal_code},
                {"key": "CITY", "value": organization.city},
            ],
        },
        organization_dict,
    )

    test_case.assertDictEqual(
        {
            "key": "WINTER_STORAGE_APPLICATIONS",
            "children": [
                {
                    "key": "WINTERSTORAGEAPPLICATION",
                    "children": [
                        {"key": "ID", "value": winter_storage_application.id},
                        {
                            "key": "CREATED_AT",
                            "value": winter_storage_application.created_at.strftime(
                                "%d-%m-%Y %H:%M:%S"
                            ),
                        },
                        {
                            "key": "STATUS",
                            "value": dict(ApplicationStatus.choices)[
                                winter_storage_application.status
                            ],
                        },
                        {
                            "key": "LANGUAGE",
                            "value": winter_storage_application.language,
                        },
                        {
                            "key": "FIRST_NAME",
                            "value": winter_storage_application.first_name,
                        },
                        {
                            "key": "LAST_NAME",
                            "value": winter_storage_application.last_name,
                        },
                        {"key": "EMAIL", "value": winter_storage_application.email},
                        {
                            "key": "PHONE_NUMBER",
                            "value": winter_storage_application.phone_number,
                        },
                        {"key": "ADDRESS", "value": winter_storage_application.address},
                        {
                            "key": "ZIP_CODE",
                            "value": winter_storage_application.zip_code,
                        },
                        {
                            "key": "MUNICIPALITY",
                            "value": winter_storage_application.municipality,
                        },
                        {"key": "COMPANY_NAME", "value": ""},
                        {"key": "BUSINESS_ID", "value": ""},
                        {
                            "key": "BOAT_TYPE",
                            "value": winter_storage_application.boat_type.name,
                        },
                        {"key": "BOAT_REGISTRATION_NUMBER", "value": ""},
                        {"key": "BOAT_NAME", "value": ""},
                        {"key": "BOAT_MODEL", "value": ""},
                        {
                            "key": "BOAT_LENGTH",
                            "value": float(winter_storage_application.boat_length),
                        },
                        {
                            "key": "BOAT_WIDTH",
                            "value": float(winter_storage_application.boat_width),
                        },
                        {"key": "ACCEPT_BOATING_NEWSLETTER", "value": False},
                        {"key": "ACCEPT_FITNESS_NEWS", "value": False},
                        {"key": "ACCEPT_LIBRARY_NEWS", "value": False},
                        {"key": "ACCEPT_OTHER_CULTURE_NEWS", "value": False},
                        {"key": "INFORMATION_ACCURACY_CONFIRMED", "value": False},
                        {"key": "APPLICATION_CODE", "value": ""},
                        {"key": "AREA_TYPE", "value": None},
                        {"key": "WINTERSTORAGEAREACHOICE_SET", "value": []},
                        {
                            "key": "STORAGE_METHOD",
                            "value": dict(WinterStorageMethod.choices)[
                                winter_storage_application.storage_method
                            ],
                        },
                        {"key": "TRAILER_REGISTRATION_NUMBER", "value": ""},
                    ],
                }
            ],
        },
        winter_storage_applications_dict,
    )

    test_case.assertDictEqual(
        {
            "key": "WINTER_STORAGE_LEASES",
            "children": [
                {
                    "key": "WINTERSTORAGELEASE",
                    "children": [
                        {"key": "ID", "value": str(winter_storage_lease.id)},
                        {"key": "BOAT", "value": str(boat.id)},
                        {
                            "key": "STATUS",
                            "value": dict(LeaseStatus.choices)[
                                winter_storage_lease.status
                            ],
                        },
                        {"key": "ORDERS", "value": []},
                        {"key": "COMMENT", "value": winter_storage_lease.comment},
                        {
                            "key": "PLACE",
                            "value": {
                                "key": "WINTERSTORAGEPLACE",
                                "children": [
                                    {
                                        "key": "NUMBER",
                                        "value": winter_storage_lease.place.number,
                                    },
                                    {
                                        "key": "WINTER_STORAGE_SECTION",
                                        "value": {
                                            "key": "WINTERSTORAGESECTION",
                                            "children": [
                                                {
                                                    "key": "IDENTIFIER",
                                                    "value": (
                                                        winter_storage_lease.place.winter_storage_section.identifier
                                                    ),
                                                }
                                            ],
                                        },
                                    },
                                ],
                            },
                        },
                        {"key": "SECTION", "value": None},
                        {"key": "APPLICATION", "value": None},
                        {
                            "key": "START_DATE",
                            "value": winter_storage_lease.start_date.strftime(
                                "%d-%m-%Y"
                            ),
                        },
                        {
                            "key": "END_DATE",
                            "value": winter_storage_lease.end_date.strftime("%d-%m-%Y"),
                        },
                        {"key": "STICKER_NUMBER", "value": None},
                        {"key": "STICKER_POSTED", "value": None},
                    ],
                }
            ],
        },
        winter_storage_leases_dict,
    )
Exemplo n.º 3
0
def winter_storage_lease():
    boat = BoatFactory()
    return WinterStorageLeaseFactory(customer=boat.owner, boat=boat)
Exemplo n.º 4
0
def berth_lease_without_product():
    boat = BoatFactory()
    return BerthLeaseFactory(customer=boat.owner,
                             boat=boat,
                             create_product=False)
Exemplo n.º 5
0
def berth_lease():
    boat = BoatFactory()
    return BerthLeaseFactory(customer=boat.owner, boat=boat)
def test_lease_should_have_boat_owner_as_customer():
    another_customers_boat = BoatFactory()
    with pytest.raises(ValidationError):
        BerthLeaseFactory(boat=another_customers_boat)